Remove i18n in plugin generators

This commit is contained in:
Pierre Burgy 2017-08-14 17:34:49 +02:00
parent 9d11c38ac7
commit 1184bc9bf4
12 changed files with 1 additions and 101 deletions

View File

@ -44,4 +44,4 @@
"npm": ">= 5.3.0"
},
"license": "MIT"
}
}

View File

@ -29,11 +29,6 @@ module.exports = {
name: 'wantCSS',
default: true,
message: 'Does it have styling?',
}, {
type: 'confirm',
name: 'wantMessages',
default: true,
message: 'Do you want i18n messages (i.e. will this component use text)?',
}],
actions: (data) => {
// Generate index.js and index.test.js

View File

@ -47,11 +47,6 @@ module.exports = {
name: 'wantSagas',
default: true,
message: 'Do you want sagas for asynchronous flows? (e.g. fetching data)',
}, {
type: 'confirm',
name: 'wantMessages',
default: true,
message: 'Do you want i18n messages (i.e. will this component use text)?',
}],
actions: (data) => {
// Expose `pluginId` value

View File

@ -10,13 +10,11 @@ const path = require('path');
const componentGenerator = require('./component/index.js');
const containerGenerator = require('./container/index.js');
const routeGenerator = require('./route/index.js');
const languageGenerator = require('./language/index.js');
module.exports = (plop) => {
plop.setGenerator('component', componentGenerator);
plop.setGenerator('container', containerGenerator);
plop.setGenerator('route', routeGenerator);
plop.setGenerator('language', languageGenerator);
plop.addHelper('directory', (comp) => {
try {
fs.accessSync(`${path.resolve(process.cwd(), 'admin', 'src', 'containers', comp)}`, fs.F_OK);

View File

@ -1 +0,0 @@
$1addLocaleData({{language}}LocaleData);

View File

@ -1 +0,0 @@
$1 {{language}}: formatTranslationMessages({{language}}TranslationMessages),

View File

@ -1,80 +0,0 @@
/**
* Language Generator
*/
const exec = require('child_process').exec;
module.exports = {
description: 'Add a langauge',
prompts: [{
type: 'input',
name: 'language',
message: 'What is the language you want to add i18n support for (e.g. "fr", "de")?',
default: 'fr',
validate: (value) => {
if ((/.+/).test(value) && value.length === 2) {
return true;
}
return '2 character language specifier is required';
},
}],
actions: () => {
const actions = [];
actions.push({
type: 'modify',
path: '../../../../../admin/src/i18n.js',
pattern: /('react-intl\/locale-data\/[a-z]+';\n)(?!.*'react-intl\/locale-data\/[a-z]+';)/g,
templateFile: './language/intl-locale-data.hbs',
});
actions.push({
type: 'modify',
path: '../../../../../admin/src/i18n.js',
pattern: /([\n\s'[a-z]+',)(?!.*[\n\s'[a-z]+',)/g,
templateFile: './language/src-locale.hbs',
});
actions.push({
type: 'modify',
path: '../../../../../admin/src/i18n.js',
pattern: /(from\s'.\/translations\/[a-z]+.json';\n)(?!.*from\s'.\/translations\/[a-z]+.json';)/g,
templateFile: './language/translation-messages.hbs',
});
actions.push({
type: 'modify',
path: '../../../../../admin/src/i18n.js',
pattern: /(addLocaleData\([a-z]+LocaleData\);\n)(?!.*addLocaleData\([a-z]+LocaleData\);)/g,
templateFile: './language/add-locale-data.hbs',
});
actions.push({
type: 'modify',
path: '../../../../../admin/src/i18n.js',
pattern: /([a-z]+:\sformatTranslationMessages\([a-z]+TranslationMessages\),\n)(?!.*[a-z]+:\sformatTranslationMessages\([a-z]+TranslationMessages\),)/g,
templateFile: './language/format-translation-messages.hbs',
});
actions.push({
type: 'add',
path: '../../../../../admin/src/translations/{{language}}.json',
templateFile: './language/translations-json.hbs',
abortOnFail: true,
});
actions.push({
type: 'modify',
path: '../../../../../admin/src/app.js',
pattern: /(System\.import\('intl\/locale-data\/jsonp\/[a-z]+\.js'\),\n)(?!.*System\.import\('intl\/locale-data\/jsonp\/[a-z]+\.js'\),)/g,
templateFile: './language/polyfill-intl-locale.hbs',
});
actions.push(
() => {
const cmd = 'npm run extract-intl';
exec(cmd, (err, result, stderr) => {
if (err || stderr) {
throw err || stderr;
}
process.stdout.write(result);
});
}
);
return actions;
},
};

View File

@ -1 +0,0 @@
$1import {{language}}LocaleData from 'react-intl/locale-data/{{language}}';

View File

@ -1 +0,0 @@
$1 System.import('intl/locale-data/jsonp/{{language}}.js'),

View File

@ -1 +0,0 @@
$1import {{language}}TranslationMessages from './translations/{{language}}.json';