UNPKG

@raona/sp

Version:

Raona utilities to work with Sharepoint using pnp/sp

229 lines (228 loc) 5.91 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); // TODO: investigate if this causes performance issues and is better to instanciate it inside getTermsByLanguageLCID var i18nLanguageCodeToLcid = { 'af': 1078, 'sq': 1052, 'am': 1118, 'ar-dz': 5121, 'ar-bh': 15361, 'ar-eg': 3073, 'ar-iq': 2049, 'ar-jo': 11265, 'ar-kw': 13313, 'ar-lb': 12289, 'ar-ly': 4097, 'ar-ma': 6145, 'ar-om': 8193, 'ar-qa': 16385, 'ar-sa': 1025, 'ar-sy': 10241, 'ar-tn': 7169, 'ar-ae': 14337, 'ar-ye': 9217, 'hy': 1067, 'as': 1101, 'az-az': 2092, // 'az-az': 1068, 'eu': 1069, 'be': 1059, 'bn': 2117, // 'bn': 1093, 'bs': 5146, 'bg': 1026, 'my': 1109, 'ca': 1027, 'zh-cn': 2052, 'zh-hk': 3076, 'zh-mo': 5124, 'zh-sg': 4100, 'zh-tw': 1028, 'hr': 1050, 'cs': 1029, 'da': 1030, 'nl-be': 2067, 'nl-nl': 1043, 'en-au': 3081, 'en-bz': 10249, 'en-ca': 4105, 'en-cb': 9225, 'en-gb': 2057, 'en-in': 16393, 'en-ie': 6153, 'en-jm': 8201, 'en-nz': 5129, 'en-ph': 13321, 'en-za': 7177, 'en-tt': 11273, 'en-us': 1033, 'et': 1061, 'mk': 1071, 'fo': 1080, 'fa': 1065, 'fi': 1035, 'fr-be': 2060, 'fr-ca': 3084, 'fr-fr': 1036, 'fr-lu': 5132, 'fr-ch': 4108, 'gd-ie': 2108, 'gd': 1084, 'de-at': 3079, 'de-de': 1031, 'de-li': 5127, 'de-lu': 4103, 'de-ch': 2055, 'el': 1032, 'gn': 1140, 'gu': 1095, 'he': 1037, 'hi': 1081, 'hu': 1038, 'is': 1039, 'id': 1057, 'it-it': 1040, 'it-ch': 2064, 'ja': 1041, 'kn': 1099, 'ks': 1120, 'kk': 1087, 'km': 1107, 'ko': 1042, 'lo': 1108, 'la': 1142, 'lv': 1062, 'lt': 1063, 'ms-bn': 2110, 'ms-my': 1086, 'ml': 1100, 'mt': 1082, 'mi': 1153, 'mr': 1102, 'mn': 2128, // 'mn': 1104, 'ne': 1121, // 'no-no': 1044, 'no-no': 2068, 'or': 1096, 'pl': 1045, 'pt-br': 1046, 'pt-pt': 2070, 'pa': 1094, 'rm': 1047, 'ro-mo': 2072, 'ro': 1048, 'ru': 1049, 'ru-mo': 2073, 'sa': 1103, 'sr-sp': 3098, // 'sr-sp': 2074, 'tn': 1074, 'sd': 1113, 'sk': 1051, 'sl': 1060, 'so': 1143, 'sb': 1070, 'es-ar': 11274, 'es-bo': 16394, 'es-cl': 13322, 'es-co': 9226, 'es-cr': 5130, 'es-do': 7178, 'es-ec': 12298, 'es-sv': 17418, 'es-gt': 4106, 'es-hn': 18442, 'es-mx': 2058, 'es-ni': 19466, 'es-pa': 6154, 'es-py': 15370, 'es-pe': 10250, 'es-pr': 20490, 'es-es': 3082, 'es-uy': 14346, 'es-ve': 8202, 'sw': 1089, 'sv-fi': 2077, 'sv-se': 1053, 'tg': 1064, 'ta': 1097, 'tt': 1092, 'te': 1098, 'th': 1054, 'bo': 1105, 'ts': 1073, 'tr': 1055, 'tk': 1090, 'uk': 1058, 'ur': 1056, 'uz-uz': 2115, // 'uz-uz': 1091, 'vi': 1066, 'cy': 1106, 'xh': 1076, 'yi': 1085, 'zu': 1077, }; var i18nTermCollection = /** @class */ (function () { function i18nTermCollection(terms) { this.terms = terms; } i18nTermCollection.prototype.getTermsByLanguageIsoCode = function (languageCode, inmutable, sortByTranslatedName) { if (sortByTranslatedName === void 0) { sortByTranslatedName = true; } var LCID = this.getLCID(languageCode); if (typeof LCID === 'undefined') return []; var terms = this.getTermsByLanguageLCID(LCID, inmutable); return sortByTranslatedName ? terms.sort(function (termA, termB) { if (inmutable) return termA.translatedLabel.localeCompare(termB.translatedLabel); else return termA.Name.localeCompare(termB.Name); }) : terms; }; i18nTermCollection.prototype.getTermByLanguageIsoCodeAndTermId = function (languageCode, termGuid, inmmutable) { var LCID = this.getLCID(languageCode); for (var i = 0; i < this.terms.length; i++) { var t = this.terms[i]; if (t.Id === termGuid) { return this.formatTerm(t, LCID, inmmutable); } } return null; }; i18nTermCollection.prototype.getTermsByLanguageLCID = function (languageLCID, inmmutable) { var _this = this; return this.terms.map(function (term) { return _this.formatTerm(term, languageLCID, inmmutable); }); }; i18nTermCollection.prototype.getLCID = function (languageCode) { return i18nLanguageCodeToLcid[languageCode.toLowerCase()]; }; i18nTermCollection.prototype.formatTerm = function (term, languageLCID, inmmutable) { var _a; var originalName = term.Name; var targetName = term.i18nLabels && term.i18nLabels[languageLCID]; var key = inmmutable ? 'translatedLabel' : 'Name'; return __assign({}, term, (_a = {}, _a[key] = targetName || originalName, _a)); }; i18nTermCollection.prototype.getRawi18nTerms = function () { return this.terms; }; return i18nTermCollection; }()); exports.i18nTermCollection = i18nTermCollection;