Skip to content

Commit

Permalink
fix(i18n init): moved the i18n init part to the cli.js
Browse files Browse the repository at this point in the history
there was an bug in the init part of the i18n setup. It was moved to the cli to handle it in the
same way

fix #157
  • Loading branch information
COMLINE\Kunz committed Jul 30, 2019
1 parent 5fe7db2 commit 5e37d2d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
15 changes: 14 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var argv = require('optimist')
.argv;

const docs = _.fromPairs(_.toPairs(argv).filter(([ key, value ]) => { return key.startsWith('link-'); }).map(([ key, value ]) => { return [ key.substr(5), value ];}));
const i18n = require('i18n');

const logger = winston.createLogger({
level: 'info',
Expand Down Expand Up @@ -82,7 +83,6 @@ var schemaDir = argv.x === '-' ? '' : argv.x ? path.resolve(argv.x) : outDir;
var target = fs.statSync(schemaPath);
const readme = argv.n !== true;
const schemaExtension = argv.e || 'schema.json';

if (argv.s){
ajv.addMetaSchema(require(path.resolve(argv.s)));
}
Expand All @@ -102,6 +102,19 @@ if (argv.m) {
}
}
}
let i18nPath;
if (argv !== undefined && argv.i !== undefined){
i18nPath=path.resolve(argv.i) ;
} else {
i18nPath=path.resolve(path.join(__dirname, 'lib/locales'));
}
i18n.configure({
// setup some locales - other locales default to en silently
locales:[ 'en' ],
// where to store json files - defaults to './locales' relative to modules directory
directory: i18nPath,
defaultLocale: 'en'
});

logger.info('output directory: %s', outDir);
if (target.isDirectory()) {
Expand Down
13 changes: 0 additions & 13 deletions lib/markdownWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,7 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
};

outDir = outDir ? outDir : path.resolve(path.join('.', 'out'));
let i18nPath;
if (consoleArgs !== undefined && consoleArgs.i !== undefined){
i18nPath=path.resolve(consoleArgs.i) ;
} else {
i18nPath=path.resolve(path.join(__dirname, 'locales'));
}
console.log(filename);
i18n.configure({
// setup some locales - other locales default to en silently
locales:[ 'en' ],
// where to store json files - defaults to './locales' relative to modules directory
directory: i18nPath,
defaultLocale: 'en'
});
//console.log(dependencyMap);
// this structure allows us to have separate templates for each element. Instead of having
// one huge template, each block can be built individually
Expand Down
8 changes: 0 additions & 8 deletions lib/readmeWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ function directory(full, base) {
* @param {string} base - schema base directory
*/
const generateReadme = function(paths, schemas, out, base) {
let i18nPath=path.resolve('./lib/locales');
i18n.configure({
// setup some locales - other locales default to en silently
locales:[ 'en' ],
// where to store json files - defaults to './locales' relative to modules directory
directory: i18nPath,
defaultLocale: 'en'
});
const coreinfo = _.values(schemas).map(schema => {
return {
id: schema.jsonSchema.$id,
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/header.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ beforeEach(function() {
colors: true,
inline: true
}));
let i18nPath=path.resolve('./lib/locales');
let i18nPath=path.resolve(path.join(__dirname, '../../lib/locales'));
i18n.configure({
// setup some locales - other locales default to en silently
locales:[ 'en' ],
Expand Down

0 comments on commit 5e37d2d

Please sign in to comment.