Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 63492a0

Browse files
feat($locale): Include original locale ID in $locale
Most systems use *IETF language tag* codes which are typically a combination of the ISO 639 language code and ISO 3166-1 country code with an underscore or hyphen delimiter. For example `en_US`, `en_AU`, etc. Whilst the `$locale.id` comes close, the lowercase format makes it impossible to transform to an IETF tag reliably. For example, it would be impossible to deduce `en_Dsrt_US` from `en-dsrt-us`. Closes #13390
1 parent adb0e17 commit 63492a0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

i18n/spec/closureI18nExtractorSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ findLocaleId = closureI18nExtractor.findLocaleId;
44
extractNumberSymbols = closureI18nExtractor.extractNumberSymbols;
55
extractCurrencySymbols = closureI18nExtractor.extractCurrencySymbols;
66
extractDateTimeSymbols = closureI18nExtractor.extractDateTimeSymbols;
7+
outputLocale = closureI18nExtractor.outputLocale;
78

89

910
function newTestLocaleInfo() {
@@ -272,3 +273,10 @@ describe("serializeContent", function() {
272273
});
273274
});
274275

276+
describe("outputLocale", function() {
277+
it("should render the correct locale ids", function() {
278+
var output = outputLocale(newTestLocaleInfo(), 'fr_CA');
279+
expect(output).toContain('"id": "fr-ca"');
280+
expect(output).toContain('"localeID": "fr_CA"');
281+
});
282+
});

i18n/src/closureI18nExtractor.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function outputLocale(localeInfo, localeID) {
161161
if (!localeObj.DATETIME_FORMATS) {
162162
localeObj.DATETIME_FORMATS = fallBackObj.DATETIME_FORMATS;
163163
}
164+
localeObj.localeID = localeID;
164165
localeObj.id = correctedLocaleId(localeID);
165166

166167
var getDecimals = [
@@ -201,10 +202,11 @@ function outputLocale(localeInfo, localeID) {
201202
DATETIME_FORMATS: localeObj.DATETIME_FORMATS,
202203
NUMBER_FORMATS: localeObj.NUMBER_FORMATS,
203204
pluralCat: localeObj.pluralCat,
204-
id: localeObj.id
205+
id: localeObj.id,
206+
localeID: localeID
205207
};
206208

207-
var content = serializeContent(localeInfo[localeID]);
209+
var content = serializeContent(localeObj);
208210
if (content.indexOf('getVF(') < 0) {
209211
getVF = '';
210212
}

0 commit comments

Comments
 (0)