* [eslint] upgrade to 4.10.0
* [eslint-config-kibana] limit jest config to jest test files
* [ui_framework] remove trailing comma from rest-spreads
* [dashboard/tests] tag jest helpers with .test.js suffix
* explicitly import expect.js where used
* [eslint] apply auto-fixes
* [eslint] manually add/wrap some parens for compliance
* [npm] point to local packages for testing/review
* [jest] remove .test extension from jest helpers
* [ui_framework] fix trailing comma removal from 3bc661a1c8
* [packages] upgrade eslint packages
85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
import Promise from 'bluebird';
|
|
import _ from 'lodash';
|
|
|
|
import { fromRoot } from '../../src/utils';
|
|
import KbnServer from '../../src/server/kbn_server';
|
|
import * as i18nVerify from '../utils/i18n_verify_keys';
|
|
|
|
export default function (grunt) {
|
|
|
|
grunt.registerTask('_build:verifyTranslations', [
|
|
'i18nextract',
|
|
'_build:check'
|
|
]);
|
|
|
|
grunt.registerTask('_build:check', function () {
|
|
const done = this.async();
|
|
|
|
const serverConfig = {
|
|
env: 'production',
|
|
logging: {
|
|
silent: true,
|
|
quiet: true,
|
|
verbose: false
|
|
},
|
|
optimize: {
|
|
useBundleCache: false,
|
|
enabled: false
|
|
},
|
|
server: {
|
|
autoListen: false
|
|
},
|
|
plugins: {
|
|
initialize: true,
|
|
scanDirs: [fromRoot('src/core_plugins')]
|
|
},
|
|
uiSettings: {
|
|
enabled: false
|
|
}
|
|
};
|
|
|
|
const kbnServer = new KbnServer(serverConfig);
|
|
kbnServer.ready()
|
|
.then(() => verifyTranslations(kbnServer.uiI18n))
|
|
.then(() => kbnServer.close())
|
|
.then(done)
|
|
.catch((err) => {
|
|
kbnServer.close()
|
|
.then(() => done(err));
|
|
});
|
|
});
|
|
|
|
}
|
|
|
|
function verifyTranslations(uiI18nObj)
|
|
{
|
|
const angularTranslations = require(fromRoot('build/i18n_extract/en.json'));
|
|
const translationKeys = Object.keys(angularTranslations);
|
|
const translationPatterns = [
|
|
{ regEx: 'i18n\\(\'(.*)\'\\)',
|
|
parsePaths: [fromRoot('/src/ui/views/*.jade')] }
|
|
];
|
|
|
|
const keyPromises = _.map(translationPatterns, (pattern) => {
|
|
return i18nVerify.getTranslationKeys(pattern.regEx, pattern.parsePaths)
|
|
.then(function (keys) {
|
|
const arrayLength = keys.length;
|
|
for (let i = 0; i < arrayLength; i++) {
|
|
translationKeys.push(keys[i]);
|
|
}
|
|
});
|
|
});
|
|
|
|
return Promise.all(keyPromises)
|
|
.then(function () {
|
|
return uiI18nObj.getAllTranslations()
|
|
.then(function (translations) {
|
|
const keysNotTranslatedPerLocale = i18nVerify.getNonTranslatedKeys(translationKeys, translations);
|
|
if (!_.isEmpty(keysNotTranslatedPerLocale)) {
|
|
const str = JSON.stringify(keysNotTranslatedPerLocale);
|
|
const errMsg = 'The following translation keys per locale are not translated: ' + str;
|
|
throw new Error(errMsg);
|
|
}
|
|
});
|
|
});
|
|
}
|