Skip to content

Commit 1f4baed

Browse files
committed
refactor: move properties to abstract class
1 parent 8c7c535 commit 1f4baed

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

packages/runtime-core/src/i18n.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,25 @@ export type TranslatorOptions<T extends { [key: string]: unknown }> = {
3636

3737
/** @public */
3838
export abstract class BaseTranslator<T extends { [key: string]: unknown } = { [key: string]: unknown }> {
39-
protected abstract currentDocumentLanguage: Language | null;
40-
protected abstract fallbackLanguage: Language;
41-
protected abstract handleLanguageChange: LanguageChangeHandler | null;
42-
isInitialized: boolean;
43-
protected abstract translations: T;
39+
protected currentDocumentLanguage: Language | null;
40+
protected fallbackLanguage: Language;
41+
protected handleLanguageChange: LanguageChangeHandler | null;
42+
public isInitialized: boolean;
43+
protected translations: T;
4444

45-
constructor() {
45+
constructor({ fallbackLanguage, translations }: TranslatorOptions<T>) {
46+
this.currentDocumentLanguage = null;
47+
this.fallbackLanguage = fallbackLanguage ?? 'en';
48+
this.handleLanguageChange = null;
4649
this.isInitialized = false;
50+
this.translations = translations;
4751
}
4852
}
4953

5054
/** @public */
5155
export class Translator<T extends { [key: string]: unknown }> extends BaseTranslator<T> {
52-
protected currentDocumentLanguage: Language | null;
53-
protected fallbackLanguage: Language;
54-
protected handleLanguageChange: LanguageChangeHandler | null;
55-
protected translations: T;
56-
5756
constructor(options: TranslatorOptions<T>) {
58-
super();
59-
this.currentDocumentLanguage = null;
60-
this.fallbackLanguage = options.fallbackLanguage ?? 'en';
61-
this.handleLanguageChange = null;
62-
this.translations = options.translations;
57+
super(options);
6358
}
6459

6560
@InitializedOnly

0 commit comments

Comments
 (0)