Skip to content

Commit

Permalink
Centralize i18n configuration to i18n.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Sep 24, 2017
1 parent 11c14fd commit 6b97583
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 183 deletions.
21 changes: 4 additions & 17 deletions gulp/tasks/i18next.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import _ from 'lodash';
import fs from 'fs';
import gulp from 'gulp';
import gutil from 'gulp-util';
import sort from 'gulp-sort';
import i18nextScanner from 'i18next-scanner';
import table from 'text-table';
import { languages } from '../../i18n.config';

const appConfig = {
src: [
Expand Down Expand Up @@ -57,20 +57,7 @@ const webConfig = {
debug: false,
sort: false,
removeUnusedKeys: true,
lngs: [
'en', // English (default)
'cs', // Czech
'de', // German
'es', // Spanish
'fr', // French
'hu', // Hungarian
'it', // Italian
'ja', // Japanese
'pt-br', // Portuguese (Brazil)
'ru', // Russian
'zh-cn', // Simplified Chinese
'zh-tw' // Traditional Chinese
],
lngs: languages,
defaultValue: (lng, ns, key) => {
if (lng === 'en') {
return key; // Use key as value for base language
Expand Down Expand Up @@ -100,7 +87,7 @@ const webConfig = {
function customTransform(file, enc, done) {
const parser = this.parser;
const content = fs.readFileSync(file.path, enc);
let tableData = [
const tableData = [
['Key', 'Value']
];

Expand All @@ -115,7 +102,7 @@ function customTransform(file, enc, done) {
});
}

if (_.size(tableData) > 1) {
if (tableData.length > 1) {
const text = table(tableData, { 'hsep': ' | ' });
gutil.log('i18next-scanner:', file.relative + '\n' + text);
} else {
Expand Down
File renamed without changes.
111 changes: 0 additions & 111 deletions src/app/api/api.i18n.js

This file was deleted.

1 change: 0 additions & 1 deletion src/app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * as version from './api.version';
export * as state from './api.state';
export * as gcode from './api.gcode';
export * as i18n from './api.i18n';
export * as controllers from './api.controllers';
export * as commands from './api.commands';
export * as events from './api.events';
Expand Down
4 changes: 0 additions & 4 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ const appMain = () => {
app.post(urljoin(settings.route, 'api/watch/files'), api.watch.getFiles);
app.get(urljoin(settings.route, 'api/watch/file'), api.watch.readFile);
app.post(urljoin(settings.route, 'api/watch/file'), api.watch.readFile);

// I18n
app.get(urljoin(settings.route, 'api/i18n/acceptedLng'), api.i18n.getAcceptedLanguage);
app.post(urljoin(settings.route, 'api/i18n/sendMissing/:__lng__/:__ns__'), api.i18n.saveMissing);
}

// page
Expand Down
31 changes: 2 additions & 29 deletions src/app/config/settings.base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import pkg from '../../package.json';
import { languages } from '../../../i18n.config';

// RCFile
const RCFILE = '.cncrc';
Expand Down Expand Up @@ -95,21 +96,6 @@ export default {
saveUninitialized: true
}
},
// Supported languages
supportedLngs: [
'en', // English (default)
'cs', // Czech
'de', // German
'es', // Spanish
'fr', // French
'hu', // Hungarian
'it', // Italian
'ja', // Japanese
'pt-br', // Portuguese (Brazil)
'ru', // Russian
'zh-cn', // Simplified Chinese
'zh-tw' // Traditional Chinese
],
siofu: { // SocketIOFileUploader
dir: './tmp/siofu'
},
Expand All @@ -131,20 +117,7 @@ export default {
// default namespace used if not passed to translation function
defaultNS: 'resource',

whitelist: [
'en', // English (default)
'cs', // Czech
'de', // German
'es', // Spanish
'fr', // French
'hu', // Hungarian
'it', // Italian
'ja', // Japanese
'pt-br', // Portuguese (Brazil)
'ru', // Russian
'zh-cn', // Simplified Chinese
'zh-tw' // Traditional Chinese
],
whitelist: languages,

// array of languages to preload
preload: [],
Expand Down
6 changes: 3 additions & 3 deletions src/app/config/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash';
import merge from 'lodash/merge';
import base from './settings.base';
import development from './settings.development';
import production from './settings.production';
Expand All @@ -7,9 +7,9 @@ const env = process.env.NODE_ENV || 'production'; // Ensure production environme
const settings = {};

if (env === 'development') {
_.merge(settings, base, development, { env: env });
merge(settings, base, development, { env: env });
} else {
_.merge(settings, base, production, { env: env });
merge(settings, base, production, { env: env });
}

export default settings;
16 changes: 2 additions & 14 deletions src/web/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,8 @@ const settings = {
// default namespace used if not passed to translation function
defaultNS: 'resource',

whitelist: [
'en', // English (default)
'cs', // Czech
'de', // German
'es', // Spanish
'fr', // French
'hu', // Hungarian
'it', // Italian
'ja', // Japanese
'pt-br', // Portuguese (Brazil)
'ru', // Russian
'zh-cn', // Simplified Chinese
'zh-tw' // Traditional Chinese
],
// @see webpack.config.i18n.js
whitelist: process.env.I18N.languages,

// array of languages to preload
preload: [],
Expand Down
7 changes: 5 additions & 2 deletions webpack.webconfig.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const HtmlWebpackPluginAddons = require('html-webpack-plugin-addons');
const nib = require('nib');
const stylusLoader = require('stylus-loader');
const baseConfig = require('./webpack.webconfig.base');
const languages = require('./webpack.webconfig.i18n').languages;
const languages = require('./i18n.config').languages;
const pkg = require('./package.json');

const timestamp = new Date().getTime();
Expand Down Expand Up @@ -48,7 +48,10 @@ const webpackConfig = Object.assign({}, baseConfig, {
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
NODE_ENV: JSON.stringify('development')
NODE_ENV: JSON.stringify('development'),
I18N: JSON.stringify({
languages: languages
})
}
}),
new webpack.HotModuleReplacementPlugin(),
Expand Down
7 changes: 5 additions & 2 deletions webpack.webconfig.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const HtmlWebpackPluginAddons = require('html-webpack-plugin-addons');
const nib = require('nib');
const stylusLoader = require('stylus-loader');
const baseConfig = require('./webpack.webconfig.base');
const languages = require('./webpack.webconfig.i18n').languages;
const languages = require('./i18n.config').languages;
const pkg = require('./package.json');

// Use publicPath for production
Expand Down Expand Up @@ -55,7 +55,10 @@ const webpackConfig = Object.assign({}, baseConfig, {
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
NODE_ENV: JSON.stringify('production')
NODE_ENV: JSON.stringify('production'),
I18N: JSON.stringify({
languages: languages
})
}
}),
new webpack.NoEmitOnErrorsPlugin(),
Expand Down

0 comments on commit 6b97583

Please sign in to comment.