diff options
| author | Di Peng | 2011-08-17 14:43:38 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-08-30 02:11:09 -0700 |
| commit | 545b31aa2ef20ad241be0a3d87ae328fdbf2404a (patch) | |
| tree | 6009e16d818d968198c67cb47b9084ac34e5ffef /i18n/src/closureSlurper.js | |
| parent | e068addadb14b44374ebb5353b860700731c866f (diff) | |
| download | angular.js-545b31aa2ef20ad241be0a3d87ae328fdbf2404a.tar.bz2 | |
feat(closureSlurper): closureSlurper plural rules
- fetch plural rules from closure
- distribtue pluralization rules into each locale specific files
Diffstat (limited to 'i18n/src/closureSlurper.js')
| -rw-r--r-- | i18n/src/closureSlurper.js | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/i18n/src/closureSlurper.js b/i18n/src/closureSlurper.js index 32ef022c..69c94e10 100644 --- a/i18n/src/closureSlurper.js +++ b/i18n/src/closureSlurper.js @@ -11,7 +11,7 @@ var Q = require('qq'), currencySymbols, goog = { provide: function() {}, require: function() {}, - i18n: {currency: {}} }; + i18n: {currency: {}, pluralRules: {}} }; createFolder('../locale/').then(function() { var promiseA = Q.defer(), @@ -58,9 +58,29 @@ createFolder('../locale/').then(function() { promiseB.resolve(); }); - + return Q.join(promiseA.promise, promiseB.promise, noop); }).then(function() { + var promise = Q.defer(); + + qfs.read(__dirname + '/../closure/pluralRules.js').then(function(content) { + for(var i = 0; i < localeIds.length; i++) { + //We don't need to care about country ID because the plural rules in more specific id are + //always the same as those in its language ID. + // e.g. plural rules for en_SG is the same as those for en. + goog.LOCALE = localeIds[i].match(/[^_]+/)[0]; + eval(content); + var temp = goog.i18n.pluralRules.select.toString(). + replace(/goog.i18n.pluralRules.Keyword/g, 'PLURAL_CATEGORY').replace(/\n/g, ''); + + ///@@ is a crazy place holder to be replaced before writing to file + localeInfo[localeIds[i]].pluralCat = "@@" + temp + "@@"; + } + promise.resolve(); + }); + + return promise.promise; +}).then(function() { localeIds.forEach(function(localeID) { var fallBackID = localeID.match(/[A-Za-z]+/)[0], localeObj = localeInfo[localeID], @@ -80,14 +100,18 @@ createFolder('../locale/').then(function() { var correctedLocaleId = localeID.replace(/_/g, '-').toLowerCase(); localeObj.id = correctedLocaleId; - var prefix = 'angular.service("$locale", function() {\nreturn ', - content = JSON.stringify(localeInfo[localeID]).replace(/\¤/g,'\\u00A4'), - suffix; + var prefix = 'angular.service("$locale", function() {\n' + + 'var PLURAL_CATEGORY = {' + + 'ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"' + + '};\n' + + 'return '; - suffix = ';\n});'; + var suffix = ';\n});'; - var toWrite = prefix + content + suffix; + var content = JSON.stringify(localeInfo[localeID]).replace(/\¤/g,'\\u00A4'). + replace(/"@@|@@"/g, ''); + var toWrite = prefix + content + suffix; qfs.write(__dirname + '/../locale/' + 'angular-locale_' + correctedLocaleId + '.js', toWrite); }); console.log('Generated ' + localeIds.length + ' locale files!'); |
