
committed by
Andrew Scott

parent
4029c98f16
commit
68380e4af2
@ -6,27 +6,14 @@
|
||||
* 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);
|
||||
},
|
||||
|
||||
closure: gulp => done => {
|
||||
const {RELATIVE_I18N_DATA_FOLDER} = require('./cldr/extract');
|
||||
// tslint:disable-next-line:no-console
|
||||
|
@ -1,84 +0,0 @@
|
||||
// tslint:disable:file-header
|
||||
|
||||
/**
|
||||
* 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;
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"core": [
|
||||
"https://github.com/unicode-cldr/cldr-core/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-segments-modern/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-dates-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-buddhist-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-chinese-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-coptic-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-dangi-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-ethiopic-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-hebrew-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-indian-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-islamic-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-japanese-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-persian-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-cal-roc-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-localenames-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-misc-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-numbers-full/archive/33.0.0.zip",
|
||||
"https://github.com/unicode-cldr/cldr-units-full/archive/33.0.0.zip"
|
||||
]
|
||||
}
|
@ -44,7 +44,7 @@ const HEADER = `/**
|
||||
|
||||
// tslint:disable:no-console
|
||||
module.exports = (gulp, done) => {
|
||||
const cldrData = require('./cldr-data');
|
||||
const cldrData = require('cldr-data');
|
||||
const LOCALES = cldrData.availableLocales;
|
||||
|
||||
console.log(`Loading CLDR data...`);
|
||||
|
Reference in New Issue
Block a user