Skip to content

Commit

Permalink
chore(build): Update closure i18n integration
Browse files Browse the repository at this point in the history
Use git repo as source and use q-io instead of q-fs
  • Loading branch information
tbosch committed Feb 7, 2014
1 parent 16301be commit fcf4393
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
3 changes: 1 addition & 2 deletions i18n/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# i18n directory overview:

- closure/ - closure files we use for ruleset generation
- locale/ - angular's locale ruleset files
- src/ - source files
- spec/ - spec files for stuff in src directory
- generate.sh - runs src scripts on closure dir and stores output in locale dir
- update-closure.sh - downloads the latest version of closure files from public svn repo
- update-closure.sh - downloads the latest version of closure files from public git repo

The closure files (maintained by Shanjian Li (shanjian)) change very rarely, so we don't need to
regenerate locale files very often.
Expand Down
7 changes: 6 additions & 1 deletion i18n/generate.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash

set -e

BASE_DIR=`dirname $0`
cd $BASE_DIR

./run-tests.sh

node src/closureSlurper.js


../node_modules/.bin/jasmine-node spec/ --noColor && node src/closureSlurper.js
3 changes: 2 additions & 1 deletion i18n/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

set -e
PARENT_DIR="$(dirname "$0")"
jasmine-node "$PARENT_DIR"/spec/

../node_modules/.bin/jasmine-node "$PARENT_DIR"/spec/
40 changes: 28 additions & 12 deletions i18n/src/closureSlurper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

var Q = require('q'),
qfs = require('q-fs'),
qfs = require('q-io/fs'),
converter = require('./converter.js'),
util = require('./util.js'),
closureI18nExtractor = require('./closureI18nExtractor.js'),
Expand Down Expand Up @@ -47,24 +47,40 @@ function extractPlurals() {

function writeLocaleFiles() {
console.log('Final stage: Writing angular locale files to directory: %j', NG_LOCALE_DIR);
var writePromises = [];
var result = Q.defer();
var localeIds = Object.keys(localeInfo);
var num_files = 0;
localeIds.forEach(function(localeID) {

console.log('Generated %j locale files.', localeIds.length);
loop();
return result.promise;

// Need to use a loop and not write the files in parallel,
// as otherwise we will get the error EMFILE, which means
// we have too many open files.
function loop() {
var nextPromise;
if (localeIds.length) {
nextPromise = process(localeIds.pop()) || Q.when();
nextPromise.then(loop, result.reject);
} else {
result.resolve(num_files);
}
}

function process(localeID) {
var content = closureI18nExtractor.outputLocale(localeInfo, localeID);
if (!content) return;
var correctedLocaleId = closureI18nExtractor.correctedLocaleId(localeID);
var filename = NG_LOCALE_DIR + 'angular-locale_' + correctedLocaleId + '.js'
writePromises.push(
qfs.write(filename, content)
.then(function () {
console.log('Wrote ' + filename);
++num_files;
}));
console.log('Writing ' + filename);
});
console.log('Generated %j locale files.', localeIds.length);
return Q.all(writePromises).then(function() { return num_files });
return qfs.write(filename, content)
.then(function () {
console.log('Wrote ' + filename);
++num_files;
});
}

}

/**
Expand Down
11 changes: 6 additions & 5 deletions i18n/update-closure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ cd $BASE_DIR

set -x # Trace commands as they're executed.

curl http://closure-library.googlecode.com/svn/trunk/closure/goog/i18n/currency.js > closure/currencySymbols.js
curl http://closure-library.googlecode.com/svn/trunk/closure/goog/i18n/datetimesymbols.js > closure/datetimeSymbols.js
curl http://closure-library.googlecode.com/svn/trunk/closure/goog/i18n/datetimesymbolsext.js > closure/datetimeSymbolsExt.js
curl http://closure-library.googlecode.com/svn/trunk/closure/goog/i18n/numberformatsymbols.js > closure/numberSymbols.js
curl http://closure-library.googlecode.com/svn/trunk/closure/goog/i18n/pluralrules.js > closure/pluralRules.js
# use the github repo as it is more up to date than the svn repo
curl https://closure-library.googlecode.com/git/closure/goog/i18n/currency.js > closure/currencySymbols.js
curl https://closure-library.googlecode.com/git/closure/goog/i18n/datetimesymbols.js > closure/datetimeSymbols.js
curl https://closure-library.googlecode.com/git/closure/goog/i18n/datetimesymbolsext.js > closure/datetimeSymbolsExt.js
curl https://closure-library.googlecode.com/git/closure/goog/i18n/numberformatsymbols.js > closure/numberSymbols.js
curl https://closure-library.googlecode.com/git/closure/goog/i18n/pluralrules.js > closure/pluralRules.js

0 comments on commit fcf4393

Please sign in to comment.