Skip to content

Commit 35eee8a

Browse files
committed
Added onLoad Option which is called after language is loaded.
1 parent 6d7f0db commit 35eee8a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ let sharedInstance: I18n = null
2121
const DEFAULT_OPTIONS: OptionsInterface = {
2222
lang: !isServer && document.documentElement.lang ? document.documentElement.lang.replace('-', '_') : null,
2323
fallbackLang: 'en',
24-
resolve: (lang: string) => new Promise((resolve) => resolve({ default: {} }))
24+
resolve: (lang: string) => new Promise((resolve) => resolve({ default: {} })),
25+
onLoad: (lang: string) => {}
2526
}
2627

2728
/**
@@ -157,7 +158,13 @@ export class I18n {
157158
* Loads the language.
158159
*/
159160
load(): void {
160-
this[isServer ? 'loadLanguage' : 'loadLanguageAsync'](this.getActiveLanguage())
161+
const lang = this.getActiveLanguage()
162+
if (isServer) {
163+
this.loadLanguage(lang)
164+
this.options.onLoad(lang)
165+
} else {
166+
this.loadLanguageAsync(lang).then(this.options.onLoad)
167+
}
161168
}
162169

163170
/**

src/interfaces/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export interface OptionsInterface {
77
lang?: string
88
fallbackLang?: string
99
resolve?(lang: string): Promise<LanguageJsonFileInterface>
10+
onLoad?: (lang: string) => void
1011
}

0 commit comments

Comments
 (0)