* fix: Logic error in toast fix: Remove useless component * fix: Logout not clearing all stores * Add icons to notification settings * Add eslint rule to enforce spaced comment * Add eslint rule for arrow-body-style * Add eslint rule to enforce self-closing components * Add menu to api key settings Fix: Deleting webhook subscription does not remove from UI Split webhook subscriptions into active and inactive Styling updates
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import path from "path";
|
|
import i18n from "i18next";
|
|
import backend from "i18next-fs-backend";
|
|
import { languages } from "@shared/i18n";
|
|
import { unicodeBCP47toCLDR, unicodeCLDRtoBCP47 } from "@shared/utils/date";
|
|
import env from "@server/env";
|
|
import { User } from "@server/models";
|
|
|
|
/**
|
|
* Returns i18n options for the given user or the default server language if
|
|
* no user is provided.
|
|
*
|
|
* @param user The user to get options for
|
|
* @returns i18n options
|
|
*/
|
|
export function opts(user?: User | null) {
|
|
return {
|
|
lng: unicodeCLDRtoBCP47(user?.language ?? env.DEFAULT_LANGUAGE),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Initializes i18n library, loading all available translations from the
|
|
* filesystem.
|
|
*
|
|
* @returns i18n instance
|
|
*/
|
|
export function initI18n() {
|
|
const lng = unicodeCLDRtoBCP47(env.DEFAULT_LANGUAGE);
|
|
i18n.use(backend).init({
|
|
compatibilityJSON: "v3",
|
|
backend: {
|
|
loadPath: (language: string) =>
|
|
path.resolve(
|
|
path.join(
|
|
__dirname,
|
|
"..",
|
|
"..",
|
|
"shared",
|
|
"i18n",
|
|
"locales",
|
|
unicodeBCP47toCLDR(language),
|
|
"translation.json"
|
|
)
|
|
),
|
|
},
|
|
preload: languages.map(unicodeCLDRtoBCP47),
|
|
interpolation: {
|
|
escapeValue: false,
|
|
},
|
|
lng,
|
|
fallbackLng: lng,
|
|
keySeparator: false,
|
|
returnNull: false,
|
|
});
|
|
return i18n;
|
|
}
|