build(common): extract i18n locale data from cldr (#18284)
PR Close #18284
This commit is contained in:
committed by
Miško Hevery
parent
409688fe17
commit
33d250ffaa
@@ -5,6 +5,7 @@ bazel-*
|
||||
e2e_test.*
|
||||
node_modules
|
||||
bower_components
|
||||
tools/gulp-tasks/cldr/cldr-data/
|
||||
|
||||
# Include when developing application packages.
|
||||
pubspec.lock
|
||||
|
||||
@@ -42,3 +42,5 @@ gulp.task('serve', loadTask('serve', 'default'));
|
||||
gulp.task('serve-examples', loadTask('serve', 'examples'));
|
||||
gulp.task('changelog', loadTask('changelog'));
|
||||
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});
|
||||
gulp.task('cldr:extract', loadTask('cldr', 'extract'));
|
||||
gulp.task('cldr:download', loadTask('cldr', 'download'));
|
||||
|
||||
+2
-1
@@ -47,7 +47,8 @@ module.exports = function(config) {
|
||||
pattern: 'packages/platform-browser/test/browser/static_assets/**',
|
||||
included: false,
|
||||
watched: false,
|
||||
}
|
||||
},
|
||||
{pattern: 'packages/common/i18n/**', included: false, watched: false, served: true},
|
||||
],
|
||||
|
||||
exclude: [
|
||||
|
||||
@@ -1542,7 +1542,7 @@
|
||||
}
|
||||
},
|
||||
"cldr": {
|
||||
"version": "3.5.2",
|
||||
"version": "4.5.0",
|
||||
"dependencies": {
|
||||
"uglify-js": {
|
||||
"version": "1.3.3"
|
||||
@@ -1552,6 +1552,59 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"cldr-data-downloader": {
|
||||
"version": "0.3.2",
|
||||
"dependencies": {
|
||||
"adm-zip": {
|
||||
"version": "0.4.4"
|
||||
},
|
||||
"async": {
|
||||
"version": "2.5.0"
|
||||
},
|
||||
"bl": {
|
||||
"version": "1.1.2"
|
||||
},
|
||||
"form-data": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.4"
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.27.0"
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.15"
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8"
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.0"
|
||||
},
|
||||
"q": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.2.3"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6"
|
||||
},
|
||||
"request": {
|
||||
"version": "2.74.0"
|
||||
},
|
||||
"tough-cookie": {
|
||||
"version": "2.3.2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"cldrjs": {
|
||||
"version": "0.5.0"
|
||||
},
|
||||
"cli-boxes": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
@@ -1660,6 +1713,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"config-chain": {
|
||||
"version": "1.1.11"
|
||||
},
|
||||
"configstore": {
|
||||
"version": "2.1.0",
|
||||
"dependencies": {
|
||||
@@ -3717,13 +3773,10 @@
|
||||
"version": "0.3.0"
|
||||
},
|
||||
"memoizeasync": {
|
||||
"version": "0.8.0",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"lru-cache": {
|
||||
"version": "2.5.0"
|
||||
},
|
||||
"passerror": {
|
||||
"version": "0.0.2"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -3876,6 +3929,14 @@
|
||||
"normalize-path": {
|
||||
"version": "2.0.1"
|
||||
},
|
||||
"npmconf": {
|
||||
"version": "2.0.9",
|
||||
"dependencies": {
|
||||
"semver": {
|
||||
"version": "4.3.6"
|
||||
}
|
||||
}
|
||||
},
|
||||
"npmlog": {
|
||||
"version": "4.0.2"
|
||||
},
|
||||
@@ -4014,7 +4075,7 @@
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"passerror": {
|
||||
"version": "0.0.1"
|
||||
"version": "1.1.1"
|
||||
},
|
||||
"path-browserify": {
|
||||
"version": "0.0.0"
|
||||
@@ -4081,6 +4142,9 @@
|
||||
"process-nextick-args": {
|
||||
"version": "1.0.6"
|
||||
},
|
||||
"progress": {
|
||||
"version": "1.1.8"
|
||||
},
|
||||
"promise": {
|
||||
"version": "7.1.1"
|
||||
},
|
||||
@@ -4095,6 +4159,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"proto-list": {
|
||||
"version": "1.2.4"
|
||||
},
|
||||
"protobufjs": {
|
||||
"version": "5.0.0",
|
||||
"dependencies": {
|
||||
@@ -4342,6 +4409,9 @@
|
||||
"request-capture-har": {
|
||||
"version": "1.1.4"
|
||||
},
|
||||
"request-progress": {
|
||||
"version": "0.3.1"
|
||||
},
|
||||
"requires-port": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
@@ -4760,6 +4830,9 @@
|
||||
"text-extensions": {
|
||||
"version": "1.3.3"
|
||||
},
|
||||
"throttleit": {
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"through": {
|
||||
"version": "2.3.8"
|
||||
},
|
||||
@@ -4932,6 +5005,9 @@
|
||||
"uglify-to-browserify": {
|
||||
"version": "1.0.2"
|
||||
},
|
||||
"uid-number": {
|
||||
"version": "0.0.5"
|
||||
},
|
||||
"uid-safe": {
|
||||
"version": "2.0.0"
|
||||
},
|
||||
@@ -5271,13 +5347,13 @@
|
||||
"version": "8.2.2"
|
||||
},
|
||||
"xmldom": {
|
||||
"version": "0.1.19"
|
||||
"version": "0.1.27"
|
||||
},
|
||||
"xmlhttprequest-ssl": {
|
||||
"version": "1.5.1"
|
||||
},
|
||||
"xpath": {
|
||||
"version": "0.0.7"
|
||||
"version": "0.0.24"
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.1"
|
||||
|
||||
Generated
+144
-20
@@ -2408,9 +2408,9 @@
|
||||
}
|
||||
},
|
||||
"cldr": {
|
||||
"version": "3.5.2",
|
||||
"from": "cldr@>=3.5.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cldr/-/cldr-3.5.2.tgz",
|
||||
"version": "4.5.0",
|
||||
"from": "cldr@4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/cldr/-/cldr-4.5.0.tgz",
|
||||
"dependencies": {
|
||||
"uglify-js": {
|
||||
"version": "1.3.3",
|
||||
@@ -2424,6 +2424,93 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"cldr-data-downloader": {
|
||||
"version": "0.3.2",
|
||||
"from": "cldr-data-downloader@>=0.3.0 <0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/cldr-data-downloader/-/cldr-data-downloader-0.3.2.tgz",
|
||||
"dependencies": {
|
||||
"adm-zip": {
|
||||
"version": "0.4.4",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.4.tgz"
|
||||
},
|
||||
"async": {
|
||||
"version": "2.5.0",
|
||||
"from": "async@>=2.0.1 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.5.0.tgz"
|
||||
},
|
||||
"bl": {
|
||||
"version": "1.1.2",
|
||||
"from": "bl@>=1.1.2 <1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-1.1.2.tgz"
|
||||
},
|
||||
"form-data": {
|
||||
"version": "1.0.1",
|
||||
"from": "form-data@>=1.0.0-rc4 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.1.tgz"
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.4",
|
||||
"from": "lodash@>=4.14.0 <5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz"
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.27.0",
|
||||
"from": "mime-db@>=1.27.0 <1.28.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz"
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.15",
|
||||
"from": "mime-types@>=2.1.7 <2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz"
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz"
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.0",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz"
|
||||
},
|
||||
"q": {
|
||||
"version": "1.0.1",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/q/-/q-1.0.1.tgz"
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.2.3",
|
||||
"from": "qs@>=6.2.0 <6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.2.3.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
"from": "readable-stream@>=2.0.5 <2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz"
|
||||
},
|
||||
"request": {
|
||||
"version": "2.74.0",
|
||||
"from": "request@>=2.74.0 <2.75.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.74.0.tgz"
|
||||
},
|
||||
"tough-cookie": {
|
||||
"version": "2.3.2",
|
||||
"from": "tough-cookie@>=2.3.0 <2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"cldrjs": {
|
||||
"version": "0.5.0",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/cldrjs/-/cldrjs-0.5.0.tgz"
|
||||
},
|
||||
"cli-boxes": {
|
||||
"version": "1.0.0",
|
||||
"from": "cli-boxes@>=1.0.0 <2.0.0",
|
||||
@@ -2596,6 +2683,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"config-chain": {
|
||||
"version": "1.1.11",
|
||||
"from": "config-chain@>=1.1.8 <1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.11.tgz"
|
||||
},
|
||||
"configstore": {
|
||||
"version": "2.1.0",
|
||||
"from": "configstore@>=2.0.0 <3.0.0",
|
||||
@@ -5917,19 +6009,14 @@
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz"
|
||||
},
|
||||
"memoizeasync": {
|
||||
"version": "0.8.0",
|
||||
"from": "memoizeasync@0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/memoizeasync/-/memoizeasync-0.8.0.tgz",
|
||||
"version": "1.0.0",
|
||||
"from": "memoizeasync@1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/memoizeasync/-/memoizeasync-1.0.0.tgz",
|
||||
"dependencies": {
|
||||
"lru-cache": {
|
||||
"version": "2.5.0",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz"
|
||||
},
|
||||
"passerror": {
|
||||
"version": "0.0.2",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/passerror/-/passerror-0.0.2.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -6176,6 +6263,18 @@
|
||||
"from": "normalize-path@>=2.0.1 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.0.1.tgz"
|
||||
},
|
||||
"npmconf": {
|
||||
"version": "2.0.9",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/npmconf/-/npmconf-2.0.9.tgz",
|
||||
"dependencies": {
|
||||
"semver": {
|
||||
"version": "4.3.6",
|
||||
"from": "semver@>=2.0.0 <3.0.0||>=3.0.0 <4.0.0||>=4.0.0 <5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"npmlog": {
|
||||
"version": "4.0.2",
|
||||
"from": "npmlog@>=0.0.0 <1.0.0||>=1.0.0 <2.0.0||>=2.0.0 <3.0.0||>=3.0.0 <4.0.0||>=4.0.0 <5.0.0",
|
||||
@@ -6400,9 +6499,9 @@
|
||||
"resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-2.0.0.tgz"
|
||||
},
|
||||
"passerror": {
|
||||
"version": "0.0.1",
|
||||
"from": "passerror@0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/passerror/-/passerror-0.0.1.tgz"
|
||||
"version": "1.1.1",
|
||||
"from": "passerror@1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/passerror/-/passerror-1.1.1.tgz"
|
||||
},
|
||||
"path-browserify": {
|
||||
"version": "0.0.0",
|
||||
@@ -6511,6 +6610,11 @@
|
||||
"from": "process-nextick-args@>=1.0.6 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.6.tgz"
|
||||
},
|
||||
"progress": {
|
||||
"version": "1.1.8",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz"
|
||||
},
|
||||
"promise": {
|
||||
"version": "7.1.1",
|
||||
"from": "promise@>=7.0.3 <8.0.0",
|
||||
@@ -6533,6 +6637,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"proto-list": {
|
||||
"version": "1.2.4",
|
||||
"from": "proto-list@>=1.2.1 <1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz"
|
||||
},
|
||||
"protobufjs": {
|
||||
"version": "5.0.0",
|
||||
"from": "[email protected]",
|
||||
@@ -6934,6 +7043,11 @@
|
||||
"from": "request-capture-har@>=1.1.4 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/request-capture-har/-/request-capture-har-1.1.4.tgz"
|
||||
},
|
||||
"request-progress": {
|
||||
"version": "0.3.1",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/request-progress/-/request-progress-0.3.1.tgz"
|
||||
},
|
||||
"requires-port": {
|
||||
"version": "1.0.0",
|
||||
"from": "requires-port@>=1.0.0 <2.0.0",
|
||||
@@ -7604,6 +7718,11 @@
|
||||
"from": "text-extensions@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/text-extensions/-/text-extensions-1.3.3.tgz"
|
||||
},
|
||||
"throttleit": {
|
||||
"version": "0.0.2",
|
||||
"from": "throttleit@>=0.0.2 <0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/throttleit/-/throttleit-0.0.2.tgz"
|
||||
},
|
||||
"through": {
|
||||
"version": "2.3.8",
|
||||
"from": "through@>=2.2.7 <3.0.0",
|
||||
@@ -7880,6 +7999,11 @@
|
||||
"from": "uglify-to-browserify@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz"
|
||||
},
|
||||
"uid-number": {
|
||||
"version": "0.0.5",
|
||||
"from": "[email protected]",
|
||||
"resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.5.tgz"
|
||||
},
|
||||
"uid-safe": {
|
||||
"version": "2.0.0",
|
||||
"from": "uid-safe@>=2.0.0 <2.1.0",
|
||||
@@ -8427,9 +8551,9 @@
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz"
|
||||
},
|
||||
"xmldom": {
|
||||
"version": "0.1.19",
|
||||
"from": "[email protected].19",
|
||||
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.19.tgz"
|
||||
"version": "0.1.27",
|
||||
"from": "[email protected].27",
|
||||
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz"
|
||||
},
|
||||
"xmlhttprequest-ssl": {
|
||||
"version": "1.5.1",
|
||||
@@ -8437,9 +8561,9 @@
|
||||
"resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.1.tgz"
|
||||
},
|
||||
"xpath": {
|
||||
"version": "0.0.7",
|
||||
"from": "[email protected].7",
|
||||
"resolved": "https://registry.npmjs.org/xpath/-/xpath-0.0.7.tgz"
|
||||
"version": "0.0.24",
|
||||
"from": "[email protected].24",
|
||||
"resolved": "https://registry.npmjs.org/xpath/-/xpath-0.0.24.tgz"
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.1",
|
||||
|
||||
+3
-1
@@ -48,7 +48,9 @@
|
||||
"canonical-path": "0.0.2",
|
||||
"chokidar": "^1.1.0",
|
||||
"clang-format": "^1.0.32",
|
||||
"cldr": "^3.5.2",
|
||||
"cldr": "^4.5.0",
|
||||
"cldr-data-downloader": "^0.3.2",
|
||||
"cldrjs": "^0.5.0",
|
||||
"conventional-changelog": "^1.1.0",
|
||||
"cors": "^2.7.1",
|
||||
"dgeni": "^0.4.2",
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
const cldr = require('cldr');
|
||||
// locale list
|
||||
const locales = cldr.localeIds;
|
||||
const langToRule = {};
|
||||
const ruleToLang = {};
|
||||
const variants = [];
|
||||
const localeToVariant = {};
|
||||
const DEFAULT_RULE = `function anonymous(n\n/**/) {\nreturn"other"\n}`;
|
||||
const EMPTY_RULE = `function anonymous(n\n/**/) {\n\n}`;
|
||||
|
||||
locales.forEach(locale => {
|
||||
const rule = normalizeRule(cldr.extractPluralRuleFunction(locale).toString());
|
||||
const lang = getVariantLang(locale, rule);
|
||||
|
||||
if (!lang || !rule) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ruleToLang[rule]) {
|
||||
ruleToLang[rule] = [];
|
||||
} else if (ruleToLang[rule].indexOf(lang) > -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
ruleToLang[rule].push(lang);
|
||||
});
|
||||
|
||||
let nextVariantCode = 'a'.charCodeAt(0);
|
||||
|
||||
variants.forEach(locale => {
|
||||
const rule = normalizeRule(cldr.extractPluralRuleFunction(locale).toString());
|
||||
if (!rule) {
|
||||
return;
|
||||
}
|
||||
|
||||
let mapTo = null;
|
||||
|
||||
if (ruleToLang[rule]) {
|
||||
mapTo = ruleToLang[rule][0];
|
||||
localeToVariant[locale] = mapTo;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mapTo) {
|
||||
mapTo = '_' + String.fromCharCode(nextVariantCode++);
|
||||
|
||||
langToRule[mapTo] = rule;
|
||||
ruleToLang[rule] = [mapTo];
|
||||
localeToVariant[locale] = mapTo;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(generateCode());
|
||||
|
||||
function generateCode() {
|
||||
checkMapping();
|
||||
|
||||
return `
|
||||
// This is generated code DO NOT MODIFY
|
||||
// see angular/script/cldr/gen_plural_rules.js
|
||||
|
||||
/** @experimental */
|
||||
export enum Plural {
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
Few,
|
||||
Many,
|
||||
Other,
|
||||
}
|
||||
` + generateVars() +
|
||||
generateRules() + `
|
||||
}`;
|
||||
}
|
||||
|
||||
function generateRules() {
|
||||
const codeParts = [`
|
||||
const lang = locale.split('-')[0].toLowerCase();
|
||||
|
||||
switch (lang) {`];
|
||||
|
||||
Object.keys(ruleToLang).forEach(rule => {
|
||||
const langs = ruleToLang[rule];
|
||||
codeParts.push(...langs.map(l => ` case '${l}': `));
|
||||
codeParts.push(` ${rule}`);
|
||||
});
|
||||
|
||||
codeParts.push(` // When there is no specification, the default is always other
|
||||
// see http://cldr.unicode.org/index/cldr-spec/plural-rules
|
||||
// "other (required—general plural form — also used if the language only has a single form)"
|
||||
default:
|
||||
return Plural.Other;
|
||||
}`);
|
||||
|
||||
return codeParts.join('\n');
|
||||
}
|
||||
|
||||
function generateVars(){
|
||||
return `
|
||||
/**
|
||||
* Returns the plural case based on the locale
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function getPluralCase(locale: string, nLike: number | string): Plural {
|
||||
// TODO(vicb): lazy compute
|
||||
if (typeof nLike === 'string') {
|
||||
nLike = parseInt(<string>nLike, 10);
|
||||
}
|
||||
const n: number = nLike as number;
|
||||
const nDecimal = n.toString().replace(/^[^.]*\\.?/, '');
|
||||
const i = Math.floor(Math.abs(n));
|
||||
const v = nDecimal.length;
|
||||
const f = parseInt(nDecimal, 10);
|
||||
const t = parseInt(n.toString().replace(/^[^.]*\\.?|0+$/g,''), 10) || 0;
|
||||
`;
|
||||
}
|
||||
|
||||
function checkMapping() {
|
||||
if (localeToVariant.length) {
|
||||
console.log(`Mapping required:`);
|
||||
console.log(localeToVariant);
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the language rule do not match an existing language rule, flag it as variant and handle it at the end
|
||||
*/
|
||||
function getVariantLang(locale, rule) {
|
||||
let lang = locale.split('_')[0];
|
||||
|
||||
if (!langToRule[lang]) {
|
||||
langToRule[lang] = rule;
|
||||
return lang;
|
||||
}
|
||||
|
||||
if (langToRule[lang] === rule) {
|
||||
return lang;
|
||||
}
|
||||
|
||||
variants.push(locale);
|
||||
return null;
|
||||
}
|
||||
|
||||
function normalizeRule(fn) {
|
||||
if (fn === DEFAULT_RULE || fn === EMPTY_RULE) return;
|
||||
|
||||
return fn
|
||||
.replace(toRegExp('function anonymous(n\n/**/) {\n'), '')
|
||||
.replace(toRegExp('var'), 'let')
|
||||
.replace(toRegExp('"zero"'), ' Plural.Zero')
|
||||
.replace(toRegExp('"one"'), ' Plural.One')
|
||||
.replace(toRegExp('"two"'), ' Plural.Two')
|
||||
.replace(toRegExp('"few"'), ' Plural.Few')
|
||||
.replace(toRegExp('"many"'), ' Plural.Many')
|
||||
.replace(toRegExp('"other"'), ' Plural.Other')
|
||||
.replace(toRegExp('\n}'), '')
|
||||
.replace(toRegExp('let'), '')
|
||||
.replace(toRegExp('if(typeof n==="string")n=parseInt(n,10);'), '')
|
||||
.replace(toRegExp('i=Math.floor(Math.abs(n))'), '')
|
||||
.replace(/v=n.toString.*?.length/g, '')
|
||||
.replace(/f=parseInt.*?\|\|0/g, '')
|
||||
.replace(/t=parseInt.*?\|\|0/g, '')
|
||||
.replace(/^[ ,;]*/, '')
|
||||
+ ';';
|
||||
}
|
||||
|
||||
function toRegExp(s) {
|
||||
return new RegExp(s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'), 'g');
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = {
|
||||
extract: gulp => done => {
|
||||
if (!fs.existsSync(path.join(__dirname, 'cldr/cldr-data'))) {
|
||||
throw new Error(`You must run "gulp cldr:download" before you can extract the data`);
|
||||
}
|
||||
const extract = require('./cldr/extract');
|
||||
return extract(gulp, done);
|
||||
},
|
||||
|
||||
download: gulp => done => {
|
||||
const cldrDownloader = require('cldr-data-downloader');
|
||||
const cldrDataFolder = path.join(__dirname, 'cldr/cldr-data');
|
||||
if (!fs.existsSync(cldrDataFolder)) {
|
||||
fs.mkdirSync(cldrDataFolder);
|
||||
}
|
||||
cldrDownloader(path.join(__dirname, 'cldr/cldr-urls.json'), cldrDataFolder, done);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Npm module for Unicode CLDR JSON data
|
||||
*
|
||||
* @license
|
||||
* Copyright 2013 Rafael Xavier de Souza
|
||||
* Released under the MIT license
|
||||
* https://github.com/rxaviers/cldr-data-npm/blob/master/LICENSE-MIT
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const JSON_EXTENSION = /^(.*)\.json$/;
|
||||
|
||||
const assert = require('assert');
|
||||
const _fs = require('fs');
|
||||
const _path = require('path');
|
||||
|
||||
function argsToArray(arg) {
|
||||
return [].slice.call(arg, 0);
|
||||
}
|
||||
|
||||
function jsonFiles(dirName) {
|
||||
const fileList = _fs.readdirSync(_path.join(__dirname, 'cldr-data', dirName));
|
||||
|
||||
return fileList.reduce(function(sum, file) {
|
||||
if (JSON_EXTENSION.test(file)) {
|
||||
return sum.concat(file.match(JSON_EXTENSION)[1]);
|
||||
}
|
||||
}, []);
|
||||
}
|
||||
|
||||
function cldrData(path /*, ...*/) {
|
||||
assert(
|
||||
typeof path === 'string', 'must include path (e.g., ' +
|
||||
'"main/en/numbers" or "supplemental/likelySubtags")');
|
||||
|
||||
if (arguments.length > 1) {
|
||||
return argsToArray(arguments).reduce(function(sum, path) {
|
||||
sum.push(cldrData(path));
|
||||
return sum;
|
||||
}, []);
|
||||
}
|
||||
return require('./cldr-data/' + path);
|
||||
}
|
||||
|
||||
function mainPathsFor(locales) {
|
||||
return locales.reduce(function(sum, locale) {
|
||||
const mainFiles = jsonFiles(_path.join('main', locale));
|
||||
mainFiles.forEach(function(mainFile) { sum.push(_path.join('main', locale, mainFile)); });
|
||||
return sum;
|
||||
}, []);
|
||||
}
|
||||
|
||||
function supplementalPaths() {
|
||||
const supplementalFiles = jsonFiles('supplemental');
|
||||
|
||||
return supplementalFiles.map(function(supplementalFile) {
|
||||
return _path.join('supplemental', supplementalFile);
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(
|
||||
cldrData, 'availableLocales',
|
||||
{get: function() { return cldrData('availableLocales').availableLocales; }});
|
||||
|
||||
cldrData.all = function() {
|
||||
const paths = supplementalPaths().concat(mainPathsFor(this.availableLocales));
|
||||
return cldrData.apply({}, paths);
|
||||
};
|
||||
|
||||
cldrData.entireMainFor = function(locale /*, ...*/) {
|
||||
assert(
|
||||
typeof locale === 'string', 'must include locale (e.g., ' +
|
||||
'"en")');
|
||||
return cldrData.apply({}, mainPathsFor(argsToArray(arguments)));
|
||||
};
|
||||
|
||||
cldrData.entireSupplemental = function() {
|
||||
return cldrData.apply({}, supplementalPaths());
|
||||
};
|
||||
|
||||
module.exports = cldrData;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"core": [
|
||||
"https://github.com/unicode-cldr/cldr-core/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-segments-modern/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-dates-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-buddhist-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-chinese-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-coptic-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-dangi-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-ethiopic-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-hebrew-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-indian-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-islamic-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-japanese-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-persian-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-roc-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-localenames-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-misc-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-numbers-full/archive/31.0.1.zip",
|
||||
"https://github.com/unicode-cldr/cldr-units-full/archive/31.0.1.zip"
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,13 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
const {I18N_FOLDER, I18N_DATA_FOLDER} = require('./cldr/extract');
|
||||
|
||||
// clang-format entry points
|
||||
const srcsToFmt = [
|
||||
'packages/**/*.{js,ts}',
|
||||
@@ -8,6 +18,11 @@ const srcsToFmt = [
|
||||
'!tools/public_api_guard/**/*.d.ts',
|
||||
'./*.{js,ts}',
|
||||
'!shims_for_IE.js',
|
||||
`!${I18N_DATA_FOLDER}/**/*.{js,ts}`,
|
||||
`!${I18N_FOLDER}/available_locales.ts`,
|
||||
`!${I18N_FOLDER}/currencies.ts`,
|
||||
`!${I18N_FOLDER}/locale_en.ts`,
|
||||
'!tools/gulp-tasks/cldr/extract.js',
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user