anytv-i18n
Advanced tools
Comparing version 2.1.2 to 2.2.0
48
index.js
@@ -233,2 +233,5 @@ 'use strict'; | ||
this.locale_folder = path__default['default'].resolve(this.config.get('locale_dir')); | ||
this.metadata_file = this.locale_folder + '/meta.json'; | ||
this.ensure_dir_existence(this.locale_folder); | ||
@@ -345,10 +348,39 @@ | ||
this.debug('getting languages'); | ||
const service_version = this.config.get('service_version'); | ||
const response = await axios__default['default'].get(this.languages_url); | ||
let meta = {}; | ||
const languages = response.data; | ||
try { | ||
// force download | ||
if (process.env.REFRESH_TRANSLATIONS) { | ||
throw new Error('force-refresh'); | ||
} | ||
this.languages = languages.data.languages; | ||
// load languages and version from meta.json | ||
meta = JSON.parse( | ||
await fs_promises.readFile(this.metadata_file) | ||
); | ||
// redownload on version mismatch | ||
if (meta.version !== service_version) { | ||
throw new Error('version-mismatch'); | ||
} | ||
/** | ||
* Since we have a valid updated meta.json, we'll assume the | ||
* previous download was successful | ||
*/ | ||
return; | ||
} | ||
catch (error) { | ||
// download from server on error or REFRESH_TRANSLATIONS | ||
const response = await axios__default['default'].get(this.languages_url); | ||
meta = response.data.data; | ||
} | ||
meta.version = service_version; | ||
this.languages = meta.languages; | ||
let default_lang = this.config.get('default'); | ||
@@ -361,3 +393,3 @@ | ||
return new Promise(resolve => { | ||
await new Promise(resolve => { | ||
async__default['default'].each( | ||
@@ -369,2 +401,8 @@ this.languages, | ||
}); | ||
// save meta.json | ||
await fs_promises.writeFile( | ||
this.metadata_file, | ||
JSON.stringify(meta) | ||
); | ||
} | ||
@@ -371,0 +409,0 @@ |
{ | ||
"name": "anytv-i18n", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "A module for globalization", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
15285
4
353
4