Skip to content

Commit

Permalink
Merge pull request #263 from mattolson/patch
Browse files Browse the repository at this point in the history
STRF-9434: Bug fix to load test
  • Loading branch information
mattolson authored Jan 31, 2022
2 parents bad4620 + b802c7c commit 02c18de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 3 additions & 5 deletions lib/translator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ Translator.create = function (acceptLanguage, allTranslations, logger = console)
* @returns {string}
*/
Translator.prototype.translate = function (key, parameters) {
const language = this.getLanguage();
if (!language.translations || !language.translations[key]) {
if (!this._language.translations || !this._language.translations[key]) {
return key;
}

Expand Down Expand Up @@ -157,12 +156,11 @@ Translator.prototype._getFormatter = function (locale) {
* @return {Function}
*/
Translator.prototype._compileTemplate = function (key) {
const language = this.getLanguage();
const locale = language.locales[key];
const locale = this._language.locales[key];
const formatter = this._getFormatter(locale);

try {
return formatter.compile(language.translations[key]);
return formatter.compile(this._language.translations[key]);
} catch (err) {
if (err.name === 'SyntaxError') {
this._logger.error(`Language File Syntax Error: ${err.message} for key "${key}"`, err.expected);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"lint": "eslint .",
"lint-and-fix": "eslint . --fix",
"test": "lab -v -t 94 --ignore i18n,WebAssembly,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask,FinalizationRegistry,WeakRef,plural,en,number,select spec",
"test": "lab -v -t 95 --ignore i18n,WebAssembly,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask,FinalizationRegistry,WeakRef,plural,en,number,select spec",
"coverage": "lab -c -r console -o stdout -r html -o coverage.html spec"
},
"repository": {
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,18 @@ describe('Translator', () => {
// Lab will output the amount of time spent in this test. We can use it to
// compare relative speed of different implementations.
it('load test', { timeout: 5000, skip: true }, done => {
fs.readFile('./spec/fixtures/lang.json', 'utf8' , (err, translations) => {
fs.readFile('./spec/fixtures/lang.json', 'utf8' , (err, data) => {
if (err) {
console.error(err);
throw err;
}

translations = JSON.parse(data);

for (let i = 0; i < 1000; i++) {
Translator.create('fr-CA', translations);
Translator.create('fr-CA, fr, en', translations);
}

done();
});
});
Expand Down

0 comments on commit 02c18de

Please sign in to comment.