-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate main i18n tool into build pipeline #22254
Changes from 1 commit
0f9eb7a
df5cb71
dcb35f1
b90f21a
08f91bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,74 +17,30 @@ | |
* under the License. | ||
*/ | ||
|
||
// TODO: Integrate a new tool for translations checking | ||
// https://github.com/elastic/kibana/pull/19826 | ||
import { i18nLoader } from '@kbn/i18n'; | ||
const { resolve } = require('path'); | ||
|
||
import { toArray } from 'rxjs/operators'; | ||
import { fromRoot, formatListAsProse } from '../src/utils'; | ||
import { findPluginSpecs } from '../src/plugin_discovery'; | ||
import { collectUiExports } from '../src/ui'; | ||
|
||
import * as i18nVerify from './utils/i18n_verify_keys'; | ||
|
||
export default function (grunt) { | ||
grunt.registerTask('verifyTranslations', async function () { | ||
module.exports = function (grunt) { | ||
grunt.registerTask('verifyTranslations', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: hmm, can you please make And let's rename |
||
const done = this.async(); | ||
|
||
try { | ||
const { spec$ } = findPluginSpecs({ | ||
env: 'production', | ||
plugins: { | ||
scanDirs: [fromRoot('src/core_plugins')] | ||
const serverCmd = { | ||
cmd: 'node', | ||
args: [resolve(__dirname, '../scripts/extract_default_translations')], | ||
opts: { stdio: 'inherit' }, | ||
}; | ||
|
||
new Promise((resolve, reject) => { | ||
grunt.util.spawn(serverCmd, (error, result, code) => { | ||
if (error || code !== 0) { | ||
const error = new Error(`verifyTranslations exited with code ${code}`); | ||
grunt.fail.fatal(error); | ||
reject(error); | ||
return; | ||
} | ||
}); | ||
|
||
const specs = await spec$.pipe(toArray()).toPromise(); | ||
const uiExports = collectUiExports(specs); | ||
await verifyTranslations(uiExports); | ||
|
||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
grunt.log.writeln(result); | ||
resolve(); | ||
}); | ||
}).then(done, done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is likely more obsolete, I would use: .then(done)
.catch(done) |
||
}); | ||
|
||
} | ||
|
||
async function verifyTranslations(uiExports) { | ||
const keysUsedInViews = []; | ||
|
||
// Search files for used translation keys | ||
const translationPatterns = [ | ||
{ regexp: 'i18n\\(\'(.*)\'\\)', | ||
parsePaths: [fromRoot('src/ui/ui_render/views/*.pug')] } | ||
]; | ||
for (const { regexp, parsePaths } of translationPatterns) { | ||
const keys = await i18nVerify.getTranslationKeys(regexp, parsePaths); | ||
for (const key of keys) { | ||
keysUsedInViews.push(key); | ||
} | ||
} | ||
|
||
// get all of the translations from uiExports | ||
const translations = await i18nLoader.getAllTranslationsFromPaths(uiExports.translationPaths); | ||
const keysWithoutTranslations = Object.entries( | ||
i18nVerify.getNonTranslatedKeys(keysUsedInViews, translations) | ||
); | ||
|
||
if (!keysWithoutTranslations.length) { | ||
return; | ||
} | ||
|
||
throw new Error( | ||
'\n' + | ||
'\n' + | ||
'The following keys are used in angular/pug views but are not translated:\n' + | ||
keysWithoutTranslations.map(([locale, keys]) => ( | ||
` - ${locale}: ${formatListAsProse(keys)}` | ||
)).join('\n') + | ||
'\n' + | ||
'\n' | ||
); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please update ids for all existing
UI-WELCOME_
messages we have in Kibana (inknb-plugin-helpers
tests) and removesrc/ui/translations
entirely for now.