Cleanup
This commit is contained in:
45
packages/i18n/src/i18n.settings.ts
Normal file
45
packages/i18n/src/i18n.settings.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { InitOptions } from 'i18next';
|
||||
|
||||
const fallbackLng = 'en';
|
||||
const languages: string[] = [fallbackLng];
|
||||
|
||||
export const I18N_COOKIE_NAME = 'lang';
|
||||
|
||||
/**
|
||||
* The default array of Internationalization (i18n) namespaces.
|
||||
* These namespaces are commonly used in the application for translation purposes.
|
||||
*
|
||||
* Add your own namespaces here
|
||||
**/
|
||||
export const defaultI18nNamespaces = [
|
||||
'common',
|
||||
'auth',
|
||||
'organization',
|
||||
'profile',
|
||||
'subscription',
|
||||
'onboarding',
|
||||
];
|
||||
|
||||
export function getI18nSettings(
|
||||
language: string | undefined,
|
||||
ns: string | string[] = defaultI18nNamespaces,
|
||||
): InitOptions {
|
||||
let lng = language ?? fallbackLng;
|
||||
|
||||
if (!languages.includes(lng)) {
|
||||
console.warn(
|
||||
`Language "${lng}" is not supported. Falling back to "${fallbackLng}"`,
|
||||
);
|
||||
|
||||
lng = fallbackLng;
|
||||
}
|
||||
|
||||
return {
|
||||
supportedLngs: languages,
|
||||
fallbackLng,
|
||||
lng,
|
||||
fallbackNS: defaultI18nNamespaces,
|
||||
defaultNS: defaultI18nNamespaces,
|
||||
ns,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user