Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: i18nextService uses namespace "KoliBri" #5610

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/components/src/core/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ export interface II18nService {

export class I18nextService implements II18nService {
private static instance: II18nService;
private static namespace = 'KoliBri';

private constructor() {}

public static async getInstance(
public static async createInstance(
lng: Generic.I18n.Locale.ISO_639_1,
translations?:
| Generic.I18n.RegisterPatch<Generic.I18n.Locale.ISO_639_1, string, string>
Expand All @@ -50,9 +51,14 @@ export class I18nextService implements II18nService {

I18nextService.instance = new I18nextService();

await i18next.init({
lng,
});
if (!i18next.isInitialized) {
await i18next.init({
ns: [I18nextService.namespace],
lng,
});
} else {
await i18next.loadNamespaces(I18nextService.namespace);
}

if (translations !== undefined) {
translations.forEach((t) =>
Expand All @@ -67,7 +73,7 @@ export class I18nextService implements II18nService {
}

public static addResourceBundle(lng: Generic.I18n.Locale.ISO_639_1, translationMap: Generic.I18n.Map<string, string>) {
i18next.addResourceBundle(lng, 'translation', translationMap, true);
i18next.addResourceBundle(lng, I18nextService.namespace, translationMap, true);
}

public addResourceBundle(lng: Generic.I18n.Locale.ISO_639_1, translationMap: Generic.I18n.Map<string, string>) {
Expand All @@ -76,6 +82,7 @@ export class I18nextService implements II18nService {

public translate(key: string, options?: ITranslationOptions) {
return i18next.t(key, {
ns: I18nextService.namespace,
count: options?.count,
...options?.placeholders,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const register = async (
options?: RegisterOptions
): Promise<void[]> => {
if (STORE.I18n === undefined) {
const i18n = await I18nextService.getInstance(options?.translation?.name ?? 'de', options?.translations);
const i18n = await I18nextService.createInstance(options?.translation?.name ?? 'de', options?.translations);
Object.defineProperty(STORE, 'I18n', {
value: i18n,
writable: false,
Expand Down
Loading