From f392b3cacca3629bece772a1adef94b42e4fdce9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 19 Mar 2013 15:31:13 -0400 Subject: [PATCH] build.js now updates locales with local en changes --- CONTRIBUTING.md | 3 +++ build.js | 10 +++++++++- data/update_locales.js | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f719095a4..38d58fa61 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -69,6 +69,9 @@ Then, add the new string to `data/core.yaml` or `data/presets.yaml` (depending on whether it pertains to core code or presets). The translation system, Transiflex, will automatically detect the change. +Use `make` to build the translations with the local changes. +`make translate` can be used to pull the latest translations from Transifex. + ## Javascript We use the [Airbnb style for Javascript](https://github.com/airbnb/javascript) with diff --git a/build.js b/build.js index fbe2535fa..7f77b6de1 100644 --- a/build.js +++ b/build.js @@ -1,7 +1,8 @@ var fs = require('fs'), path = require('path'), glob = require('glob'), - YAML = require('js-yaml'); + YAML = require('js-yaml'), + _ = require('./js/lib/lodash'); function read(f) { return JSON.parse(fs.readFileSync(f)); @@ -60,3 +61,10 @@ fs.writeFileSync('data/data.js', 'iD.data = ' + JSON.stringify({ fields: rp('fields.json') } }, null, 4) + ';'); + +// Push changes from data/core.yaml into data/locales.js +var core = YAML.load(fs.readFileSync('data/core.yaml', 'utf8')); +var presets = YAML.load(fs.readFileSync('data/presets.yaml', 'utf8')); +var en = _.merge(core, presets); +var out = 'locale.en = ' + JSON.stringify(en.en, null, 4) + ';\n'; +fs.writeFileSync('data/locales.js', fs.readFileSync('data/locales.js', 'utf8').replace(/locale.en =[^;]*;/, out)); diff --git a/data/update_locales.js b/data/update_locales.js index 91c9b2b6c..5bcccf70f 100644 --- a/data/update_locales.js +++ b/data/update_locales.js @@ -1,3 +1,5 @@ +/* Downloads the latest translations from Transifex */ + var request = require('request'), yaml = require('js-yaml'), fs = require('fs'), @@ -32,7 +34,7 @@ asyncMap(resources, getResource, function(err, locales) { }); for (var i in locale) { - out += 'locale.' + i + ' = ' + JSON.stringify(locale[i], null, 4) + ';'; + out += 'locale.' + i + ' = ' + JSON.stringify(locale[i], null, 4) + ';\n'; } fs.writeFileSync(outfile, out); });