Skip to content

Commit

Permalink
feat(i18n): new internationalization system
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The file format for the i18n files has changed

You can now specify the language to use using `-l` and `jsonschema2md` will pick up the correct language configuration.
  • Loading branch information
trieloff committed Dec 11, 2019
1 parent dd18f3b commit 1a664de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 172 deletions.
11 changes: 10 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
iter, pipe, filter, map, obj,
} = require('ferrum');
const npath = require('path');
const { i18nConfig } = require('es2015-i18n-tag');
const traverse = require('./lib/traverseSchema');
const build = require('./lib/markdownBuilder');
const { writereadme, writemarkdown } = require('./lib/writeMarkdown');
Expand Down Expand Up @@ -81,10 +82,15 @@ const { argv } = yargs
.describe('link-*', 'Add this file as a link the explain the * attribute, e.g. --link-abstract=abstract.md')

.alias('i', 'i18n')
.describe('i', 'path to a locales folder with an en.json file in it. This file will be used for all text parts in all templates')
.describe('i', 'path to a locales folder with JSON files')
.default('i', nodepath.resolve(__dirname, 'lib', 'locales'))
.coerce('i', i => nodepath.resolve(i))

.alias('l', 'language')
.describe('l', 'the selected language')
.choices('l', ['en_US', 'de_DE'])
.default('l', 'en_US')

.alias('p', 'properties')
.array('p')
.describe('p', 'name of a custom property which should be also in the description of an element (may be used multiple times)')
Expand All @@ -103,6 +109,9 @@ const docs = pipe(
const schemaPath = argv.d;
const schemaExtension = argv.e;

// eslint-disable-next-line import/no-dynamic-require
i18nConfig(require(nodepath.resolve(argv.i, `${argv.l}.json`)));

const schemaloader = loader();

// list all schema files in the specified directory
Expand Down
6 changes: 6 additions & 0 deletions lib/locales/de_DE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"locales": "de_DE",
"translations": {
"${0} Schema": "${0} Schema"
}
}
171 changes: 0 additions & 171 deletions lib/locales/en.json

This file was deleted.

6 changes: 6 additions & 0 deletions lib/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"locales": "en_US",
"translations": {
"${0} Schema": "Schema: ${0}"
}
}

0 comments on commit 1a664de

Please sign in to comment.