Commit 1ab83397 authored by Phyks (Lucas Verney)'s avatar Phyks (Lucas Verney)
Browse files

i18n-extract

parent 330e337f
Pipeline #20334 failed with stage
in 5 minutes and 27 seconds
......@@ -61,12 +61,12 @@ class CategoryList extends React.Component {
let buttonType = 'plus';
let buttonAriaLabel = 'add';
let buttonLabel = 'client.category.add';
let buttonLabel = $t('client.category.add');
if (this.state.showForm) {
buttonType = 'minus';
buttonAriaLabel = 'cancel';
buttonLabel = 'client.general.cancel';
buttonLabel = $t('client.general.cancel');
}
return (
......@@ -80,7 +80,7 @@ class CategoryList extends React.Component {
<span
className={ `option-legend fa fa-${buttonType}-circle` }
aria-label={ buttonAriaLabel }
title={ $t(buttonLabel) }
title={ buttonLabel }
onClick={ this.handleShowForm }
/>
</div>
......
import fs from 'fs';
import path from 'path';
import process from 'process';
import {
extractFromFiles,
findMissing,
findUnused,
findDuplicated,
flatten,
} from 'i18n-extract';
import { forbidDynamic } from 'i18n-extract';
import { makeLogger } from '../server/helpers';
const logger = makeLogger('check-locales');
// Find locale keys in the code
const keys = extractFromFiles(['client/**/*.js'], { marker: '$t' });
let dynamic_keys = forbidDynamic({}, keys);
// Forbid any dynamic key
if (dynamic_keys.length > 0) {
dynamic_keys = dynamic_keys.map(item => {
item.location = `${item.file}:${item.loc.start.line}`;
delete item.loc;
delete item.file;
return item;
});
dynamic_keys = JSON.stringify(dynamic_keys, null, 2);
logger.error(`Found some dynamic keys: ${dynamic_keys}.`);
logger.error('Dynamic keys are not allowed.');
process.exit(1);
}
// Get all locales in Kresus
const locales = {};
const localesPath = path.resolve(__dirname, '..', 'shared', 'locales');
fs.readdirSync(localesPath).forEach(file => {
const localeData = require(path.join(localesPath, file));
const localeName = file.replace(/\.[^/.]+$/, '');
locales[localeName] = flatten(localeData);
})
for (let locale of Object.keys(locales)) {
logger.info(`Checking locale ${locale}...`);
let reports = [];
reports = reports.concat(findMissing(locales[locale], keys));
reports = reports.concat(findUnused(locales[locale], keys));
if (reports.length > 0) {
logger.error(`Found missing and unused keys: ${reports}.`);
process.exit(1);
} else {
logger.info(`Locale ${locale} is OK!`);
}
}
#!/bin/bash
set -e
# Compare locales
./node_modules/babel-cli/bin/babel-node.js --presets es2015 ./scripts/compare-locales.js && \
./node_modules/babel-cli/bin/babel-node.js --presets es2015 ./scripts/compare-locales.js
# Check locales are correctly used (no missing value, no extra value)
./node_modules/babel-cli/bin/babel-node.js --presets es2015 ./scripts/check-locales.js
# Check all bank related data is correct (logo, translation keys ...)
./node_modules/babel-cli/bin/babel-node.js --presets es2015 ./scripts/check-banks.js && \
./node_modules/babel-cli/bin/babel-node.js --presets es2015 ./scripts/check-banks.js
# Run proper tests
./node_modules/mocha/bin/mocha ./tests/ --recursive --require babel-register
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