prodap-lore-locale
Version:
Package used to carry out the internationalization of Lore
439 lines • 17.3 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const localeDeDE = __importStar(require("../translations/translation-de-de.json"));
const localeEnUS = __importStar(require("../translations/translation-en-us.json"));
const localeEsES = __importStar(require("../translations/translation-es-es.json"));
const localeFrFR = __importStar(require("../translations/translation-fr-fr.json"));
const localeItIT = __importStar(require("../translations/translation-it-it.json"));
const localeNlNL = __importStar(require("../translations/translation-nl-nl.json"));
const localePtBR = __importStar(require("../translations/translation-pt-br.json"));
const onlyUnique = (value, index, self) => {
return self.indexOf(value) !== index;
};
const linkJsonSorter = 'https://codeshack.io/json-sorter/';
const keysDeDE = localeDeDE.data.map(x => x.key);
const keysEnus = localeEnUS.data.map(x => x.key);
const keysEses = localeEsES.data.map(x => x.key);
const keysFrFR = localeFrFR.data.map(x => x.key);
const keysItIT = localeItIT.data.map(x => x.key);
const keysNlNL = localeNlNL.data.map(x => x.key);
const keysPtbr = localePtBR.data.map(x => x.key);
const valueDeDE = localeDeDE.data.map(x => x.value);
const valueEnus = localeEnUS.data.map(x => x.value);
const valueEses = localeEsES.data.map(x => x.value);
const valueFrFR = localeFrFR.data.map(x => x.value);
const valueItIT = localeItIT.data.map(x => x.value);
const valueNlNL = localeNlNL.data.map(x => x.value);
const valuePtbr = localePtBR.data.map(x => x.value);
const allLanguageValues = [
valueDeDE,
valueEnus,
valueEses,
valueFrFR,
valueItIT,
valueNlNL,
valuePtbr,
];
describe('Gereral tests', () => {
test('Should return correct list locales', () => {
const locale = new index_1.Locales();
expect(locale.getLocales()).toStrictEqual([
'de-DE',
'en-US',
'es-ES',
'fr-FR',
'it-IT',
'nl-NL',
'pt-BR',
]);
});
test('Check if there is empty space inside HTML tag', () => {
const regex = /<\s+[^>]*>|<[^<]*\s+>/;
const valueString = [];
allLanguageValues.map(item => {
item.map(languageItem => {
if (regex.test(languageItem)) {
valueString.push(languageItem);
return false;
}
});
return true;
});
expect(valueString).toEqual([]);
});
test('Check if there is empty space inside HTML tag', () => {
const valueString = [];
allLanguageValues.map(item => {
item.map(languageItem => {
const matchesClosingHtmlTag = languageItem.split('</').length - 1;
const matchesOpeningHtmlTag = languageItem.split('<').length - 1;
const matchesAngledBracketCloseHtmlTag = languageItem.split('>').length - 1;
if (matchesClosingHtmlTag > matchesOpeningHtmlTag / 2 ||
matchesClosingHtmlTag > matchesAngledBracketCloseHtmlTag / 2) {
valueString.push(languageItem);
}
});
return true;
});
console.log('valueString: ', valueString);
expect(valueString).toEqual([]);
});
test('All languages should have the same amount of keys', () => {
const langKeysLengthArray = [
keysPtbr.length,
keysDeDE.length,
keysEnus.length,
keysEses.length,
keysFrFR.length,
keysItIT.length,
keysNlNL.length,
];
const allEqual = arr => arr.every(val => val === arr[0]);
const result = allEqual(langKeysLengthArray);
console.log('langKeysLengthArray', langKeysLengthArray);
expect(result).toEqual(true);
});
test('Should have the same keys in all locales and the same amount', () => {
let value = true;
let valueString = true;
keysPtbr.map(x => {
if (!keysDeDE.includes(x)) {
value = false;
valueString = `A chave '${x}' não está presente no idioma 'de-DE'\n`;
}
if (!keysEnus.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'en-US'\n`;
}
if (!keysEses.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'es-ES'\n`;
}
if (!keysFrFR.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'fr-FR'\n`;
}
if (!keysItIT.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'it-IT'\n`;
}
if (!keysNlNL.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'nl-NL'\n`;
}
if (!value) {
value = x;
return;
}
});
keysEnus.map(x => {
if (!keysPtbr.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'pt-BR'\n`;
}
if (!keysEses.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'es-ES'\n`;
}
if (!value) {
value = x;
return;
}
});
keysEses.map(x => {
if (!keysPtbr.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'pt-BR'\n`;
}
if (!keysEnus.includes(x)) {
value = false;
if (valueString === true) {
valueString = '';
}
valueString += `A chave '${x}' não está presente no idioma 'en-US'\n`;
}
if (!value) {
value = x;
return;
}
});
expect(valueString).toBe(true);
});
});
describe('Translation-pt-BR', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localePtBR.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(pt-BR): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localePtBR.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados(pt-BR): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localePtBR.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localePtBR.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale corretly', () => {
const locale = new index_1.Locales({ locale: 'pt-BR' });
expect(locale.getCurrentLocale()).toBe('pt-BR');
});
test('Should return correct value to key', () => {
const locale = new index_1.Locales({ locale: 'pt-BR' });
expect(locale.translate('generic_cancel')).toBe('Cancelar');
});
});
describe('Translation-de-DE', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localeDeDE.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(de-DE): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localeDeDE.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados(de-DE): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localeDeDE.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localeDeDE.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale corretly', () => {
const locale = new index_1.Locales({ locale: 'de-DE' });
expect(locale.getCurrentLocale()).toBe('de-DE');
});
});
describe('Translation-en-US', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localeEnUS.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(en-US): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localeEnUS.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados(en-US): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localeEnUS.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localeEnUS.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale corretly', () => {
const locale = new index_1.Locales({ locale: 'en-US' });
expect(locale.getCurrentLocale()).toBe('en-US');
});
test('Should return correct values to keys', () => {
const locale = new index_1.Locales({ locale: 'en-US' });
expect(locale.translate(['generic_cancel', 'generic_login'])).toStrictEqual([
'Cancel',
'Login',
]);
});
});
describe('Translation-es-ES', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localeEsES.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(es-ES): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localeEsES.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados(es-ES): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localeEsES.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localeEsES.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale corretly', () => {
const locale = new index_1.Locales({ locale: 'es-ES' });
expect(locale.getCurrentLocale()).toBe('es-ES');
});
});
describe('Translation-fr-FR', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localeFrFR.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(fr-FR): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localeFrFR.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados(fr-FR): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localeFrFR.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localeFrFR.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale corretly', () => {
const locale = new index_1.Locales({ locale: 'fr-FR' });
expect(locale.getCurrentLocale()).toBe('fr-FR');
});
});
describe('Translation-it-IT', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localeItIT.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(it-IT): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localeItIT.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados(it-IT): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localeItIT.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localeItIT.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale corretly', () => {
const locale = new index_1.Locales({ locale: 'it-IT' });
expect(locale.getCurrentLocale()).toBe('it-IT');
});
});
describe('Translation-nl-NL', () => {
beforeAll(() => null);
test('Should have unique keys in json file', () => {
const uniqueKeys = localeNlNL.data.map(x => x.key).filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Chaves duplicadas(nl-NL): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have unique values in json file', () => {
const uniqueKeys = localeNlNL.data
.filter(({ isDuplicated }) => !isDuplicated)
.map(x => x.value)
.filter(onlyUnique);
let valueString = '';
if (uniqueKeys.length > 0) {
valueString = `Valores duplicados((nl-NL): '${uniqueKeys}'`;
}
expect(valueString).toBe('');
});
test('Should have ordered keys', () => {
const keys = localeNlNL.data.map(x => x.key);
keys.sort((prev, next) => prev.localeCompare(next));
expect(localeNlNL.data.map(x => x.key)).toStrictEqual(keys);
});
test('Should set currentLocale correctly', () => {
const locale = new index_1.Locales({ locale: '(nl-NL' });
expect(locale.getCurrentLocale()).toBe('(nl-NL');
});
});
//# sourceMappingURL=index.test.js.map