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

Commit 96a3147

Browse files
committed
fix(ngLocale): fix i18n code-generation to support get_vf_, decimals_, and get_wt_
The updated Closure I18N code relies on these methods to enhance the localization quality. This fix prevents ngLocale files from referencing undefined values. In the short term, this means adding references to versions of these methods in locales where they are necessary.
1 parent 6aa31e1 commit 96a3147

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

i18n/src/closureI18nExtractor.js

+58-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ function pluralExtractor(content, localeInfo) {
8787
continue;
8888
}
8989
var temp = goog.i18n.pluralRules.select.toString().
90-
replace(/goog.i18n.pluralRules.Keyword/g, 'PLURAL_CATEGORY').replace(/\n/g, '');
90+
replace(/goog\.i18n\.pluralRules\.Keyword/g, 'PLURAL_CATEGORY').
91+
replace(/goog\.i18n\.pluralRules\.get_vf_/g, 'getVF').
92+
replace(/goog\.i18n\.pluralRules\.get_wt_/g, 'getWT').
93+
replace(/goog\.i18n\.pluralRules\.decimals_/g, 'getDecimals').
94+
replace(/\n/g, '');
9195

9296
///@@ is a crazy place holder to be replaced before writing to file
9397
localeInfo[localeIds[i]].pluralCat = "@@" + temp + "@@";
@@ -158,15 +162,39 @@ function outputLocale(localeInfo, localeID) {
158162
}
159163
localeObj.id = correctedLocaleId(localeID);
160164

161-
var prefix =
162-
"'use strict';\n" +
163-
'angular.module("ngLocale", [], ["$provide", function($provide) {\n' +
164-
'var PLURAL_CATEGORY = {' +
165-
'ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"' +
166-
'};\n' +
167-
'$provide.value("$locale", ';
168-
169-
var suffix = ');\n}]);';
165+
var getDecimals = [
166+
'function getDecimals(n) {',
167+
' n = n + \'\';',
168+
' var i = n.indexOf(\'.\');',
169+
' return (i == -1) ? 0 : n.length - i - 1;',
170+
'}', '', ''
171+
].join('\n');
172+
173+
var getVF = [
174+
'function getVF(n, opt_precision) {',
175+
' var v = opt_precision;', '',
176+
' if (undefined === v) {',
177+
' v = Math.min(getDecimals(n), 3);',
178+
' }', '',
179+
' var base = Math.pow(10, v);',
180+
' var f = ((n * base) | 0) % base;',
181+
' return {v: v, f: f};',
182+
'}', '', ''
183+
].join('\n');
184+
185+
var getWT =
186+
[
187+
'function getWT(v, f) {',
188+
' if (f === 0) {',
189+
' return {w: 0, t: 0};',
190+
' }', '',
191+
' while ((f % 10) === 0) {',
192+
' f /= 10;',
193+
' v--;',
194+
' }', '',
195+
' return {w: v, t: f};',
196+
'}', '', ''
197+
].join('\n');
170198

171199
localeObj = {
172200
DATETIME_FORMATS: localeObj.DATETIME_FORMATS,
@@ -176,6 +204,26 @@ function outputLocale(localeInfo, localeID) {
176204
};
177205

178206
var content = serializeContent(localeInfo[localeID]);
207+
if (content.indexOf('getVF(') < 0) {
208+
getVF = '';
209+
}
210+
if (content.indexOf('getWT(') < 0) {
211+
getWT = '';
212+
}
213+
if (!getVF && content.indexOf('getDecimals(') < 0) {
214+
getDecimals = '';
215+
}
216+
217+
var prefix =
218+
"'use strict';\n" +
219+
'angular.module("ngLocale", [], ["$provide", function($provide) {\n' +
220+
'var PLURAL_CATEGORY = {' +
221+
'ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"' +
222+
'};\n' +
223+
getDecimals + getVF + getWT +
224+
'$provide.value("$locale", ';
225+
226+
var suffix = ');\n}]);';
179227

180228
return prefix + content + suffix;
181229
}

0 commit comments

Comments
 (0)