Socket
Socket
Sign inDemoInstall

@tginternal/language-util

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tginternal/language-util - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

4

lib/flags.test.js

@@ -44,3 +44,5 @@ "use strict";

var _a;
return (__assign(__assign({}, acc), (_a = {}, _a[curr] = languages_1.getLanguageRegions(curr).map(function (r) { return flags_1.getCountryFlagEmoji(r); }), _a)));
return (__assign(__assign({}, acc), (_a = {}, _a[curr] = languages_1.getLanguageRegions(curr).map(function (r) {
return flags_1.getCountryFlagEmoji(r);
}), _a)));
}, {});

@@ -47,0 +49,0 @@ expect(result['en'][0]).toEqual('🇬🇧');

@@ -46,3 +46,45 @@ "use strict";

});
describe('languages', function () {
test('returns correct language population', function () {
var population = languageInfo_1.languageInfo['en'].population;
expect(population).toBeGreaterThan(1000000000);
});
test('returns correct language cs', function () {
var population = languageInfo_1.languageInfo['cs'].population;
expect(population).toBeGreaterThan(9000000);
});
test('returns correct language cs-CZ', function () {
var population = languageInfo_1.languageInfo['cs-CZ'].population;
expect(population).toBeGreaterThan(9000000);
});
test('returns correct language zh-Hans', function () {
var population = languageInfo_1.languageInfo['zh-Hans'].population;
expect(population).toBeGreaterThan(9000000);
});
test('returns territory by language', function () {
var territories = languageInfo_1.languageInfo['cs'].regions;
expect(territories).toEqual(['CZ']);
});
test('returns territory from parsed region', function () {
var territories = languageInfo_1.languageInfo['en-US'].regions;
expect(territories).toEqual(['US']);
});
test('returns correct territories for english', function () {
var territories = languageInfo_1.languageInfo['en'].regions;
expect(territories.length).toEqual(89);
expect(territories[0]).toEqual('GB');
expect(territories[1]).toEqual('US');
});
test('returns territories for spanish', function () {
var territories = languageInfo_1.languageInfo['es'].regions;
expect(territories.length).toEqual(23);
expect(territories[0]).toEqual('ES');
});
test('returns territories for french', function () {
var territories = languageInfo_1.languageInfo['fr'].regions;
expect(territories.length).toEqual(45);
expect(territories[0]).toEqual('FR');
});
});
});
//# sourceMappingURL=languageInfo.test.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportedFlags = void 0;
exports.supportedFlags = ["🇳🇦", "🇪🇹", "🇪🇬", "🇩🇿", "🇸🇩", "🇮🇶", "🇾🇪", "🇲🇦", "🇸🇾", "🇯🇴", "🇹🇳", "🇦🇪", "🇱🇾", "🇵🇸", "🇸🇦", "🇱🇧", "🇸🇴", "🇴🇲", "🇲🇷", "🇰🇼", "🇹🇩", "🇶🇦", "🇮🇱", "🇧🇭", "🇪🇭", "🇰🇲", "🇪🇷", "🇩🇯", "🇸🇸", "🇦🇿", "🇧🇾", "🇧🇬", "🇧🇩", "🇮🇳", "🇧🇦", "🇦🇩", "🇪🇸", "🇫🇷", "🇮🇹", "🇨🇿", "🇩🇰", "🇬🇱", "🇩🇪", "🇦🇹", "🇨🇭", "🇧🇪", "🇱🇺", "🇱🇮", "🇬🇷", "🇨🇾", "🇬🇧", "🇺🇸", "🇵🇰", "🇳🇬", "🇵🇭", "🇹🇿", "🇦🇺", "🇰🇪", "🇬🇭", "🇮🇪", "🇲🇬", "🇱🇷", "🇭🇰", "🇯🇲", "🇧🇼", "🇬🇲", "🇧🇧", "🇧🇸", "🇧🇿", "🇦🇬", "🇨🇦", "🇿🇦", "🇲🇼", "🇨🇲", "🇿🇼", "🇸🇬", "🇳🇿", "🇵🇬", "🇿🇲", "🇸🇱", "🇷🇼", "🇺🇬", "🇵🇷", "🇲🇺", "🇸🇿", "🇸🇧", "🇲🇹", "🇹🇹", "🇩🇲", "🇫🇯", "🇬🇾", "🇱🇸", "🇻🇺", "🇬🇺", "🇱🇨", "🇬🇩", "🇬🇬", "🇮🇲", "🇰🇮", "🇻🇨", "🇲🇭", "🇧🇲", "🇫🇲", "🇰🇳", "🇰🇾", "🇦🇸", "🇬🇮", "🇦🇮", "🇯🇪", "🇻🇮", "🇹🇨", "🇲🇵", "🇻🇬", "🇸🇨", "🇸🇽", "🇹🇴", "🇳🇷", "🇨🇰", "🇧🇮", "🇸🇭", "🇼🇸", "🇮🇴", "🇲🇸", "🇫🇰", "🇵🇼", "🇳🇫", "🇨🇽", "🇹🇰", "🇳🇺", "🇹🇻", "🇩🇬", "🇺🇲", "🇨🇨", "🇵🇳", "🇫🇮", "🇲🇴", "🇲🇾", "🇳🇱", "🇸🇪", "🇸🇮", "🇲🇽", "🇨🇴", "🇦🇷", "🇻🇪", "🇵🇪", "🇨🇱", "🇪🇨", "🇬🇹", "🇨🇺", "🇩🇴", "🇭🇳", "🇧🇴", "🇸🇻", "🇨🇷", "🇳🇮", "🇺🇾", "🇵🇦", "🇬🇶", "🇵🇾", "🇪🇦", "🇮🇨", "🇧🇷", "🇪🇪", "🇮🇷", "🇦🇫", "🇨🇮", "🇲🇱", "🇧🇫", "🇳🇪", "🇸🇳", "🇹🇬", "🇧🇯", "🇨🇬", "🇨🇩", "🇬🇳", "🇨🇫", "🇬🇦", "🇷🇪", "🇭🇹", "🇲🇶", "🇬🇵", "🇳🇨", "🇵🇫", "🇬🇫", "🇾🇹", "🇲🇨", "🇲🇫", "🇼🇫", "🇧🇱", "🇵🇲", "🇭🇷", "🇭🇺", "🇦🇲", "🇮🇩", "🇮🇸", "🇸🇲", "🇻🇦", "🇯🇵", "🇬🇪", "🇰🇿", "🇰🇭", "🇰🇷", "🇰🇵", "🇰🇬", "🇱🇦", "🇱🇹", "🇱🇻", "🇲🇰", "🇲🇳", "🇧🇳", "🇲🇲", "🇳🇴", "🇸🇯", "🇳🇵", "🇸🇷", "🇦🇼", "🇧🇶", "🇨🇼", "🇵🇱", "🇦🇴", "🇵🇹", "🇲🇿", "🇬🇼", "🇹🇱", "🇨🇻", "🇸🇹", "🇷🇴", "🇲🇩", "🇷🇺", "🇺🇦", "🇱🇰", "🇸🇰", "🇦🇱", "🇽🇰", "🇷🇸", "🇲🇪", "🇦🇽", "🇹🇭", "🇹🇲", "🇹🇷", "🇺🇿", "🇻🇳", "🇹🇼", "🇨🇳", "🇧🇹", "🇫🇴", "🇹🇯", "🏁"];
exports.supportedFlags = [
'🇳🇦',
'🇪🇹',
'🇪🇬',
'🇩🇿',
'🇸🇩',
'🇮🇶',
'🇾🇪',
'🇲🇦',
'🇸🇾',
'🇯🇴',
'🇹🇳',
'🇦🇪',
'🇱🇾',
'🇵🇸',
'🇸🇦',
'🇱🇧',
'🇸🇴',
'🇴🇲',
'🇲🇷',
'🇰🇼',
'🇹🇩',
'🇶🇦',
'🇮🇱',
'🇧🇭',
'🇪🇭',
'🇰🇲',
'🇪🇷',
'🇩🇯',
'🇸🇸',
'🇦🇿',
'🇧🇾',
'🇧🇬',
'🇧🇩',
'🇮🇳',
'🇧🇦',
'🇦🇩',
'🇪🇸',
'🇫🇷',
'🇮🇹',
'🇨🇿',
'🇩🇰',
'🇬🇱',
'🇩🇪',
'🇦🇹',
'🇨🇭',
'🇧🇪',
'🇱🇺',
'🇱🇮',
'🇬🇷',
'🇨🇾',
'🇬🇧',
'🇺🇸',
'🇵🇰',
'🇳🇬',
'🇵🇭',
'🇹🇿',
'🇦🇺',
'🇰🇪',
'🇬🇭',
'🇮🇪',
'🇲🇬',
'🇱🇷',
'🇭🇰',
'🇯🇲',
'🇧🇼',
'🇬🇲',
'🇧🇧',
'🇧🇸',
'🇧🇿',
'🇦🇬',
'🇨🇦',
'🇿🇦',
'🇲🇼',
'🇨🇲',
'🇿🇼',
'🇸🇬',
'🇳🇿',
'🇵🇬',
'🇿🇲',
'🇸🇱',
'🇷🇼',
'🇺🇬',
'🇵🇷',
'🇲🇺',
'🇸🇿',
'🇸🇧',
'🇲🇹',
'🇹🇹',
'🇩🇲',
'🇫🇯',
'🇬🇾',
'🇱🇸',
'🇻🇺',
'🇬🇺',
'🇱🇨',
'🇬🇩',
'🇬🇬',
'🇮🇲',
'🇰🇮',
'🇻🇨',
'🇲🇭',
'🇧🇲',
'🇫🇲',
'🇰🇳',
'🇰🇾',
'🇦🇸',
'🇬🇮',
'🇦🇮',
'🇯🇪',
'🇻🇮',
'🇹🇨',
'🇲🇵',
'🇻🇬',
'🇸🇨',
'🇸🇽',
'🇹🇴',
'🇳🇷',
'🇨🇰',
'🇧🇮',
'🇸🇭',
'🇼🇸',
'🇮🇴',
'🇲🇸',
'🇫🇰',
'🇵🇼',
'🇳🇫',
'🇨🇽',
'🇹🇰',
'🇳🇺',
'🇹🇻',
'🇩🇬',
'🇺🇲',
'🇨🇨',
'🇵🇳',
'🇫🇮',
'🇲🇴',
'🇲🇾',
'🇳🇱',
'🇸🇪',
'🇸🇮',
'🇲🇽',
'🇨🇴',
'🇦🇷',
'🇻🇪',
'🇵🇪',
'🇨🇱',
'🇪🇨',
'🇬🇹',
'🇨🇺',
'🇩🇴',
'🇭🇳',
'🇧🇴',
'🇸🇻',
'🇨🇷',
'🇳🇮',
'🇺🇾',
'🇵🇦',
'🇬🇶',
'🇵🇾',
'🇪🇦',
'🇮🇨',
'🇧🇷',
'🇪🇪',
'🇮🇷',
'🇦🇫',
'🇨🇮',
'🇲🇱',
'🇧🇫',
'🇳🇪',
'🇸🇳',
'🇹🇬',
'🇧🇯',
'🇨🇬',
'🇨🇩',
'🇬🇳',
'🇨🇫',
'🇬🇦',
'🇷🇪',
'🇭🇹',
'🇲🇶',
'🇬🇵',
'🇳🇨',
'🇵🇫',
'🇬🇫',
'🇾🇹',
'🇲🇨',
'🇲🇫',
'🇼🇫',
'🇧🇱',
'🇵🇲',
'🇭🇷',
'🇭🇺',
'🇦🇲',
'🇮🇩',
'🇮🇸',
'🇸🇲',
'🇻🇦',
'🇯🇵',
'🇬🇪',
'🇰🇿',
'🇰🇭',
'🇰🇷',
'🇰🇵',
'🇰🇬',
'🇱🇦',
'🇱🇹',
'🇱🇻',
'🇲🇰',
'🇲🇳',
'🇧🇳',
'🇲🇲',
'🇳🇴',
'🇸🇯',
'🇳🇵',
'🇸🇷',
'🇦🇼',
'🇧🇶',
'🇨🇼',
'🇵🇱',
'🇦🇴',
'🇵🇹',
'🇲🇿',
'🇬🇼',
'🇹🇱',
'🇨🇻',
'🇸🇹',
'🇷🇴',
'🇲🇩',
'🇷🇺',
'🇺🇦',
'🇱🇰',
'🇸🇰',
'🇦🇱',
'🇽🇰',
'🇷🇸',
'🇲🇪',
'🇦🇽',
'🇹🇭',
'🇹🇲',
'🇹🇷',
'🇺🇿',
'🇻🇳',
'🇹🇼',
'🇨🇳',
'🇧🇹',
'🇫🇴',
'🇹🇯',
'🏁',
];
//# sourceMappingURL=supportedFlags.js.map

