@generaltranslation/supported-locales 1.1.4 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var e=require("generaltranslation"),r={af:["af"],am:["am"],ar:["ar-AE","ar-EG","ar-LB","ar-MA","ar-SA"],bg:["bg"],bn:["bn-BD","bn-IN"],bs:["bs"],ca:["ca"],cs:["cs"],cy:["cy"],da:["da"],de:["de","de-AT","de-CH"],el:["el","el-CY"],en:["en-AU","en-CA","en-GB","en-NZ","en-US"],es:["es","es-419","es-AR","es-CL","es-CO","es-MX","es-PE","es-US","es-VE"],et:["et"],fa:["fa"],fi:["fi"],fil:["fil"],fr:["fr","fr-BE","fr-CM","fr-CA","fr-CH","fr-SN"],gu:["gu"],hi:["hi"],he:["he"],hr:["hr"],hu:["hu"],hy:["hy"],id:["id"],is:["is"],it:["it-CH","it-IT"],ja:["ja"],ka:["ka"],kk:["kk"],kn:["kn"],ko:["ko"],la:["la"],lt:["lt"],lv:["lv"],mk:["mk"],ml:["ml"],mn:["mn"],mr:["mr"],ms:["ms"],my:["my"],nl:["nl","nl-BE"],no:["no"],pa:["pa"],pl:["pl"],pt:["pt-BR","pt-PT"],ro:["ro"],ru:["ru"],sk:["sk"],sl:["sl"],so:["so"],sq:["sq"],sr:["sr"],sv:["sv"],sw:["sw-KE","sw-TZ"],ta:["ta"],te:["te"],th:["th"],tl:["tl"],tr:["tr"],uk:["uk"],ur:["ur"],vi:["vi"],zh:["zh","zh-HK","zh-SG","zh-TW"]};exports.getSupportedLocale=function(a){if(!e.isValidLocale(a))return null;a=e.standardizeLocale(a);var s=e.getLocaleProperties(a),t=s.languageCode,n=s.minimizedCode,i=s.maximizedCode,l=s.regionCode,u=s.scriptCode;if(r[t]){var o=r[t];if(o.includes(a))return a;if(o.includes(n))return n;if(o.includes(t))return t;if(i.split("-").length>2){var c="".concat(t,"-").concat(l);if(o.includes(c))return c;var f="".concat(t,"-").concat(u);if(o.includes(f))return f}}return null},exports.listSupportedLocales=function(){for(var e=[],a=0,s=Object.values(r);a<s.length;a++){var t=s[a];e.push.apply(e,t)}return e.sort()};
|
|
2
2
|
//# sourceMappingURL=index.cjs.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.min.cjs","sources":["../src/index.ts"],"sourcesContent":["\nimport supportedLocales from \"./supportedLocales\";\nimport { getLocaleProperties, isValidLocale, standardizeLocale } from \"generaltranslation\";\n\n/**\n * @function getSupportedLocale\n * @description\n * Takes an arbitrary locale string, validates and standardizes it, and then attempts to map it \n * to a supported locale code based on a predefined list of locales. If the exact locale is supported, \n * it returns that locale directly. Otherwise, it attempts to find a compatible fallback by:\n * 1. Checking if the language portion is supported.\n * 2. Checking if a minimized form (e.g. \"en\" for \"en-US\") is supported.\n * If no supported match is found, it returns null.\n * \n * @param {string} locale - The locale string to check (e.g., \"en-Latn-US\").\n * @returns {string | null} A valid supported locale code if matched, otherwise null.\n */\nexport function getSupportedLocale(locale: string): string | null {\n \n // Validate and standardize\n if (!isValidLocale(locale)) return null;\n locale = standardizeLocale(locale);\n\n // Check if
|
|
1
|
+
{"version":3,"file":"index.cjs.min.cjs","sources":["../src/supportedLocales.ts","../src/index.ts"],"sourcesContent":["const supportedLocales = {\n \"af\": [\"af\"], // Afrikaans\n \"am\": [\"am\"], // Amharic\n \"ar\": [ // Arabic\n \"ar-AE\", // United Arab Emirates\n \"ar-EG\", // Egypt\n \"ar-LB\", // Lebanon\n \"ar-MA\", // Morocco\n \"ar-SA\" // Saudi Arabia\n ],\n \"bg\": [\"bg\"], // Bulgarian\n \"bn\": [ // Bengali\n \"bn-BD\", // Bangladesh\n \"bn-IN\" // India\n ],\n \"bs\": [\"bs\"], // Bosnian\n \"ca\": [\"ca\"], // Catalan\n \"cs\": [\"cs\"], // Czech\n \"cy\": [\"cy\"], // Welsh\n \"da\": [\"da\"], // Danish\n \"de\": [ // German\n \"de\",\n \"de-AT\", // Austria\n \"de-CH\", // Switzerland\n ],\n \"el\": [ // Greek\n \"el\",\n \"el-CY\", // Cyprus\n ],\n \"en\": [ // English\n \"en-AU\", // Australia\n \"en-CA\", // Canada\n \"en-GB\", // United Kingdom\n \"en-NZ\", // New Zealand\n \"en-US\", // United States\n ],\n \"es\": [ // Spanish\n \"es\", // Spain\n \"es-419\", // Latin America\n \"es-AR\", // Argentina\n \"es-CL\", // Chile\n \"es-CO\", // Colombia\n \"es-MX\", // Mexico\n \"es-PE\", // Peru\n \"es-US\", // United States\n \"es-VE\", // Venezuela\n ],\n \"et\": [\"et\"], // Estonian\n \"fa\": [\"fa\"], // Persian\n \"fi\": [\"fi\"], // Finnish\n \"fil\": [\"fil\"], // Filipino\n \"fr\": [ // French\n \"fr\", // France\n \"fr-BE\", // Belgium\n \"fr-CM\", // Cameroon\n \"fr-CA\", // Canada\n \"fr-CH\", // Switzerland\n \"fr-SN\", // Senegal\n ],\n \"gu\": [\"gu\"], // Gujarati\n \"hi\": [\"hi\"], // Hindi\n \"he\": [\"he\"], // Hebrew\n \"hr\": [\"hr\"], // Croatian\n \"hu\": [\"hu\"], // Hungarian\n \"hy\": [\"hy\"], // Armenian\n \"id\": [\"id\"], // Indonesian\n \"is\": [\"is\"], // Icelandic\n \"it\": [ // Italian\n \"it-CH\", // Switzerland\n \"it-IT\", // Italy\n ],\n \"ja\": [\"ja\"], // Japanese\n \"ka\": [\"ka\"], // Georgian\n \"kk\": [\"kk\"], // Kazakh\n \"kn\": [\"kn\"], // Kannada\n \"ko\": [\"ko\"], // Korean\n \"la\": [\"la\"], // Latin\n \"lt\": [\"lt\"], // Lithuanian\n \"lv\": [\"lv\"], // Latvian\n \"mk\": [\"mk\"], // Macedonian\n \"ml\": [\"ml\"], // Malayalam\n \"mn\": [\"mn\"], // Mongolian\n \"mr\": [\"mr\"], // Marathi\n \"ms\": [\"ms\"], // Malay\n \"my\": [\"my\"], // Burmese\n \"nl\": [ // Dutch\n \"nl\", // Netherlands\n \"nl-BE\", // Belgium\n ],\n \"no\": [\"no\"], // Norwegian\n \"pa\": [\"pa\"], // Punjabi\n \"pl\": [\"pl\"], // Polish\n \"pt\": [ // Portuguese\n \"pt-BR\", // Brazil\n \"pt-PT\", // Portugal\n ],\n \"ro\": [\"ro\"], // Romanian\n \"ru\": [\"ru\"], // Russian\n \"sk\": [\"sk\"], // Slovak\n \"sl\": [\"sl\"], // Slovenian\n \"so\": [\"so\"], // Somali\n \"sq\": [\"sq\"], // Albanian\n \"sr\": [\"sr\"], // Serbian\n \"sv\": [\"sv\"], // Swedish\n \"sw\": [ // Swahili\n \"sw-KE\", // Kenya\n \"sw-TZ\", // Tanzania\n ],\n \"ta\": [\"ta\"], // Tamil\n \"te\": [\"te\"], // Telugu\n \"th\": [\"th\"], // Thai\n \"tl\": [\"tl\"], // Tagalog\n \"tr\": [\"tr\"], // Turkish\n \"uk\": [\"uk\"], // Ukrainian\n \"ur\": [\"ur\"], // Urdu\n \"vi\": [\"vi\"], // Vietnamese\n \"zh\": [ // Chinese\n \"zh\", // China\n \"zh-HK\", // Hong Kong\n \"zh-SG\", // Singapore\n \"zh-TW\", // Taiwan\n ]\n} as {\n [language: string]: string[]\n};\n\nexport default supportedLocales;","\nimport supportedLocales from \"./supportedLocales\";\nimport { getLocaleProperties, isValidLocale, standardizeLocale } from \"generaltranslation\";\n\n/**\n * @function getSupportedLocale\n * @description\n * Takes an arbitrary locale string, validates and standardizes it, and then attempts to map it \n * to a supported locale code based on a predefined list of locales. If the exact locale is supported, \n * it returns that locale directly. Otherwise, it attempts to find a compatible fallback by:\n * 1. Checking if the language portion is supported.\n * 2. Checking if a minimized form (e.g. \"en\" for \"en-US\") is supported.\n * If no supported match is found, it returns null.\n * \n * @param {string} locale - The locale string to check (e.g., \"en-Latn-US\").\n * @returns {string | null} A valid supported locale code if matched, otherwise null.\n */\nexport function getSupportedLocale(locale: string): string | null {\n \n // Validate and standardize\n if (!isValidLocale(locale)) return null;\n locale = standardizeLocale(locale);\n\n // Check if there's support for the general language code\n const { \n languageCode, \n minimizedCode, maximizedCode,\n regionCode, scriptCode\n } = getLocaleProperties(locale);\n if (supportedLocales[languageCode]) {\n const exactSupportedLocales = supportedLocales[languageCode];\n\n // If the full locale is supported under this language category\n if (exactSupportedLocales.includes(locale)) return locale;\n\n // If a minimized variant of this locale is supported\n if (exactSupportedLocales.includes(minimizedCode)) return minimizedCode;\n\n // If only the language code is supported\n if (exactSupportedLocales.includes(languageCode)) return languageCode;\n\n // Attempt to match parts\n const parts = maximizedCode.split('-');\n if (parts.length > 2) {\n const languageWithRegion = `${languageCode}-${regionCode}`;\n if (exactSupportedLocales.includes(languageWithRegion)) return languageWithRegion;\n const languageWithScript = `${languageCode}-${scriptCode}`;\n if (exactSupportedLocales.includes(languageWithScript)) return languageWithScript;\n }\n }\n\n // No match found; return null\n return null;\n}\n\n/**\n * Generates a sorted list of supported locales.\n * @returns {string[]} A sorted array containing the supported base languages and their specific locales.\n */\nexport function listSupportedLocales(): string[] {\n const list: string[] = [];\n for (const localeList of Object.values(supportedLocales)) {\n list.push(...localeList); // Add each locale in the list\n }\n return list.sort();\n}"],"names":["supportedLocales","af","am","ar","bg","bn","bs","ca","cs","cy","da","de","el","en","es","et","fa","fi","fil","fr","gu","hi","he","hr","hu","hy","id","is","it","ja","ka","kk","kn","ko","la","lt","lv","mk","ml","mn","mr","ms","my","nl","no","pa","pl","pt","ro","ru","sk","sl","so","sq","sr","sv","sw","ta","te","th","tl","tr","uk","ur","vi","zh","locale","isValidLocale","standardizeLocale","_a","getLocaleProperties","languageCode","minimizedCode","maximizedCode","regionCode","scriptCode","exactSupportedLocales","includes","split","length","languageWithRegion","concat","languageWithScript","list","_i","Object","values","localeList","push","apply","sort"],"mappings":"iDAAMA,EAAmB,CACrBC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CACF,QACA,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AAC,MACPC,GAAM,CACF,KACA,QACA,QACA,qCCvGF,SAA6BC,GAG/B,IAAKC,EAAaA,cAACD,GAAS,OAAO,KACnCA,EAASE,EAAiBA,kBAACF,GAGrB,IAAAG,EAIFC,EAAmBA,oBAACJ,GAHpBK,iBACAC,kBAAeC,kBACfC,eAAYC,eAEhB,GAAI3E,EAAiBuE,GAAe,CAChC,IAAMK,EAAwB5E,EAAiBuE,GAG/C,GAAIK,EAAsBC,SAASX,GAAS,OAAOA,EAGnD,GAAIU,EAAsBC,SAASL,GAAgB,OAAOA,EAG1D,GAAII,EAAsBC,SAASN,GAAe,OAAOA,EAIzD,GADcE,EAAcK,MAAM,KACxBC,OAAS,EAAG,CAClB,IAAMC,EAAqB,GAAAC,OAAGV,EAAgB,KAAAU,OAAAP,GAC9C,GAAIE,EAAsBC,SAASG,GAAqB,OAAOA,EAC/D,IAAME,EAAqB,GAAAD,OAAGV,EAAgB,KAAAU,OAAAN,GAC9C,GAAIC,EAAsBC,SAASK,GAAqB,OAAOA,GAKvE,OAAO,IACX,0CAQI,IADA,IAAMC,EAAiB,GACiCC,EAAA,EAA/Bf,EAAAgB,OAAOC,OAAOtF,GAAdoF,EAAAf,EAAAU,OAAAK,IAAiC,CAArD,IAAMG,EAAUlB,EAAAe,GACjBD,EAAKK,KAALC,MAAAN,EAAaI,GAEjB,OAAOJ,EAAKO,MAChB"}
|
package/dist/index.esm.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{isValidLocale as r,standardizeLocale as e,getLocaleProperties as n}from"generaltranslation";var a={af:["af"],am:["am"],ar:["ar-AE","ar-EG","ar-LB","ar-MA","ar-SA"],bg:["bg"],bn:["bn-BD","bn-IN"],bs:["bs"],ca:["ca"],cs:["cs"],cy:["cy"],da:["da"],de:["de","de-AT","de-CH"],el:["el","el-CY"],en:["en-AU","en-CA","en-GB","en-NZ","en-US"],es:["es","es-419","es-AR","es-CL","es-CO","es-MX","es-PE","es-US","es-VE"],et:["et"],fa:["fa"],fi:["fi"],fil:["fil"],fr:["fr","fr-BE","fr-CM","fr-CA","fr-CH","fr-SN"],gu:["gu"],hi:["hi"],he:["he"],hr:["hr"],hu:["hu"],hy:["hy"],id:["id"],is:["is"],it:["it-CH","it-IT"],ja:["ja"],ka:["ka"],kk:["kk"],kn:["kn"],ko:["ko"],la:["la"],lt:["lt"],lv:["lv"],mk:["mk"],ml:["ml"],mn:["mn"],mr:["mr"],ms:["ms"],my:["my"],nl:["nl","nl-BE"],no:["no"],pa:["pa"],pl:["pl"],pt:["pt-BR","pt-PT"],ro:["ro"],ru:["ru"],sk:["sk"],sl:["sl"],so:["so"],sq:["sq"],sr:["sr"],sv:["sv"],sw:["sw-KE","sw-TZ"],ta:["ta"],te:["te"],th:["th"],tl:["tl"],tr:["tr"],uk:["uk"],ur:["ur"],vi:["vi"],zh:["zh","zh-HK","zh-SG","zh-TW"]};function s(s){if(!r(s))return null;s=e(s);var t=n(s),i=t.languageCode,l=t.minimizedCode,u=t.maximizedCode,f=t.regionCode,o=t.scriptCode;if(a[i]){var c=a[i];if(c.includes(s))return s;if(c.includes(l))return l;if(c.includes(i))return i;if(u.split("-").length>2){var d="".concat(i,"-").concat(f);if(c.includes(d))return d;var h="".concat(i,"-").concat(o);if(c.includes(h))return h}}return null}function t(){for(var r=[],e=0,n=Object.values(a);e<n.length;e++){var s=n[e];r.push.apply(r,s)}return r.sort()}export{s as getSupportedLocale,t as listSupportedLocales};
|
|
2
2
|
//# sourceMappingURL=index.esm.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.min.mjs","sources":["../src/index.ts"],"sourcesContent":["\nimport supportedLocales from \"./supportedLocales\";\nimport { getLocaleProperties, isValidLocale, standardizeLocale } from \"generaltranslation\";\n\n/**\n * @function getSupportedLocale\n * @description\n * Takes an arbitrary locale string, validates and standardizes it, and then attempts to map it \n * to a supported locale code based on a predefined list of locales. If the exact locale is supported, \n * it returns that locale directly. Otherwise, it attempts to find a compatible fallback by:\n * 1. Checking if the language portion is supported.\n * 2. Checking if a minimized form (e.g. \"en\" for \"en-US\") is supported.\n * If no supported match is found, it returns null.\n * \n * @param {string} locale - The locale string to check (e.g., \"en-Latn-US\").\n * @returns {string | null} A valid supported locale code if matched, otherwise null.\n */\nexport function getSupportedLocale(locale: string): string | null {\n \n // Validate and standardize\n if (!isValidLocale(locale)) return null;\n locale = standardizeLocale(locale);\n\n // Check if
|
|
1
|
+
{"version":3,"file":"index.esm.min.mjs","sources":["../src/supportedLocales.ts","../src/index.ts"],"sourcesContent":["const supportedLocales = {\n \"af\": [\"af\"], // Afrikaans\n \"am\": [\"am\"], // Amharic\n \"ar\": [ // Arabic\n \"ar-AE\", // United Arab Emirates\n \"ar-EG\", // Egypt\n \"ar-LB\", // Lebanon\n \"ar-MA\", // Morocco\n \"ar-SA\" // Saudi Arabia\n ],\n \"bg\": [\"bg\"], // Bulgarian\n \"bn\": [ // Bengali\n \"bn-BD\", // Bangladesh\n \"bn-IN\" // India\n ],\n \"bs\": [\"bs\"], // Bosnian\n \"ca\": [\"ca\"], // Catalan\n \"cs\": [\"cs\"], // Czech\n \"cy\": [\"cy\"], // Welsh\n \"da\": [\"da\"], // Danish\n \"de\": [ // German\n \"de\",\n \"de-AT\", // Austria\n \"de-CH\", // Switzerland\n ],\n \"el\": [ // Greek\n \"el\",\n \"el-CY\", // Cyprus\n ],\n \"en\": [ // English\n \"en-AU\", // Australia\n \"en-CA\", // Canada\n \"en-GB\", // United Kingdom\n \"en-NZ\", // New Zealand\n \"en-US\", // United States\n ],\n \"es\": [ // Spanish\n \"es\", // Spain\n \"es-419\", // Latin America\n \"es-AR\", // Argentina\n \"es-CL\", // Chile\n \"es-CO\", // Colombia\n \"es-MX\", // Mexico\n \"es-PE\", // Peru\n \"es-US\", // United States\n \"es-VE\", // Venezuela\n ],\n \"et\": [\"et\"], // Estonian\n \"fa\": [\"fa\"], // Persian\n \"fi\": [\"fi\"], // Finnish\n \"fil\": [\"fil\"], // Filipino\n \"fr\": [ // French\n \"fr\", // France\n \"fr-BE\", // Belgium\n \"fr-CM\", // Cameroon\n \"fr-CA\", // Canada\n \"fr-CH\", // Switzerland\n \"fr-SN\", // Senegal\n ],\n \"gu\": [\"gu\"], // Gujarati\n \"hi\": [\"hi\"], // Hindi\n \"he\": [\"he\"], // Hebrew\n \"hr\": [\"hr\"], // Croatian\n \"hu\": [\"hu\"], // Hungarian\n \"hy\": [\"hy\"], // Armenian\n \"id\": [\"id\"], // Indonesian\n \"is\": [\"is\"], // Icelandic\n \"it\": [ // Italian\n \"it-CH\", // Switzerland\n \"it-IT\", // Italy\n ],\n \"ja\": [\"ja\"], // Japanese\n \"ka\": [\"ka\"], // Georgian\n \"kk\": [\"kk\"], // Kazakh\n \"kn\": [\"kn\"], // Kannada\n \"ko\": [\"ko\"], // Korean\n \"la\": [\"la\"], // Latin\n \"lt\": [\"lt\"], // Lithuanian\n \"lv\": [\"lv\"], // Latvian\n \"mk\": [\"mk\"], // Macedonian\n \"ml\": [\"ml\"], // Malayalam\n \"mn\": [\"mn\"], // Mongolian\n \"mr\": [\"mr\"], // Marathi\n \"ms\": [\"ms\"], // Malay\n \"my\": [\"my\"], // Burmese\n \"nl\": [ // Dutch\n \"nl\", // Netherlands\n \"nl-BE\", // Belgium\n ],\n \"no\": [\"no\"], // Norwegian\n \"pa\": [\"pa\"], // Punjabi\n \"pl\": [\"pl\"], // Polish\n \"pt\": [ // Portuguese\n \"pt-BR\", // Brazil\n \"pt-PT\", // Portugal\n ],\n \"ro\": [\"ro\"], // Romanian\n \"ru\": [\"ru\"], // Russian\n \"sk\": [\"sk\"], // Slovak\n \"sl\": [\"sl\"], // Slovenian\n \"so\": [\"so\"], // Somali\n \"sq\": [\"sq\"], // Albanian\n \"sr\": [\"sr\"], // Serbian\n \"sv\": [\"sv\"], // Swedish\n \"sw\": [ // Swahili\n \"sw-KE\", // Kenya\n \"sw-TZ\", // Tanzania\n ],\n \"ta\": [\"ta\"], // Tamil\n \"te\": [\"te\"], // Telugu\n \"th\": [\"th\"], // Thai\n \"tl\": [\"tl\"], // Tagalog\n \"tr\": [\"tr\"], // Turkish\n \"uk\": [\"uk\"], // Ukrainian\n \"ur\": [\"ur\"], // Urdu\n \"vi\": [\"vi\"], // Vietnamese\n \"zh\": [ // Chinese\n \"zh\", // China\n \"zh-HK\", // Hong Kong\n \"zh-SG\", // Singapore\n \"zh-TW\", // Taiwan\n ]\n} as {\n [language: string]: string[]\n};\n\nexport default supportedLocales;","\nimport supportedLocales from \"./supportedLocales\";\nimport { getLocaleProperties, isValidLocale, standardizeLocale } from \"generaltranslation\";\n\n/**\n * @function getSupportedLocale\n * @description\n * Takes an arbitrary locale string, validates and standardizes it, and then attempts to map it \n * to a supported locale code based on a predefined list of locales. If the exact locale is supported, \n * it returns that locale directly. Otherwise, it attempts to find a compatible fallback by:\n * 1. Checking if the language portion is supported.\n * 2. Checking if a minimized form (e.g. \"en\" for \"en-US\") is supported.\n * If no supported match is found, it returns null.\n * \n * @param {string} locale - The locale string to check (e.g., \"en-Latn-US\").\n * @returns {string | null} A valid supported locale code if matched, otherwise null.\n */\nexport function getSupportedLocale(locale: string): string | null {\n \n // Validate and standardize\n if (!isValidLocale(locale)) return null;\n locale = standardizeLocale(locale);\n\n // Check if there's support for the general language code\n const { \n languageCode, \n minimizedCode, maximizedCode,\n regionCode, scriptCode\n } = getLocaleProperties(locale);\n if (supportedLocales[languageCode]) {\n const exactSupportedLocales = supportedLocales[languageCode];\n\n // If the full locale is supported under this language category\n if (exactSupportedLocales.includes(locale)) return locale;\n\n // If a minimized variant of this locale is supported\n if (exactSupportedLocales.includes(minimizedCode)) return minimizedCode;\n\n // If only the language code is supported\n if (exactSupportedLocales.includes(languageCode)) return languageCode;\n\n // Attempt to match parts\n const parts = maximizedCode.split('-');\n if (parts.length > 2) {\n const languageWithRegion = `${languageCode}-${regionCode}`;\n if (exactSupportedLocales.includes(languageWithRegion)) return languageWithRegion;\n const languageWithScript = `${languageCode}-${scriptCode}`;\n if (exactSupportedLocales.includes(languageWithScript)) return languageWithScript;\n }\n }\n\n // No match found; return null\n return null;\n}\n\n/**\n * Generates a sorted list of supported locales.\n * @returns {string[]} A sorted array containing the supported base languages and their specific locales.\n */\nexport function listSupportedLocales(): string[] {\n const list: string[] = [];\n for (const localeList of Object.values(supportedLocales)) {\n list.push(...localeList); // Add each locale in the list\n }\n return list.sort();\n}"],"names":["supportedLocales","af","am","ar","bg","bn","bs","ca","cs","cy","da","de","el","en","es","et","fa","fi","fil","fr","gu","hi","he","hr","hu","hy","id","is","it","ja","ka","kk","kn","ko","la","lt","lv","mk","ml","mn","mr","ms","my","nl","no","pa","pl","pt","ro","ru","sk","sl","so","sq","sr","sv","sw","ta","te","th","tl","tr","uk","ur","vi","zh","getSupportedLocale","locale","isValidLocale","standardizeLocale","_a","getLocaleProperties","languageCode","minimizedCode","maximizedCode","regionCode","scriptCode","exactSupportedLocales","includes","split","length","languageWithRegion","concat","languageWithScript","listSupportedLocales","list","_i","Object","values","localeList","push","apply","sort"],"mappings":"mGAAA,IAAMA,EAAmB,CACrBC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CACF,QACA,QACA,QACA,QACA,SAEJC,GAAM,CAAC,MACPC,GAAM,CACF,QACA,SAEJC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CACF,KACA,QACA,SAEJC,GAAM,CACF,KACA,SAEJC,GAAM,CACF,QACA,QACA,QACA,QACA,SAEJC,GAAM,CACF,KACA,SACA,QACA,QACA,QACA,QACA,QACA,QACA,SAEJC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,IAAO,CAAC,OACRC,GAAM,CACF,KACA,QACA,QACA,QACA,QACA,SAEJC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CAAC,MACPC,GAAM,CAAC,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AC9C,GAAIE,EAAsBC,SAASG,GAAqB,OAAOA,EAC/D,IAAME,EAAqB,GAAAD,OAAGV,EAAgB,KAAAU,OAAAN,GAC9C,GAAIC,EAAsBC,SAASK,GAAqB,OAAOA,GAKvE,OAAO,IACX,UAMgBC,IAEZ,IADA,IAAMC,EAAiB,GACiCC,EAAA,EAA/BhB,EAAAiB,OAAOC,OAAOxF,GAAdsF,EAAAhB,EAAAU,OAAAM,IAAiC,CAArD,IAAMG,EAAUnB,EAAAgB,GACjBD,EAAKK,KAALC,MAAAN,EAAaI,GAEjB,OAAOJ,EAAKO,MAChB"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generaltranslation/supported-locales",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "List of supported locales for General Translation",
|
|
5
|
-
"main": "dist/index.cjs.min.cjs",
|
|
6
|
-
"module": "dist/index.esm.min.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "./dist/index.cjs.min.cjs",
|
|
6
|
+
"module": "./dist/index.esm.min.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"clean
|
|
12
|
+
"build:clean": "rm -rf dist; npm run build",
|
|
13
13
|
"build": "rollup -c",
|
|
14
|
-
"
|
|
14
|
+
"release": "npm run build:clean && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -25,19 +25,20 @@
|
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/General-Translation/gt-libraries/issues"
|
|
27
27
|
},
|
|
28
|
-
"homepage": "https://
|
|
28
|
+
"homepage": "https://www.generaltranslation.com/",
|
|
29
29
|
"typescript": {
|
|
30
|
-
"definition": "dist/index.d.ts"
|
|
30
|
+
"definition": "./dist/index.d.ts"
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"require": "./dist/index.cjs.min.cjs",
|
|
36
|
-
"import": "./dist/index.esm.min.mjs"
|
|
36
|
+
"import": "./dist/index.esm.min.mjs",
|
|
37
|
+
"default": "./dist/index.esm.min.mjs"
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"generaltranslation": "^6.1.
|
|
41
|
+
"generaltranslation": "^6.1.7"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@rollup/plugin-commonjs": "^28.0.1",
|