Files
myeasycms-v2/apps/dev-tool/lib/i18n/i18n.settings.ts
Giancarlo Buomprisco ad427365c9 Storybook (#328)
* feat(docs): add interactive examples and API references for Button, Card, and LoadingFallback components
- Updated dependencies
- Set `retries` to a fixed value of 3 for consistent test retries across environments.
- Increased `timeout` from 60 seconds to 120 seconds to allow more time for tests to complete.
- Reduced `expect` timeout from 10 seconds to 5 seconds for quicker feedback on assertions.
2025-08-22 07:35:44 +08:00

53 lines
1.3 KiB
TypeScript

import { createI18nSettings } from '@kit/i18n';
/**
* The default language of the application.
* This is used as a fallback language when the selected language is not supported.
*/
const defaultLanguage = process.env.NEXT_PUBLIC_DEFAULT_LOCALE ?? 'en';
/**
* The list of supported languages.
* By default, only the default language is supported.
* Add more languages here if needed.
*/
export const languages: string[] = [defaultLanguage];
/**
* The name of the cookie that stores the selected language.
*/
export const I18N_COOKIE_NAME = 'lang';
/**
* The default array of Internationalization (i18n) namespaces.
* These namespaces are commonly used in the application for translation purposes.
*/
export const defaultI18nNamespaces = ['common'];
/**
* Get the i18n settings for the given language and namespaces.
* If the language is not supported, it will fall back to the default language.
* @param language
* @param ns
*/
export function getI18nSettings(
language: string | undefined,
ns: string | string[] = defaultI18nNamespaces,
) {
let lng = language ?? defaultLanguage;
if (!languages.includes(lng)) {
console.warn(
`Language "${lng}" is not supported. Falling back to "${defaultLanguage}"`,
);
lng = defaultLanguage;
}
return createI18nSettings({
language: lng,
namespaces: ns,
languages,
});
}