@@ -1,4 +0,3 @@

export declare const getLanguagePopulation: (language: string) => number;
export declare const getLanguageRegions: (locale: string) => string[];
export declare const isValidLanguageTag: (tag: string) => boolean;
export declare const getLanguageRegions: (language: string) => string[];
export interface TerritoryInfo {

@@ -5,0 +4,0 @@ languagePopulation?: {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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;
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidLanguageTag = exports.getLanguageRegions = exports.getLanguagePopulation = void 0;
var territoryInfoData = __importStar(require("cldr-core/supplemental/territoryInfo.json"));
exports.getLanguageRegions = exports.isValidLanguageTag = void 0;
var intl_getcanonicallocales_1 = require("@formatjs/intl-getcanonicallocales");
var languageTerritoryOrder_1 = require("./languageTerritoryOrder");
var languageData = __importStar(require("cldr-core/supplemental/languageData.json"));
var getLanguagePopulation = function (language) {
var _a, _b;
var parsed = intl_getcanonicallocales_1.parseUnicodeLanguageId(language);
var info = territoryInfoData.supplemental.territoryInfo;
if (parsed.region) {
var regionInfo = info[parsed.region];
var populationPercent = (_b = (_a = regionInfo === null || regionInfo === void 0 ? void 0 : regionInfo.languagePopulation) === null || _a === void 0 ? void 0 : _a[parsed.lang]) === null || _b === void 0 ? void 0 : _b._populationPercent;
var population = regionInfo === null || regionInfo === void 0 ? void 0 : regionInfo._population;
if (population && populationPercent) {
return (parseInt(populationPercent) / 100) * parseInt(population);
}
return 0;
}
return Object.values(info).reduce(function (acc, data) {
var _a;
var typedData = data;
var languagePopulation = (_a = typedData.languagePopulation) === null || _a === void 0 ? void 0 : _a[parsed.lang];
if (languagePopulation &&
languagePopulation._populationPercent &&
typedData._population) {
return (acc +
Math.ceil((parseFloat(languagePopulation._populationPercent) / 100) *
parseInt(typedData._population)));
}
return acc;
}, 0);
};
exports.getLanguagePopulation = getLanguagePopulation;
var getLanguageRegions = function (locale) {
var parsed = intl_getcanonicallocales_1.parseUnicodeLanguageId(locale);
if (parsed.region) {
return [parsed.region];
}
if (parsed.lang) {
var info = languageData.supplemental.languageData;
var langInfo = info[parsed.lang];
var territories = langInfo === null || langInfo === void 0 ? void 0 : langInfo._territories;
if (!territories) {
return [];
}
return sortTerritoriesByLanguage(territories, parsed.lang) || [];
}
return [];
};
exports.getLanguageRegions = getLanguageRegions;
var languageInfo_1 = require("./generated/languageInfo");
var isValidLanguageTag = function (tag) {

@@ -97,66 +10,4 @@ return intl_getcanonicallocales_1.isStructurallyValidLanguageTag(tag);

exports.isValidLanguageTag = isValidLanguageTag;
var getTerritoriesLanguagePopulations = function (territories, language) {
var info = territoryInfoData.supplemental.territoryInfo;
var territoriesLanguagePopulation = {};
territories.forEach(function (t) {
var _a;
var territoryData = info[t];
var languagePopulation = (_a = territoryData === null || territoryData === void 0 ? void 0 : territoryData.languagePopulation) === null || _a === void 0 ? void 0 : _a[language];
if (languagePopulation) {
territoriesLanguagePopulation[t] = languagePopulation;
territoriesLanguagePopulation[t].territoryTotalPopulation =
territoryData === null || territoryData === void 0 ? void 0 : territoryData._population;
}
});
return territoriesLanguagePopulation;
};
var sortTerritoriesByLanguage = function (territories, language) {
var customOrder = languageTerritoryOrder_1.languageTerritoryOrder[language] || [];
territories = territories.filter(function (t) { return customOrder.indexOf(t) === -1; });
var territoriesLanguagePopulation = getTerritoriesLanguagePopulations(territories, language);
territories.sort(function (a, b) {
var _a, _b, _c, _d, _e, _f;
var aOfficialStatus = (_a = territoriesLanguagePopulation[a]) === null || _a === void 0 ? void 0 : _a._officialStatus;
var bOfficialStatus = (_b = territoriesLanguagePopulation[b]) === null || _b === void 0 ? void 0 : _b._officialStatus;
if ((aOfficialStatus == 'official' ||
aOfficialStatus == 'de_facto_official') &&
bOfficialStatus != 'official' &&
bOfficialStatus !== 'de_facto_official') {
return -1;
}
if ((bOfficialStatus == 'official' ||
bOfficialStatus == 'de_facto_official') &&
aOfficialStatus != 'official' &&
aOfficialStatus !== 'de_facto_official') {
return -1;
}
if (aOfficialStatus == 'official_regional' &&
bOfficialStatus != 'official_regional') {
return -1;
}
if (bOfficialStatus == 'official_regional' &&
aOfficialStatus != 'official_regional') {
return 1;
}
var aPercent = (_c = territoriesLanguagePopulation[a]) === null || _c === void 0 ? void 0 : _c._populationPercent;
var bPercent = (_d = territoriesLanguagePopulation[b]) === null || _d === void 0 ? void 0 : _d._populationPercent;
var aTotalPopulation = (_e = territoriesLanguagePopulation[a]) === null || _e === void 0 ? void 0 : _e.territoryTotalPopulation;
var bTotalPopulation = (_f = territoriesLanguagePopulation[b]) === null || _f === void 0 ? void 0 : _f.territoryTotalPopulation;
if (aPercent === bPercent) {
return 0;
}
if (aPercent && !bPercent) {
return -1;
}
if (bPercent && !aPercent) {
return 1;
}
if (!aTotalPopulation || !bTotalPopulation) {
return 0;
}
return (parseFloat(bPercent) * parseInt(bTotalPopulation) -
parseFloat(aPercent) * parseInt(aTotalPopulation));
});
return __spreadArray(__spreadArray([], __read(customOrder)), __read(territories));
};
var getLanguageRegions = function (language) { var _a; return ((_a = languageInfo_1.languageInfo[language]) === null || _a === void 0 ? void 0 : _a.regions) || []; };
exports.getLanguageRegions = getLanguageRegions;
//# sourceMappingURL=languages.js.map

@@ -5,22 +5,2 @@ "use strict";

describe('languages', function () {
test('returns correct language population', function () {
var population = languages_1.getLanguagePopulation('en');
expect(population).toBeGreaterThan(1000000000);
});
test('returns correct language cs', function () {
var population = languages_1.getLanguagePopulation('cs');
expect(population).toBeGreaterThan(9000000);
});
test('returns correct language cs-CZ', function () {
var population = languages_1.getLanguagePopulation('cs-CZ');
expect(population).toBeGreaterThan(9000000);
});
test('returns correct language zh-Hans', function () {
var population = languages_1.getLanguagePopulation('zh-Hans');
expect(population).toBeGreaterThan(9000000);
});
test('returns territory by language', function () {
var territories = languages_1.getLanguageRegions('cs');
expect(territories).toEqual(['CZ']);
});
test('returns territory from parsed region', function () {

@@ -30,19 +10,7 @@ var territories = languages_1.getLanguageRegions('en-US');

});
test('returns correct territories for english', function () {
var territories = languages_1.getLanguageRegions('en');
expect(territories.length).toEqual(89);
expect(territories[0]).toEqual('GB');
expect(territories[1]).toEqual('US');
test('validates language tag', function () {
expect(languages_1.isValidLanguageTag('en')).toBeTruthy();
expect(languages_1.isValidLanguageTag('en_de')).toBeFalsy();
});
test('returns territories for spanish', function () {
var territories = languages_1.getLanguageRegions('es');
expect(territories.length).toEqual(23);
expect(territories[0]).toEqual('ES');
});
test('returns territories for french', function () {
var territories = languages_1.getLanguageRegions('fr');
expect(territories.length).toEqual(45);
expect(territories[0]).toEqual('FR');
});
});
//# sourceMappingURL=languages.test.js.map
{
"name": "@tginternal/language-util",
"version": "1.0.1",
"version": "1.0.2",
"description": "Language data utility for Tolgee localization tool",

@@ -45,8 +45,9 @@ "main": "lib/index.js",

"ts-node": "^10.0.0",
"typescript": "^4.3.2"
"typescript": "^4.3.2",
"prettier": "^2.3.1",
"eslint": "^7.28.0"
},
"dependencies": {
"eslint": "^7.28.0",
"latinize": "^0.5.0",
"prettier": "^2.3.1"
"@formatjs/intl-getcanonicallocales": "^1.7.0"
},

@@ -53,0 +54,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc