feat: add server settings for default board, default color scheme and default locale (#1373)
* feat: add server settings for default board, default color scheme and default locale * chore: address pull request feedback * test: adjust unit tests to match requirements * fix: deepsource issue * chore: add deepsource as dependency to translation library * refactor: restructure language-combobox, adjust default locale for next-intl * chore: change cookie keys prefix from homarr- to homarr.
This commit is contained in:
@@ -23,4 +23,4 @@ export const localeConfigurations = {
|
||||
export const supportedLanguages = objectKeys(localeConfigurations);
|
||||
export type SupportedLanguage = (typeof supportedLanguages)[number];
|
||||
|
||||
export const defaultLocale = "en" satisfies SupportedLanguage;
|
||||
export const fallbackLocale = "en" satisfies SupportedLanguage;
|
||||
|
||||
@@ -1922,6 +1922,14 @@ export default {
|
||||
},
|
||||
settings: {
|
||||
title: "Settings",
|
||||
notification: {
|
||||
success: {
|
||||
message: "Settings saved successfully",
|
||||
},
|
||||
error: {
|
||||
message: "Failed to save settings",
|
||||
},
|
||||
},
|
||||
section: {
|
||||
analytics: {
|
||||
title: "Analytics",
|
||||
@@ -1963,6 +1971,29 @@ export default {
|
||||
text: "Google will build a search box with the crawled links along with other direct links. Enabling this will ask Google to disable that box.",
|
||||
},
|
||||
},
|
||||
board: {
|
||||
title: "Boards",
|
||||
defaultBoard: {
|
||||
label: "Global default board",
|
||||
description: "Only public boards are available for selection",
|
||||
},
|
||||
},
|
||||
appearance: {
|
||||
title: "Appearance",
|
||||
defaultColorScheme: {
|
||||
label: "Default color scheme",
|
||||
options: {
|
||||
light: "Light",
|
||||
dark: "Dark",
|
||||
},
|
||||
},
|
||||
},
|
||||
culture: {
|
||||
title: "Culture",
|
||||
defaultLocale: {
|
||||
label: "Default language",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tool: {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import createMiddleware from "next-intl/middleware";
|
||||
|
||||
import { routing } from "./routing";
|
||||
import type { SupportedLanguage } from ".";
|
||||
import { createRouting } from "./routing";
|
||||
|
||||
export const I18nMiddleware = createMiddleware(routing);
|
||||
export const createI18nMiddleware = (defaultLocale: SupportedLanguage) =>
|
||||
createMiddleware(createRouting(defaultLocale));
|
||||
|
||||
export const config = {
|
||||
// Match only internationalized pathnames
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import deepmerge from "deepmerge";
|
||||
import { getRequestConfig } from "next-intl/server";
|
||||
|
||||
import { isLocaleSupported } from ".";
|
||||
import { fallbackLocale, isLocaleSupported } from ".";
|
||||
import type { SupportedLanguage } from "./config";
|
||||
import { createLanguageMapping } from "./mapping";
|
||||
import { routing } from "./routing";
|
||||
|
||||
// This file is referenced in the `next.config.js` file. See https://next-intl-docs.vercel.app/docs/usage/configuration
|
||||
export default getRequestConfig(async ({ requestLocale }) => {
|
||||
let currentLocale = await requestLocale;
|
||||
|
||||
if (!currentLocale || !isLocaleSupported(currentLocale)) {
|
||||
currentLocale = routing.defaultLocale;
|
||||
currentLocale = fallbackLocale;
|
||||
}
|
||||
const typedLocale = currentLocale as SupportedLanguage;
|
||||
|
||||
@@ -19,8 +18,8 @@ export default getRequestConfig(async ({ requestLocale }) => {
|
||||
const currentMessages = (await languageMap[typedLocale]()).default;
|
||||
|
||||
// Fallback to default locale if the current locales messages if not all messages are present
|
||||
if (currentLocale !== routing.defaultLocale) {
|
||||
const fallbackMessages = (await languageMap[routing.defaultLocale]()).default;
|
||||
if (currentLocale !== fallbackLocale) {
|
||||
const fallbackMessages = (await languageMap[fallbackLocale]()).default;
|
||||
return {
|
||||
locale: currentLocale,
|
||||
messages: deepmerge(fallbackMessages, currentMessages),
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import { defineRouting } from "next-intl/routing";
|
||||
|
||||
import { defaultLocale, supportedLanguages } from "./config";
|
||||
import { localeCookieKey } from "@homarr/definitions";
|
||||
|
||||
export const routing = defineRouting({
|
||||
locales: supportedLanguages,
|
||||
defaultLocale,
|
||||
localePrefix: {
|
||||
mode: "never", // Rewrite the URL with locale parameter but without shown in url
|
||||
},
|
||||
});
|
||||
import type { SupportedLanguage } from "./config";
|
||||
import { supportedLanguages } from "./config";
|
||||
|
||||
export const createRouting = (defaultLocale: SupportedLanguage) =>
|
||||
defineRouting({
|
||||
locales: supportedLanguages,
|
||||
defaultLocale,
|
||||
localeCookie: {
|
||||
name: localeCookieKey,
|
||||
},
|
||||
localePrefix: {
|
||||
mode: "never", // Rewrite the URL with locale parameter but without shown in url
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user