@ribajs/i18n
Advanced tools
Comparing version 0.18.1 to 0.18.2
{ | ||
"name": "@ribajs/i18n", | ||
"description": "Internationalization extension for Riba.js", | ||
"version": "0.18.1", | ||
"version": "0.18.2", | ||
"author": "Pascal Garber <pascal@jumplink.eu>", | ||
@@ -24,3 +24,4 @@ "url": "https://github.com/ribajs/riba/tree/master/packages/i18n", | ||
"build": "npm run build:module", | ||
"build:module": "tsc" | ||
"build:module": "tsc", | ||
"link": "npm link; npm link @ribajs/core" | ||
}, | ||
@@ -27,0 +28,0 @@ "devDependencies": { |
@@ -115,2 +115,3 @@ import { | ||
protected setLangcode(langcode: string) { | ||
this.debug('setLangcode', langcode); | ||
this.localesService.setLangcode(langcode); | ||
@@ -117,0 +118,0 @@ } |
@@ -119,2 +119,3 @@ import { Utils, EventDispatcher, Debug } from '@ribajs/core'; | ||
if (this.currentLangcode !== langcode) { | ||
this.debug('setLangcode', langcode, this.currentLangcode); | ||
this.currentLangcode = langcode; | ||
@@ -203,12 +204,8 @@ | ||
protected init() { | ||
protected async init() { | ||
this.initalLangcode = this.getHTMLLangcode(); | ||
this.currentLangcode = this.initalLangcode; | ||
this._ready = true; | ||
if (!this.initalLangcode ) { | ||
throw new Error(`The lang attribute on the html element is requred to detect the default theme language: ${this.initalLangcode}`); | ||
} | ||
} | ||
protected async switchToBrowserLanguage() { | ||
// Detect browser language and switch to this language when available | ||
@@ -231,2 +228,3 @@ const browserLangcode = this.getBrowserLangcode(); | ||
.then((availableLangcodes) => { | ||
this._ready = true; | ||
// If the current langcode is not the inital langcode then translation is needed | ||
@@ -233,0 +231,0 @@ const translationNeeded = this.currentLangcode !== this.initalLangcode || !this.doNotTranslateDefaultLanguage; |
@@ -40,4 +40,2 @@ import { Debug, Utils } from '@ribajs/core'; | ||
this.init(); | ||
if (LocalesRestService.instances[this.url]) { | ||
@@ -47,4 +45,3 @@ return LocalesRestService.instances[this.url]; | ||
this.switchToBrowserLanguage(); | ||
this.init(); | ||
LocalesRestService.instances[this.url] = this; | ||
@@ -73,4 +70,5 @@ } | ||
return Utils.getJSON(url) | ||
.then((locals: any /** TODO any */) => { | ||
this.locales[url as string] = locals; | ||
.then((locales: any) => { | ||
this.locales[url as string] = locales; | ||
this.debug('getAll', locales); | ||
return this.locales[url as string]; | ||
@@ -77,0 +75,0 @@ }); |
@@ -31,4 +31,2 @@ import { Debug } from '@ribajs/core'; | ||
this.init(); | ||
if (LocalesStaticService.instances[id]) { | ||
@@ -38,4 +36,3 @@ return LocalesStaticService.instances[id]; | ||
this.switchToBrowserLanguage(); | ||
this.init(); | ||
LocalesStaticService.instances[id] = this; | ||
@@ -42,0 +39,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52395
1371