B2B-88: add starter kit structure and elements
This commit is contained in:
31
lib/i18n/i18n.resolver.ts
Normal file
31
lib/i18n/i18n.resolver.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
/**
|
||||
* @name i18nResolver
|
||||
* @description Resolve the translation file for the given language and namespace in the current application.
|
||||
* @param language
|
||||
* @param namespace
|
||||
*/
|
||||
export async function i18nResolver(language: string, namespace: string) {
|
||||
const logger = await getLogger();
|
||||
|
||||
try {
|
||||
const data = await import(
|
||||
`../../public/locales/${language}/${namespace}.json`
|
||||
);
|
||||
|
||||
return data as Record<string, string>;
|
||||
} catch (error) {
|
||||
console.group(
|
||||
`Error while loading translation file: ${language}/${namespace}`,
|
||||
);
|
||||
logger.error(error instanceof Error ? error.message : error);
|
||||
logger.warn(
|
||||
`Please create a translation file for this language at "public/locales/${language}/${namespace}.json"`,
|
||||
);
|
||||
console.groupEnd();
|
||||
|
||||
// return an empty object if the file could not be loaded to avoid loops
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user