Commit fc834b88 authored by Matthew Taylor's avatar Matthew Taylor

Move scripts to new `lib` folder

Thanks @thisandagain for the tip!
parent ca102324
......@@ -35,7 +35,7 @@ static:
cp -a ./static/. ./build/
translations:
./src/scripts/buildLocales/build-locales locales/translations.json
./lib/bin/build-locales locales/translations.json
webpack:
$(WEBPACK) --bail
......@@ -59,13 +59,12 @@ start:
test:
@make lint
@make build
@echo ""
@make unit
@echo ""
@make functional
@echo ""
@make integration
@echo ""
lint:
$(ESLINT) ./*.js
......
......@@ -10,7 +10,7 @@ var glob = require('glob');
var path = require('path');
var po2icu = require('po2icu');
var helpers = require('./helpers');
var localeCompare = require('../locale-compare');
// -----------------------------------------------------------------------------
// Main script
......@@ -45,7 +45,7 @@ var icuWithIds = {};
for (var id in idsWithICU) {
icuWithIds[idsWithICU[id]] = id;
}
var md5WithIds = helpers.getMD5Map(icuWithIds);
var md5WithIds = localeCompare.getMD5Map(icuWithIds);
// Get ui localization strings first
glob(poUiDir + '/*', function (err, files) {
......@@ -59,14 +59,14 @@ glob(poUiDir + '/*', function (err, files) {
var translations = {};
try {
var jsTranslations = po2icu.poFileToICUSync(lang, jsFile);
translations = helpers.mergeNewTranslations(translations, jsTranslations, md5WithIds);
translations = localeCompare.mergeNewTranslations(translations, jsTranslations, md5WithIds);
} catch (err) {
process.stdout.write(lang + ': ' + err + '\n');
}
try {
var pyTranslations = po2icu.poFileToICUSync(lang, pyFile);
translations = helpers.mergeNewTranslations(translations, pyTranslations, md5WithIds);
translations = localeCompare.mergeNewTranslations(translations, pyTranslations, md5WithIds);
} catch (err) {
process.stdout.write(lang + ': ' + err + '\n');
}
......
......@@ -46,7 +46,7 @@ Helpers.mergeNewTranslations = function (existingTranslations, newTranslations,
*
* @param {object} idICUMap map where key=icuString, value=react-intl id
*
* @return {objec}
* @return {object}
*/
Helpers.getMD5Map = function (ICUIdMap) {
var md5Map = {};
......
{
"2ec20d41b181e1a41c071e13f414a74d": "test.id1",
"37ba6d5ef524504215f478912155f9ba": "test.id2"
}
......@@ -3,12 +3,11 @@ var path = require('path');
var po2icu = require('po2icu');
var tap = require('tap');
var buildLocales = require('../../src/scripts/buildLocales/helpers');
var buildLocales = require('../../lib/locale-compare');
tap.test('buildLocalesFile', function (t) {
var templates = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../fixtures/build_locales.json'), 'utf8'));
var md5map = buildLocales.getMD5Map(templates);
var newTranslations = po2icu.poFileToICUSync('es', path.resolve(__dirname, '../fixtures/build_locales.po'));
var md5map = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../fixtures/test_es_md5map.json'), 'utf8'));
var newTranslations = po2icu.poFileToICUSync('es', path.resolve(__dirname, '../fixtures/test_es.po'));
var translations = buildLocales.mergeNewTranslations({}, newTranslations, md5map);
t.ok(translations['test.id1'] !== undefined);
......
var fs = require('fs');
var path = require('path');
var tap = require('tap');
var buildLocales = require('../../lib/locale-compare');
tap.test('buildLocalesFile', function (t) {
var actualMd5map = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../fixtures/test_es_md5map.json'), 'utf8'));
var templates = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../fixtures/build_locales.json'), 'utf8'));
var testMd5map = buildLocales.getMD5Map(templates);
for (var key in actualMd5map) {
t.ok(testMd5map[key] !== undefined);
}
t.end();
});
var crypto = require('crypto');
var tap = require('tap');
var buildLocales = require('../../src/scripts/buildLocales/helpers');
var buildLocales = require('../../lib/locale-compare');
tap.test('buildLocalesMergeTranslations', function (t) {
var existingTranslations = {
'test.test1': 'It\'s like raaayaaain, on your wedding day',
'test.test2': 'Free to flyyy, when you already paid'
};
var md5Test1 = crypto.createHash('md5').update(existingTranslations['test.test1'], 'utf8').digest('hex');
var md5Test2 = crypto.createHash('md5').update(existingTranslations['test.test2'], 'utf8').digest('hex');
var md5map = {};
md5map[md5Test1] = 'test.test1';
md5map[md5Test2] = 'test.test2';
var newTranslations = {
'Isn\'t it ironic? No.': 'Es irónico? No.'
};
var md5Test3 = crypto.createHash('md5').update('Isn\'titironic?No.', 'utf8').digest('hex');
md5map[md5Test3] = 'test.test3';
var md5map = {
'c21ce5ceefe167028182032d4255a384': 'test.test1',
'9c40648034e467e16f8d6ae24bd610ab': 'test.test2',
'6885a345adafb3a9dd43d9f549430c88': 'test.test3'
};
var mergedTranslations = buildLocales.mergeNewTranslations(existingTranslations, newTranslations, md5map);
t.ok(mergedTranslations['test.test3'] !== undefined);
......
var tap = require('tap');
var buildLocales = require('../../src/scripts/buildLocales/helpers');
var buildLocales = require('../../lib/locale-compare');
tap.test('buildLocalesGetMD5', function (t) {
var testString1 = 'are there bears here?';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment