Don't rely on Webpack for available languages
parent
edf59c4bb4
commit
bed0d4e232
|
@ -28,7 +28,7 @@ import { readdirSync, readFileSync } from 'fs';
|
||||||
import { join, sep } from 'path';
|
import { join, sep } from 'path';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { defaultPack, toSep, fromSep } from '../util/language_packs';
|
import { defaultPack, availablePacks, toSep, fromSep } from '../util/language_packs';
|
||||||
import snakeToCamel from '../util/snake_to_camel';
|
import snakeToCamel from '../util/snake_to_camel';
|
||||||
|
|
||||||
// Recursively get all keys in a i18n pack object fragment
|
// Recursively get all keys in a i18n pack object fragment
|
||||||
|
@ -150,10 +150,10 @@ const main = async () => {
|
||||||
// Output the pack results
|
// Output the pack results
|
||||||
if (warnings.length)
|
if (warnings.length)
|
||||||
for (const warning of warnings)
|
for (const warning of warnings)
|
||||||
console.log(` ${chalk.yellow('warning')} ${warning}`);
|
console.warn(` ${chalk.yellow('warning')} ${warning}`);
|
||||||
if (errors.length)
|
if (errors.length)
|
||||||
for (const error of errors)
|
for (const error of errors)
|
||||||
console.log(` ${chalk.red('error')} ${error}`);
|
console.error(` ${chalk.red('error')} ${error}`);
|
||||||
if (!errors.length && !warnings.length)
|
if (!errors.length && !warnings.length)
|
||||||
console.log(` ${chalk.green('No issues')}`);
|
console.log(` ${chalk.green('No issues')}`);
|
||||||
|
|
||||||
|
@ -164,6 +164,16 @@ const main = async () => {
|
||||||
console.log(chalk.reset());
|
console.log(chalk.reset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check available language packs
|
||||||
|
const packKeys = Object.keys(packs);
|
||||||
|
const missingPacks = packKeys.filter(x => !availablePacks.includes(x));
|
||||||
|
const extraPacks = availablePacks.filter(x => !packKeys.includes(x));
|
||||||
|
|
||||||
|
// Missing packs and extra packs are errors
|
||||||
|
missingPacks.forEach(pack => console.error(`${chalk.red('error')} Language pack \`${pack}\` not included in \`availablePacks\``));
|
||||||
|
extraPacks.forEach(pack => console.error(`${chalk.red('error')} Language pack \`${pack}\` included in \`availablePacks\` but not found`));
|
||||||
|
if (missingPacks.length || extraPacks.length) hadError = true;
|
||||||
|
|
||||||
// Exit 1 if we had errors
|
// Exit 1 if we had errors
|
||||||
if (hadError) process.exit(1);
|
if (hadError) process.exit(1);
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,12 +37,15 @@ export const toSep = (pack, sep) => pack
|
||||||
|
|
||||||
export const fromSep = (pack, sep) => pack.split(sep, 2)[0].toLowerCase() + (pack.split(sep, 2)[1] || '').toUpperCase();
|
export const fromSep = (pack, sep) => pack.split(sep, 2)[0].toLowerCase() + (pack.split(sep, 2)[1] || '').toUpperCase();
|
||||||
|
|
||||||
// Use webpack magic to get all the language packs we've bundled
|
// Export a static array of all language packs
|
||||||
// If not in a webpack context, return no packs
|
export const availablePacks = Object.freeze([
|
||||||
/* global __webpack_modules__ */
|
'de',
|
||||||
export const availablePacks = typeof __webpack_modules__ === 'undefined'
|
'en',
|
||||||
? []
|
'es',
|
||||||
: Object.keys(__webpack_modules__)
|
'fr',
|
||||||
.map(pack => pack.match(/i18n\/([^/]+)\/languages\.js$/))
|
'pl',
|
||||||
.filter(pack => pack !== null)
|
'ptBR',
|
||||||
.map(pack => fromSep(pack[1], '-'));
|
'ru',
|
||||||
|
'zhCN',
|
||||||
|
'zhTW',
|
||||||
|
]);
|
||||||
|
|
Loading…
Reference in New Issue