From daa58a207ef51bf1ad820376bd9bcd13fc4455b5 Mon Sep 17 00:00:00 2001 From: Claymore1337 <31853210+Claymore1337@users.noreply.github.com> Date: Tue, 30 Jul 2019 11:37:28 +0200 Subject: [PATCH] feat(i18n): enable localization of all strings, provide en as default language fixes #143 --- README.md | 11 ++ cli.js | 6 +- lib/header.js | 24 +-- lib/locales/en.json | 171 +++++++++++++++++++ lib/markdownWriter.js | 40 +++-- lib/readmeWriter.js | 14 +- lib/schema.js | 4 +- package-lock.json | 259 +++++++++++++++++++++++++++-- package.json | 1 + spec/lib/header.spec.js | 10 ++ templates/md/array-type.ejs | 22 +-- templates/md/boolean-type.ejs | 2 +- templates/md/definitions.ejs | 4 +- templates/md/examples.ejs | 4 +- templates/md/header.ejs | 7 +- templates/md/innerSchema.ejs | 2 +- templates/md/join-type.ejs | 26 +-- templates/md/multiple-type.ejs | 4 +- templates/md/nested-properties.ejs | 4 +- templates/md/nested-property.ejs | 40 ++--- templates/md/null-type.ejs | 2 +- templates/md/number-type.ejs | 10 +- templates/md/object-type.ejs | 7 +- templates/md/pattern-property.ejs | 46 ++--- templates/md/properties.ejs | 14 +- templates/md/property.ejs | 50 +++--- templates/md/readme.ejs | 2 +- templates/md/string-type.ejs | 47 +++--- 28 files changed, 642 insertions(+), 191 deletions(-) create mode 100644 lib/locales/en.json diff --git a/README.md b/README.md index 8a3b1c8..35ac04a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,17 @@ $ jsonschema2md -d examples/schemas -o examples/docs -v 04 $ jsonschema2md -d examples/schemas -o examples/docs -v 06 ``` +## Text in Templates +Each text which is not provided by the JSON Schema is loaded from an i18n file. With i18n parameter you can change the location of the i18n folder and load your own text file. The folder must contain an locales folder and in this folder there should be an en.json file. + +```bash +# run against JSON Schema Draft 06 +$ jsonschema2md -d examples/schemas -o examples/docs -v 06 -i temp/myFiles +``` + + + + ## Using JSON Schema Markdown Tools from `npm` You can conveniently use the JSON Schema Markdown Tools from `npm`. This makes it possible to set up a conversion toolchain for your JSON Schema project that is driven entirely by `npm`. To do so, first define the dependency by adding this to your `"devDependencies"` section of `package.json` diff --git a/cli.js b/cli.js index b9f99ee..a8eb90c 100755 --- a/cli.js +++ b/cli.js @@ -49,6 +49,8 @@ var argv = require('optimist') throw 'Meta schema file "' + args.s + '" does not exist!'; } }) + .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') .argv; const docs = _.fromPairs(_.toPairs(argv).filter(([ key, value ]) => { return key.startsWith('link-'); }).map(([ key, value ]) => { return [ key.substr(5), value ];})); @@ -122,7 +124,7 @@ if (target.isDirectory()) { return Promise.reduce(files, readSchemaFile, schemaPathMap) .then(schemaMap => { logger.info('finished reading all *.%s files in %s, beginning processing….', schemaExtension, schemaPath); - return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, readme, docs); + return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, readme, docs, argv); }) .then(() => { logger.info('Processing complete.'); @@ -143,7 +145,7 @@ if (target.isDirectory()) { Schema.setAjv(ajv); Schema.setSchemaPathMap(schemaPathMap); logger.info('finished reading %s, beginning processing....', schemaPath); - return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, false, docs); + return Schema.process(schemaMap, schemaPath, outDir, schemaDir, metaElements, false, docs, argv); }) .then(() => { logger.info('Processing complete.'); diff --git a/lib/header.js b/lib/header.js index 1a944f5..4b2dc8f 100644 --- a/lib/header.js +++ b/lib/header.js @@ -6,6 +6,7 @@ */ const _ = require('lodash'); +const i18n = require('i18n'); const path = require('path'); function custom(schema) { @@ -22,11 +23,12 @@ function custom(schema) { function schemaProps(schema, schemaPath, filename) { return { // if there are definitions, but no properties - abstract: (schema.definitions !== undefined && _.keys(schema.properties).length === 0) ? 'Cannot be instantiated' : 'Can be instantiated', - extensible: (schema.definitions !== undefined || schema['meta:extensible'] === true) ? 'Yes' : 'No', - status: schema['meta:status'] !== undefined ? (schema['meta:status'].charAt(0).toUpperCase() + schema['meta:status'].slice(1)) : 'Experimental', - custom: custom(schema) ? 'Allowed' : 'Forbidden', + abstract: (schema.definitions !== undefined && _.keys(schema.properties).length === 0) ? i18n.__('header.tabel.abstractNo') : i18n.__('header.tabel.abstractYes'), + extensible: (schema.definitions !== undefined || schema['meta:extensible'] === true) ? i18n.__('header.tabel.extensibleYes') : i18n.__('header.tabel.extensibleNo'), + status: schema['meta:status'] !== undefined ? (schema['meta:status'].charAt(0).toUpperCase() + schema['meta:status'].slice(1)) : i18n.__('header.tabel.statusExperimental'), + custom: custom(schema) ? i18n.__('header.tabel.customPropertiesYes') : i18n.__('header.tabel.customPropertiesNo'), original: filename.substr(schemaPath.length).substr(1), + additionalProperties:schema.additionalProperties===false ? i18n.__('header.tabel.additionalPropertiesNo'): i18n.__('header.tabel.additionalPropertiesYes'), }; } @@ -99,13 +101,13 @@ function headers(schema, indir, filename, docs, outdir) { this.doclinks = docs ? docs : {}; this.myheaders = []; - this.myheaders.push(new Header('Abstract', link(indir, filename, this.doclinks['abstract']), props.abstract)); - this.myheaders.push(new Header('Extensible', link(indir, filename, this.doclinks['extensible']), props.extensible)); - this.myheaders.push(new Header('Status', link(indir, filename, this.doclinks['status']), props.status)); - this.myheaders.push(new Header('Identifiable', link(indir, filename, this.doclinks['id']), isIdentifiable(schema))); - this.myheaders.push(new Header('Custom Properties', link(indir, filename, this.doclinks['custom']), props.custom)); - this.myheaders.push(new Header('Additional Properties', link(indir, filename, this.doclinks['additional']), schema.additionalProperties===false ? 'Forbidden' : 'Permitted')); - this.myheaders.push(new Header('Defined In', undefined, props.original, path.basename(props.original))); + this.myheaders.push(new Header(i18n.__('header.tabel.abstract'), link(indir, filename, this.doclinks['abstract']), props.abstract)); + this.myheaders.push(new Header(i18n.__('header.tabel.extensible'), link(indir, filename, this.doclinks['extensible']), props.extensible)); + this.myheaders.push(new Header(i18n.__('header.tabel.status'), link(indir, filename, this.doclinks['status']), props.status)); + this.myheaders.push(new Header(i18n.__('header.tabel.identifiable'), link(indir, filename, this.doclinks['id']), isIdentifiable(schema))); + this.myheaders.push(new Header(i18n.__('header.tabel.customProperties'), link(indir, filename, this.doclinks['custom']), props.custom)); + this.myheaders.push(new Header(i18n.__('header.tabel.additionalProperties'), link(indir, filename, this.doclinks['additional']), props.additionalProperties)); + this.myheaders.push(new Header(i18n.__('header.tabel.definedIn'), undefined, props.original, path.basename(props.original))); this.render = function() { var buf = ''; diff --git a/lib/locales/en.json b/lib/locales/en.json new file mode 100644 index 0000000..2830115 --- /dev/null +++ b/lib/locales/en.json @@ -0,0 +1,171 @@ +{ + "header.titel": "Schema", + "header.hierarchy": "Schema Hierarchy", + "header.tabel.abstract": "Abstract", + "header.tabel.abstractYes": "Can be instantiated", + "header.tabel.abstractNo": "Cannot be instantiated", + "header.tabel.extensible": "Extensible", + "header.tabel.extensibleYes": "Yes", + "header.tabel.extensibleNo": "No", + "header.tabel.status": "Status", + "header.tabel.statusExperimental": "Experimental", + "header.tabel.identifiable": "Identifiable", + "header.tabel.customProperties": "Custom Properties", + "header.tabel.customPropertiesYes": "Allowed", + "header.tabel.customPropertiesNo": "Forbidden", + "header.tabel.additionalProperties": "Additional Properties", + "header.tabel.additionalPropertiesYes": "Permitted", + "header.tabel.additionalPropertiesNo": "Forbidden", + "header.tabel.definedIn": "Defined In", + "examples.example": "Example", + "examples.examples": "Examples", + "definitions.definitions": "Definitions", + "definitions.tabel.property": "Property", + "definitions.tabel.type": "Type", + "definitions.tabel.group": "Group", + "propertyIs": "is", + "propertyRequired": "**required**", + "propertyOptional": "optional", + "propertyType": "type:", + "propertyNestedArray": "(nested array)", + "propertyBetween": "between", + "propertyBetweenAnd": "and", + "propertyBetweenItems": "items in the array", + "propertyBetweenMaxItemsPrefix": "no more than", + "propertyBetweenMaxItemsSuffix": "items in the array", + "propertyBetweenMinItemsPrefix": "at least", + "propertyBetweenMinItemsSuffix": "items in the array", + "propertySchemaDefault": "default", + "propertySchemaDefinedIn": "defined in", + "propertySchemaDefinedSelf": "this schema", + "propertySchemaConst": "The value of this property **must** be equal to:", + "propertySchemaEnum": "The value of this property **must** be equal to one of the [known values below](#{{enum}}-known-values).", + "propertyHeaderType": "Type", + "propertyUnknownType": "Unknown type", + "propertyEnumKnownVaules": "Known Values", + "propertyEnum.tabel.value": "Value", + "propertyEnum.tabel.description": "Description", + "propertyExample": "Example", + "propertyExamples": "Examples", + "arrayTypeNested": "Nested array type:", + "arrayTypeArray": "Array type:", + "arrayTypeList": "All items must be of the type:", + "arrayTypeUnknownType": "Unknown type", + "booleanTypeNullabel": ", nullable", + "booleanTypeEmpty": " ", + "multitpleType.types": "Either one of:", + "multitpleType.none": "or `null`", + "joinTypeAny": "**Any** following *options* needs to be fulfilled.", + "joinTypeAll": "**All** of the following *requirements* need to be fulfilled.", + "joinTypeOne": "**One** of the following *conditions* need to be fulfilled.", + "joinTypeOption": "Option", + "joinTypeRequirement": "Requirement", + "joinTypeCondition": "Condition", + "innerSchemaDefined": "**Defined In:**", + "nestedProperties.tabel.property": "Property", + "nestedProperties.tabel.type": "Type", + "nestedProperties.tabel.required": "Required", + "nestedProperties.tabel.requiredYes": "**Required**", + "nestedProperties.tabel.requiredNo": "Optional", + "nestedProperties.tabel.default": "Default", + "nestedPropertyIs": "is", + "nestedPropertyRequired": "**required**", + "nestedPropertyOptinal": "optional", + "nestedPropertyType": "type:", + "nestedPropertyTypeNestedArray": "nested array", + "nestedPropertyItemsBetween": "between", + "nestedPropertyItemsAnd": "and", + "nestedPropertyItemsBetweenEnd": "items in the array", + "nestedPropertyItemsMax": "no more than", + "nestedPropertyItemsMaxEnd": "items in the array", + "nestedPropertyItemsMin": "at least", + "nestedPropertyItemsMinEnd": "items in the array", + "nestedPropertySchemaDefault": "default:", + "nestedPropertySchemaConst": "The value of this property **must** be equal to:", + "nestedPropertyHeaderType": "Type", + "nestedPropertyUnknownType": "Unknown type", + "nestedPropertySchemaEnum": "The value of this property **must** be equal to one of the [known values below](#{{enum}}-known-values).", + "nestedPropertyEnumKnownVaules": "Known Values", + "nestedPropertyEnum.tabel.value": "Value", + "nestedPropertyEnum.tabel.description": "Description", + "nestedPropertyExample": "Example", + "nestedPropertyExamples": "Examples", + "numberTypeExclusiveMinumum": "value must not be smaller or equal than:", + "numberTypeMinimum": "minimum value:", + "numberTypeExclusiveMaximum": "value must not be greater or equal than:", + "numberTypeMaximum": "maximum value:", + "numberTypeMultipleOf": "must be a multiple of", + "objectTypeObject": "object", + "objectTypeObjectFollowing": "with following properties:", + "patternPropertyPattern": "Pattern:", + "patternPropertyExpression": "Applies to all properties that match the regular expression", + "patternPropertyIsPropertyPattern": "is a property pattern", + "patternPropertyType": "type:", + "patternPropertyNestedArray": "(nested array):", + "patternPropertyBetween": "between", + "patternPropertyBetweenAnd": "and", + "patternPropertyBetweenItems": "items in the array", + "patternPropertyMaxItemsPrefix": "no more than", + "patternPropertyMaxItemsSuffix": "items in the array", + "patternPropertyMinItemsPrefix": "at least", + "patternPropertyMinItemsSuffix": "items in the array", + "patternPropertySchemaDefault": "default:", + "patternPropertySchemaDefinedIn": "defined in", + "patternPropertySchemaDefinedSelf": "this schema", + "patternPropertySchemaConst": "The value of this property **must** be equal to:", + "patternPropertySchemaEnum": "The value of this property **must** be equal to one of the [known values below](#{{enum}}-known-values).", + "patternPropertyHeaderPattern": "Pattern", + "patternPropertyHeaderType": "Type", + "patternPropertyUnknownType": "Unknown type", + "patternPropertyEnumPattern": "Pattern", + "patternPropertyEnumKnownVaules": "Known Values", + "patternPropertyEnum.tabel.value": "Value", + "patternPropertyEnum.tabel.description": "Description", + "patternPropertyExample": "Example", + "patternPropertyPatternExamples": "Pattern", + "patternPropertyExamples": "Examples", + "propertiesTitel": "Properties", + "properties.tabel.property": "Property", + "properties.tabel.type": "Type", + "properties.tabel.required": "Required", + "properties.tabel.nullable": "Nullable", + "properties.tabel.default": "Default", + "properties.tabel.definedBy": "Defined by", + "propertiesRequired": "**Required**", + "propertiesOptional": "Optional", + "propertiesNullableYes": "Yes", + "propertiesNullableNo": "No", + "propertiesSchema": "(this schema)", + "propertiesPattern": "Pattern", + "propertiesAny": "any", + "propertiesAdditional": "Additional", + "propertiesAdditionalYes": "Yes", + "propertiesPatternAdditionalText": "this schema *allows* additional properties", + "readmeHead": "Readme", + "stringTypeUri": "format: `uri` – Uniformous Resource Identifier (according to [RFC3986](http://tools.ietf.org/html/rfc3986))", + "stringTypeDateTime": "format: `date-time` – date and time (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))", + "stringTypeEmail": "format: `email` – email address (according to [RFC 5322, section 3.4.1](https://tools.ietf.org/html/rfc5322))", + "stringTypeIPv4": "format: `ipv4` – IP (v4) address (according to [RFC 2673, section 3.2](https://tools.ietf.org/html/rfc2673))", + "stringTypeIPv6": "format: `ipv6` – IP (v6) address (according to [RFC 4291, section 2.2](https://tools.ietf.org/html/rfc4291))", + "stringTypeDate": "format: `date` – date, without time (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))", + "stringTypeTime": "format: `time` – time, without date (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))", + "stringTypeIdnEmail": "format: `idn-email` – international email address (according to [RFC 6531](https://tools.ietf.org/html/rfc6531))", + "stringTypeIdnHostname": "format: `idn-hostname` – Internationalized Domain Name (according to [RFC 5890, section 2.3.2.3](https://tools.ietf.org/html/rfc5890))", + "stringTypeUriReference": "format: `uri-reference` – URI Reference (according to [RFC3986](https://tools.ietf.org/html/rfc3986))", + "stringTypeIRI": "format: `iri` – Internationalized Resource Identifier (according to [RFC3987](https://tools.ietf.org/html/rfc3987))", + "stringTypeIRIReference": "format: `iri-reference` – IRI Reference (according to [RFC3987](https://tools.ietf.org/html/rfc3987))", + "stringTypeURITemplate": "format: `uri-template` – URI Template (according to [RFC6570](https://tools.ietf.org/html/rfc6570))", + "stringTypeJSONPointer": "format: `json-pointer` – JSON Pointer (according to [RFC 6901, section 5](https://tools.ietf.org/html/rfc6901))", + "stringTypeRegex": "format: `regex` – Regular Expression (according to [ECMA 262](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf))", + "stringTypeRelativeJsonPointer": "format: `relative-json-pointer` – Relative JSON Pointer (according to [Relative JSON Pointer](http://tools.ietf.org/html/draft-handrews-relative-json-pointer-00))", + "stringTypeHostname": "format: `hostname` – Domain Name (according to [RFC 1034, section 3.1](https://tools.ietf.org/html/rfc1034))", + "stringTypeMinimum": "minimum length:", + "stringTypeMinimumCharacters": "characters", + "stringTypeMaximum": "maximum length:", + "stringTypeMaximumCharacters": "characters", + "stringTypePattern": "All instances must conform to this regular expression ", + "stringTypePatternExampleUndefined": "(test examples [here](https://regexr.com/?expression={{pattern}} )):", + "stringTypePatternExampleString": "((test example: [{{example}}](https://regexr.com/?expression={{pattern}}&text={{text}})):", + "stringTypePatternExampleNotString": "* test example: [{{example}}](https://regexr.com/?expression={{pattern}}&text={{text}})", + "nullType": "This property can only have the value `null`." +} \ No newline at end of file diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index 3632ebd..c2e95e9 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ - +const i18n = require('i18n'); const writeFile = require('./writeFiles'); const prettyMarkdown = require('./prettyMarkdown'); var Promise=require('bluebird'); @@ -162,7 +162,7 @@ function ejsRender(template, ctx) { //return JSON.stringify(obj, null, 2); } -const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap, docs) { +const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap, docs, consoleArgs) { var ctx = { schema: schema, _: _, @@ -171,21 +171,33 @@ 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=consoleArgs.i ; + } else { + i18nPath=__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 let multi = [ [ 'frontmatter.ejs', { meta: schema.metaElements } ], [ 'header.ejs', { + i18n: i18n, schema: schema, dependencies: flatten(dependencyMap), table: headers(schema, schemaPath, filename, docs, outDir).render() } ], //[ 'divider.ejs', null ], //[ 'topSchema.ejs', ctx ], - [ 'examples.ejs', { examples: stringifyExamples(schema.examples), title: schema.title } ] + [ 'examples.ejs', { i18n: i18n, examples: stringifyExamples(schema.examples), title: schema.title } ] ]; const required = []; //to store required of whole schema, even those in definitions @@ -218,7 +230,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen props: requiredProperties(abstract, required), title: schema.title, id: schema.$id, - propertiesSlugs:propertiesSlugs + propertiesSlugs:propertiesSlugs, + i18n: i18n } ]); for (let i=0; i<_.keys(abstract).length;i++) { const name = _.keys(abstract).sort()[i]; @@ -228,7 +241,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen ejs: ejsRender, examples: stringifyExamples(abstract[name]['examples']), schema: simpletype(abstract[name]), - nameSlug: propertiesSlugs[name] + nameSlug: propertiesSlugs[name], + i18n: i18n } ]); } } @@ -243,7 +257,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen pprops: _.mapValues(schema.patternProperties, simpletype), title: schema.title, additional: schema.additionalProperties, - propertiesSlugs: propertiesSlugs + propertiesSlugs: propertiesSlugs, + i18n: i18n } ]); //regular properties for (let i=0; i<_.keys(schema.properties).length;i++) { @@ -254,7 +269,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen examples: stringifyExamples(schema.properties[name]['examples']), ejs: ejsRender, schema: simpletype(schema.properties[name]), - nameSlug: propertiesSlugs[name] + nameSlug: propertiesSlugs[name], + i18n: i18n } ]); } } @@ -267,7 +283,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen name: name, examples: stringifyExamples(schema.patternProperties[name]['examples']), ejs: ejsRender, - schema: simpletype(schema.patternProperties[name]) } ]); + schema: simpletype(schema.patternProperties[name]), + i18n: i18n } ]); } } @@ -280,7 +297,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen multi.push( [ 'join-type.ejs', { ejs: ejsRender, schemas: simpletype(joinType), - schema: simpletype(schema) } ]); + schema: simpletype(schema), + i18n: i18n } ]); } } //find definitions that contain properties that are not part of the main schema diff --git a/lib/readmeWriter.js b/lib/readmeWriter.js index a657dad..acf4641 100644 --- a/lib/readmeWriter.js +++ b/lib/readmeWriter.js @@ -13,6 +13,7 @@ var ejs = require('ejs'); var path = require('path'); const pejs = Promise.promisifyAll(ejs); var validUrl = require('valid-url'); +const i18n = require('i18n'); function relativePath(full, base) { if (full.indexOf(base)===0) { @@ -34,6 +35,14 @@ 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, @@ -42,18 +51,19 @@ const generateReadme = function(paths, schemas, out, base) { status: schema.jsonSchema['meta:status'] !== undefined ? (schema.jsonSchema['meta:status'].charAt(0).toUpperCase() + schema.jsonSchema['meta:status'].slice(1)) : 'Unknown', relative: relativePath(schema.filePath, base), dir: directory(schema.filePath, base), + i18n:i18n, }; }); const ctx = { paths: paths, + i18n:i18n, _: _, validUrl: validUrl, schemas: schemas, core: coreinfo, groups: _.groupBy(coreinfo, key => { return key.dir; }) }; - - return pejs.renderFileAsync(path.join(__dirname, '../templates/md/readme.ejs'), ctx, { debug: false }).then(str => { + return pejs.renderFileAsync(path.join(__dirname, '../templates/md/readme.ejs'), ctx, { debug: false }, i18n).then(str => { console.log('Writing README'); return writeFile(out, 'README.md', prettyMarkdown(str)); }).then(out => { diff --git a/lib/schema.js b/lib/schema.js index e3390dc..580ceaa 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -422,7 +422,7 @@ Schema.setSchemaPathMap=function(schemaMap){ * @param {boolean} readme - generate a README.md directory listing * @param {map} docs - a map of documentation links for headers */ -Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme, docs) { +Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements, readme, docs, consoleArgs) { smap=schemaMap; let keys = Object.keys(schemaMap); return Promise.mapSeries(keys, schemaKey => { @@ -448,7 +448,7 @@ Schema.process = function(schemaMap, schemaPath, docDir, schemaDir, metaElements return { mSchema:mSchema, wSchema:allSchema, dep:wmap }; }); }).then(object => { - const outputTasks = [ markdownWriter(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep, docs) ]; + const outputTasks = [ markdownWriter(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep, docs, consoleArgs) ]; if (schemaDir !== '') { outputTasks.push(schemaWriter(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir)); } diff --git a/package-lock.json b/package-lock.json index 2cbbc65..cb4a277 100644 --- a/package-lock.json +++ b/package-lock.json @@ -436,8 +436,7 @@ "abbrev": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.9.tgz", - "integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=", - "dev": true + "integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=" }, "acorn": { "version": "6.2.1", @@ -481,6 +480,36 @@ "uri-js": "^4.2.2" } }, + "ambi": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/ambi/-/ambi-2.5.0.tgz", + "integrity": "sha1-fI43K+SIkRV+fOoBy2+RQ9H3QiA=", + "requires": { + "editions": "^1.1.1", + "typechecker": "^4.3.0" + }, + "dependencies": { + "typechecker": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/typechecker/-/typechecker-4.7.0.tgz", + "integrity": "sha512-4LHc1KMNJ6NDGO+dSM/yNfZQRtp8NN7psYrPHUblD62Dvkwsp3VShsbM78kOgpcmMkRTgvwdKOTjctS+uMllgQ==", + "requires": { + "editions": "^2.1.0" + }, + "dependencies": { + "editions": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/editions/-/editions-2.1.3.tgz", + "integrity": "sha512-xDZyVm0A4nLgMNWVVLJvcwMjI80ShiH/27RyLiCnW1L273TcJIA25C4pwJ33AWV01OX6UriP35Xu+lH4S7HWQw==", + "requires": { + "errlop": "^1.1.1", + "semver": "^5.6.0" + } + } + } + } + } + }, "amdefine": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", @@ -635,8 +664,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base": { "version": "0.11.2", @@ -714,7 +742,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1252,8 +1279,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "conventional-changelog-angular": { "version": "5.0.3", @@ -1394,6 +1420,11 @@ "which": "^1.2.9" } }, + "csextends": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/csextends/-/csextends-1.2.0.tgz", + "integrity": "sha512-S/8k1bDTJIwuGgQYmsRoE+8P+ohV32WhQ0l4zqrc0XDdxOhjQQD7/wTZwCzoZX53jSX3V/qwjT+OkPTxWQcmjg==" + }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -1819,6 +1850,19 @@ "readable-stream": "^2.0.2" } }, + "eachr": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/eachr/-/eachr-2.0.4.tgz", + "integrity": "sha1-Rm98qhBwj2EFCeMsgHqv5X/BIr8=", + "requires": { + "typechecker": "^2.0.8" + } + }, + "editions": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/editions/-/editions-1.3.4.tgz", + "integrity": "sha512-gzao+mxnYDzIysXKMQi/+M1mjy/rjestjg6OPoYTtI+3Izp23oiGZitsl9lPDPiTGXbcSIk1iJWhliSaglxnUg==" + }, "ejs": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/ejs/-/ejs-2.6.1.tgz", @@ -1867,6 +1911,25 @@ "resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz", "integrity": "sha1-kT3YML7xHpagOcA41BMGBOujf4g=" }, + "errlop": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/errlop/-/errlop-1.1.1.tgz", + "integrity": "sha512-WX7QjiPHhsny7/PQvrhS5VMizXXKoKCS3udaBp8gjlARdbn+XmK300eKBAAN0hGyRaTCtRpOaxK+xFVPUJ3zkw==", + "requires": { + "editions": "^2.1.2" + }, + "dependencies": { + "editions": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/editions/-/editions-2.1.3.tgz", + "integrity": "sha512-xDZyVm0A4nLgMNWVVLJvcwMjI80ShiH/27RyLiCnW1L273TcJIA25C4pwJ33AWV01OX6UriP35Xu+lH4S7HWQw==", + "requires": { + "errlop": "^1.1.1", + "semver": "^5.6.0" + } + } + } + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -2215,6 +2278,21 @@ } } }, + "extendr": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/extendr/-/extendr-2.1.0.tgz", + "integrity": "sha1-MBqgu+pWX00tyPVw8qImEahSe1Y=", + "requires": { + "typechecker": "~2.0.1" + }, + "dependencies": { + "typechecker": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/typechecker/-/typechecker-2.0.8.tgz", + "integrity": "sha1-6D2oS7ZMWEzLNFg4V2xAsDN9uC4=" + } + } + }, "external-editor": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", @@ -2291,6 +2369,21 @@ } } }, + "extract-opts": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/extract-opts/-/extract-opts-2.2.0.tgz", + "integrity": "sha1-H6KOunNSxttID4hc63GkaBC+bX0=", + "requires": { + "typechecker": "~2.0.1" + }, + "dependencies": { + "typechecker": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/typechecker/-/typechecker-2.0.8.tgz", + "integrity": "sha1-6D2oS7ZMWEzLNFg4V2xAsDN9uC4=" + } + } + }, "fast-deep-equal": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", @@ -2863,6 +2956,19 @@ } } }, + "i18n": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/i18n/-/i18n-0.8.3.tgz", + "integrity": "sha1-LYzxwkciYCwgQdAbpq5eqlE4jw4=", + "requires": { + "debug": "*", + "make-plural": "^3.0.3", + "math-interval-parser": "^1.1.0", + "messageformat": "^0.3.1", + "mustache": "*", + "sprintf-js": ">=1.0.3" + } + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -2878,6 +2984,20 @@ "integrity": "sha1-dQ49tYYgh7RzfrrIIH/9HvJ7Jfw=", "dev": true }, + "ignorefs": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/ignorefs/-/ignorefs-1.2.0.tgz", + "integrity": "sha1-2ln7hYl25KXkNwLM0fKC/byeV1Y=", + "requires": { + "editions": "^1.3.3", + "ignorepatterns": "^1.1.0" + } + }, + "ignorepatterns": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ignorepatterns/-/ignorepatterns-1.1.0.tgz", + "integrity": "sha1-rI9DbyI5td+2bV8NOpBKh6xnzF4=" + }, "import-fresh": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", @@ -2920,7 +3040,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -3947,6 +4066,22 @@ "integrity": "sha1-yHk1iR++sNunU3kT/Gb0af7p1mI=", "dev": true }, + "make-plural": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/make-plural/-/make-plural-3.0.6.tgz", + "integrity": "sha1-IDOgO6wpC487uRJY9lud9+iwHKc=", + "requires": { + "minimist": "^1.2.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "optional": true + } + } + }, "manage-path": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/manage-path/-/manage-path-2.0.0.tgz", @@ -4003,6 +4138,14 @@ "supports-hyperlinks": "^1.0.1" } }, + "math-interval-parser": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-interval-parser/-/math-interval-parser-1.1.0.tgz", + "integrity": "sha1-2+2lsGsySZc8bfYXD94jhvCv2JM=", + "requires": { + "xregexp": "^2.0.0" + } + }, "mem": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/mem/-/mem-4.2.0.tgz", @@ -4075,6 +4218,37 @@ "integrity": "sha1-fumdvWm7ZIFoklPwGEiKG5ArDtU=", "dev": true }, + "messageformat": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/messageformat/-/messageformat-0.3.1.tgz", + "integrity": "sha1-5Y//gkXps5cXmeW0PbWLPpQX9aI=", + "requires": { + "async": "~1.5.2", + "glob": "~6.0.4", + "make-plural": "~3.0.3", + "nopt": "~3.0.6", + "watchr": "~2.4.13" + }, + "dependencies": { + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" + }, + "glob": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", + "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", + "requires": { + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "2 || 3", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + } + } + }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -4112,7 +4286,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4173,6 +4346,11 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, + "mustache": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-3.0.1.tgz", + "integrity": "sha512-jFI/4UVRsRYdUbuDTKT7KzfOp7FiD5WzYmmwNwXyUVypC0xjoTL78Fqc0jHUPIvvGD+6DQSPHIt1NE7D1ArsqA==" + }, "mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", @@ -4241,7 +4419,6 @@ "version": "3.0.6", "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", "integrity": "sha1-xkZdvwirzU2zWTF/eaxopkayj/k=", - "dev": true, "requires": { "abbrev": "1" } @@ -7849,7 +8026,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -8103,8 +8279,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-is-inside": { "version": "1.0.2", @@ -8499,12 +8674,30 @@ "ret": "~0.1.10" } }, + "safefs": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/safefs/-/safefs-3.2.2.tgz", + "integrity": "sha1-gXDBRE1wOOCMrqBaN0+uL6NJ4Vw=", + "requires": { + "graceful-fs": "*" + } + }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo=", "dev": true }, + "scandirectory": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/scandirectory/-/scandirectory-2.5.0.tgz", + "integrity": "sha1-bOA/VKCQtmjjy+2/IO354xBZPnI=", + "requires": { + "ignorefs": "^1.0.0", + "safefs": "^3.1.2", + "taskgroup": "^4.0.5" + } + }, "semantic-release": { "version": "15.13.3", "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-15.13.3.tgz", @@ -8559,8 +8752,7 @@ "semver": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha1-fnQlb7qknHWqfHogXMInmcrIAAQ=", - "dev": true + "integrity": "sha1-fnQlb7qknHWqfHogXMInmcrIAAQ=" }, "semver-compare": { "version": "1.0.0", @@ -9085,6 +9277,15 @@ } } }, + "taskgroup": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/taskgroup/-/taskgroup-4.3.1.tgz", + "integrity": "sha1-feGT/r12gnPEV3MElwJNUSwnkVo=", + "requires": { + "ambi": "^2.2.0", + "csextends": "^1.0.3" + } + }, "text-extensions": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/text-extensions/-/text-extensions-1.9.0.tgz", @@ -9207,6 +9408,11 @@ "prelude-ls": "~1.1.2" } }, + "typechecker": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/typechecker/-/typechecker-2.1.0.tgz", + "integrity": "sha1-0cIJOlT/ihn1jP+HfuqlTyJC04M=" + }, "uglify-js": { "version": "3.4.9", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz", @@ -9375,6 +9581,21 @@ "spdx-expression-parse": "^3.0.0" } }, + "watchr": { + "version": "2.4.13", + "resolved": "https://registry.npmjs.org/watchr/-/watchr-2.4.13.tgz", + "integrity": "sha1-10hHu01vkPYf4sdPn2hmKqDgdgE=", + "requires": { + "eachr": "^2.0.2", + "extendr": "^2.1.0", + "extract-opts": "^2.2.0", + "ignorefs": "^1.0.0", + "safefs": "^3.1.2", + "scandirectory": "^2.5.0", + "taskgroup": "^4.2.0", + "typechecker": "^2.0.8" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -9480,8 +9701,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "1.0.3", @@ -9497,6 +9717,11 @@ "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz", "integrity": "sha1-1QH5ezvbQDr4757MIFcxh6rawOk=" }, + "xregexp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-2.0.0.tgz", + "integrity": "sha1-UqY+VsoLhKfzpfPWGHLxJq16WUM=" + }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", diff --git a/package.json b/package.json index 4904b5d..e61e326 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "bluebird": "^3.5.5", "ejs": "^2.4.2", "github-slugger": "^1.2.1", + "i18n": "^0.8.3", "jasmine-xml-reporter": "^1.2.1", "json-pointer": "^0.6.0", "lodash": "^4.5.0", diff --git a/spec/lib/header.spec.js b/spec/lib/header.spec.js index e48ece2..c253f40 100644 --- a/spec/lib/header.spec.js +++ b/spec/lib/header.spec.js @@ -1,10 +1,20 @@ const { Header, headers } = require('../../lib/header'); +const i18n = require('i18n'); +var path = require('path'); beforeEach(function() { jasmine.addMatchers(require('jasmine-diff')(jasmine, { colors: true, inline: true })); + 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' + }); }); describe('Header Integration Test', () => { diff --git a/templates/md/array-type.ejs b/templates/md/array-type.ejs index 12d2883..8c028a6 100644 --- a/templates/md/array-type.ejs +++ b/templates/md/array-type.ejs @@ -5,29 +5,29 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> <% if (schema.items!==undefined&&schema.items.type==="array") { %> -Nested array type: <%=schema.items.simpletype %> +<%=i18n.__('arrayTypeNested')%> <%=schema.items.simpletype %> <% } else if (nested===undefined||nested===false) { %> -Array type: <%=schema.simpletype %> +<%=i18n.__('arrayTypeArray')%> <%=schema.simpletype %> <% } %> <% if (schema.items!==undefined) { %> <% if (!(schema.items!==undefined&&schema.items.type==="array")) { %> -All items must be of the type:<% } +<%=i18n.__('arrayTypeList')%><% } if (schema.items.type==="string") { - %><%- include("string-type",{schema:schema.items,_:_}) + %><%- include("string-type",{schema:schema.items,_:_, i18n:i18n}) %><% } else if (schema.items.type==="number"||schema.items.type==="integer") { - %><%- include("number-type",{schema:schema.items,_:_}) + %><%- include("number-type",{schema:schema.items,_:_, i18n:i18n}) %><% } else if (schema.items.type==="boolean") { - %><%- include("boolean-type",{schema:schema.items,_:_}) + %><%- include("boolean-type",{schema:schema.items,_:_, i18n:i18n}) %><% } else if (schema.items.type==="object") { - %><%- include("object-type",{schema:schema.items,_:_}) + %><%- include("object-type",{schema:schema.items,_:_, i18n:i18n}) %><% } else if (schema.items.type==="array") { - %><%- include("array-type",{schema:schema.items,_:_, nested:true}) + %><%- include("array-type",{schema:schema.items,_:_, nested:true, i18n:i18n}) %><% } else if (schema.items.anyOf!==undefined || schema.items.allOf!==undefined || schema.items.oneOf!==undefined) { - %><%- include("join-type",{schema:schema.items,_:_,schemas:schema.items.anyOf || schema.items.allOf || schema.items.oneOf, ejs:ejs}) %> + %><%- include("join-type",{schema:schema.items,_:_,schemas:schema.items.anyOf || schema.items.allOf || schema.items.oneOf, ejs:ejs, i18n:i18n}) %> %><% } else if (schema.items.$ref!==undefined) { - %><%- include("referenced-type",{schema:schema.items,_:_}) %> + %><%- include("referenced-type",{schema:schema.items,_:_, i18n:i18n}) %> <% } else { %> -Unknown type `<%= schema.items.type %>`. +<%=i18n.__('arrayTypeUnknownType')%> `<%= schema.items.type %>`. ```json diff --git a/templates/md/boolean-type.ejs b/templates/md/boolean-type.ejs index 85a9b07..8707bc0 100644 --- a/templates/md/boolean-type.ejs +++ b/templates/md/boolean-type.ejs @@ -5,4 +5,4 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -`<%=schema.type %>`<%=schema.nullable ? ", nullable" : "" %> +`<%=schema.type %>` <% if (schema.nullable) { %> <%=i18n.__('booleanTypeNullabel')%> <% }else{%> <%=i18n.__('booleanTypeEmpty')%> <% } %> diff --git a/templates/md/definitions.ejs b/templates/md/definitions.ejs index 333bd9a..77416c3 100644 --- a/templates/md/definitions.ejs +++ b/templates/md/definitions.ejs @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -# <%=title %> Definitions +# <%=title %> <%=i18n.__('definitions.definitions')%> -| Property | Type | Group | +| <%=i18n.__('definitions.tabel.property')%> | <%=i18n.__('definitions.tabel.type')%> | <%=i18n.__('definitions.tabel.group')%> | |----------|------|-------| <% _.keys(props).sort().forEach(property => { const schema = props[property]; %> diff --git a/templates/md/examples.ejs b/templates/md/examples.ejs index 76c997d..e84af11 100644 --- a/templates/md/examples.ejs +++ b/templates/md/examples.ejs @@ -4,13 +4,13 @@ * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %><% if (examples && examples.length == 1) { %> -## <%=title %> Example +## <%=title %> <%=i18n.__('examples.example')%> ```json <%- examples[0] %> ``` <% } else if (examples && examples.length > 1) { %> -## <%=title %> Examples +## <%=title %> <%=i18n.__('examples.examples')%> <% _.forEach(examples, example => { %> ```json diff --git a/templates/md/header.ejs b/templates/md/header.ejs index 1b75864..f3cbcbe 100644 --- a/templates/md/header.ejs +++ b/templates/md/header.ejs @@ -4,8 +4,7 @@ * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -# <%=schema.title %> Schema - +# <%=schema.title %> <%=i18n.__('header.titel')%> ``` <%= schema.$id %> @@ -20,11 +19,11 @@ <%= table %> <% if (dependencies.length > 0) { %> -## Schema Hierarchy +## <%=i18n.__('header.hierarchy')%> * <%=schema.title %> `<%= schema.$id %>` <% _.forEach(dependencies, ({$linkVal, $linkPath, $id}) => { %> * [<%= $linkVal %>](<%=$linkPath %>) `<%= $id %>` <% }); %> -<% } %> +<% } %> \ No newline at end of file diff --git a/templates/md/innerSchema.ejs b/templates/md/innerSchema.ejs index 413a7a2..22ce499 100644 --- a/templates/md/innerSchema.ejs +++ b/templates/md/innerSchema.ejs @@ -15,7 +15,7 @@ function displayStringIfExists(object,key,str){ return str; } %><%- HelperFunctions.displayType(nschema,1) %><%- HelperFunctions.displayFormat(nschema)%> -<% if(nschema["$oSchema"]) { %>* **Defined In:** <%- HelperFunctions.createLink(nschema.$oSchema.$linkVal,nschema.$oSchema.$linkPath) %> +<% if(nschema["$oSchema"]) { %>* <%=i18n.__('innerSchemaDefined')%> <%- HelperFunctions.createLink(nschema.$oSchema.$linkVal,nschema.$oSchema.$linkPath) %> <% }%><%- displayIfExists(nschema,"description") %><%- HelperFunctions.getSimpleKeywords(nschema) %><%- displayStringIfExists(nschema,"properties"," \n**"+ sName.charAt(0).toUpperCase() + sName.slice(1) + " Properties**") %><% if(nschema.properties){ var resetVal=HelperFunctions.nestLevel; Object.keys(nschema.properties).map((prop) => { var value= nschema.properties[prop]; HelperFunctions.nestLevel= resetVal+1;%><%- " \n"+Array(HelperFunctions.nestLevel * 4).join(" ") %><% if(value["title"]) diff --git a/templates/md/join-type.ejs b/templates/md/join-type.ejs index c834edc..0d38738 100644 --- a/templates/md/join-type.ejs +++ b/templates/md/join-type.ejs @@ -6,37 +6,37 @@ */ %> <% if (schema.anyOf!==undefined) { %> -**Any** following *options* needs to be fulfilled. +<%=i18n.__('joinTypeAny')%> <% } else if (schema.allOf!==undefined) { %> -**All** of the following *requirements* need to be fulfilled. +<%=i18n.__('joinTypeAll')%> <% } else if (schema.oneOf!==undefined) { %> -**One** of the following *conditions* need to be fulfilled. +<%=i18n.__('joinTypeOne')%> <% } %> <% for (let i=0;i<schemas.length;i++) { -%> <% if (schema.anyOf!==undefined) { %> -#### Option <%= i+1 %> +#### <%=i18n.__('joinTypeOption')%> <%= i+1 %> <% } else if (schema.allOf!==undefined) { %> -#### Requirement <%= i+1 %> +#### <%=i18n.__('joinTypeRequirement')%> <%= i+1 %> <% } else if (schema.oneOf!==undefined) { %> -#### Condition <%= i+1 %> +#### <%=i18n.__('joinTypeCondition')%> <%= i+1 %> <% } %> <% if (schemas[i].type==="string") { %> -<%- include("string-type",{schema:schemas[i],_:_}) %> +<%- include("string-type",{schema:schemas[i],_:_,i18n:i18n}) %> <% } else if (schemas[i].type==="number"||schemas[i].type==="integer") { %> -<%- include("number-type",{schema:schemas[i],_:_}) %> +<%- include("number-type",{schema:schemas[i],_:_,i18n:i18n}) %> <% } else if (schemas[i].type==="boolean") { %> -<%- include("boolean-type",{schema:schemas[i],_:_}) %> +<%- include("boolean-type",{schema:schemas[i],_:_,i18n:i18n}) %> <% } else if (schemas[i].type==="array") { %> -<%- include("array-type",{schema:schemas[i],_:_,nested:false,ejs:ejs}) %> +<%- include("array-type",{schema:schemas[i],_:_,nested:false,ejs:ejs,i18n:i18n}) %> <% } else if (schemas[i].type==="object") { %> -<%- include("object-type",{schema:schemas[i],_:_, nameSlug:_}) %> +<%- include("object-type",{schema:schemas[i],_:_, nameSlug:_,i18n:i18n}) %> <% } else if (schemas[i].$ref!==undefined) { %> -<%- include("referenced-type",{schema:schemas[i],_:_}) %> +<%- include("referenced-type",{schema:schemas[i],_:_,i18n:i18n}) %> <% } else if (schemas[i].anyOf!==undefined||schemas[i].allOf!==undefined) { %> -<%- include("join-type",{schema:schemas[i],_:_,schemas:schemas[i].anyOf || schemas[i].allOf ,ejs:ejs}) %> +<%- include("join-type",{schema:schemas[i],_:_,schemas:schemas[i].anyOf || schemas[i].allOf ,ejs:ejs,i18n:i18n}) %> <% } else { %> <% } %> <% } %> diff --git a/templates/md/multiple-type.ejs b/templates/md/multiple-type.ejs index 57accdf..c84f71a 100644 --- a/templates/md/multiple-type.ejs +++ b/templates/md/multiple-type.ejs @@ -5,9 +5,9 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -Either one of: +<%=i18n.__('multitpleType.types')%> <% _.forEach(schema.type, (t) => { %> * `<%= t %>` <% }); %><% if (schema.nullable) { %> - * or `null` + * <%=i18n.__('multitpleType.none')%> <% } %> \ No newline at end of file diff --git a/templates/md/nested-properties.ejs b/templates/md/nested-properties.ejs index 8899c1b..569dea2 100644 --- a/templates/md/nested-properties.ejs +++ b/templates/md/nested-properties.ejs @@ -7,11 +7,11 @@ <% const hasDefault = _.keys(props).filter(property => _.has(props, property + '.default')).length > 0; %> -| Property | Type | Required |<% if(hasDefault) { %> Default |<% } %> +| <%=i18n.__('nestedProperties.tabel.property')%> | <%=i18n.__('nestedProperties.tabel.type')%> | <%=i18n.__('nestedProperties.tabel.required')%> |<% if(hasDefault) { %> <%=i18n.__('nestedProperties.tabel.default')%> |<% } %> |----------|------|----------|<% if(hasDefault) { %>---------|<% } %> <% _.keys(props).sort().forEach(property => { const schema = props[property]; %> -| `<%= property %>`| <%= schema.type %> | <%= (Array.isArray(outer.required)&&outer.required.indexOf(property)>=0) ? "**Required**" : "Optional" %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> +| `<%= property %>`| <%= schema.type %> | <% if(Array.isArray(outer.required)&&outer.required.indexOf(property)>=0) { %> <%=i18n.__('nestedProperties.tabel.requiredYes')%> <% } else { %> <%=i18n.__('nestedProperties.tabel.requiredNo')%> <% } %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% }); %> \ No newline at end of file diff --git a/templates/md/nested-property.ejs b/templates/md/nested-property.ejs index c39ea4d..e245721 100644 --- a/templates/md/nested-property.ejs +++ b/templates/md/nested-property.ejs @@ -20,17 +20,17 @@ `<%=name %>` -* is <% if (required) { %>**required**<% } else { %>optional<% } %> -* type: <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> (nested array)<% } %><% if (schema.type==='array') { -%> -<% if (schema.maxItems!==undefined&&schema.minItems!==undefined) { %>* between `<%=schema.minItems %>` and `<%=schema.maxItems %>` items in the array<% } -else if (schema.maxItems!==undefined ) { %>* no more than `<%=schema.maxItems %>` items in the array<% } -else if (schema.minItems!==undefined ) { %>* at least `<%=schema.minItems %>` items in the array<% } %> +* <%=i18n.__('nestedPropertyIs')%> <% if (required) { %><%=i18n.__('nestedPropertyRequired')%><% } else { %><%=i18n.__('nestedPropertyOptinal')%><% } %> +* <%=i18n.__('nestedPropertyType')%> <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> <%=i18n.__('nestedPropertyTypeNestedArray')%><% } %><% if (schema.type==='array') { -%> +<% if (schema.maxItems!==undefined&&schema.minItems!==undefined) { %>* <%=i18n.__('nestedPropertyItemsBetween')%> `<%=schema.minItems %>` <%=i18n.__('nestedPropertyItemsAnd')%> `<%=schema.maxItems %>` <%=i18n.__('nestedPropertyItemsBetweenEnd')%><% } +else if (schema.maxItems!==undefined ) { %>* <%=i18n.__('nestedPropertyItemsMax')%> `<%=schema.maxItems %>` <%=i18n.__('nestedPropertyItemsMaxEnd')%><% } +else if (schema.minItems!==undefined ) { %>* <%=i18n.__('nestedPropertyItemsMin')%> `<%=schema.minItems %>` <%=i18n.__('nestedPropertyItemsMinEnd')%><% } %> <% } %><% if (schema.default!==undefined) { %> -* default: `<%- JSON.stringify(schema.default) %>` +* <%=i18n.__('nestedPropertySchemaDefault')%> `<%- JSON.stringify(schema.default) %>` <% } %> <% if (schema.const!==undefined) { %> -The value of this property **must** be equal to: +<%=i18n.__('nestedPropertySchemaConst')%> ```json @@ -38,27 +38,27 @@ The value of this property **must** be equal to: ``` <% } else if (schema.enum!==undefined) { %> -The value of this property **must** be equal to one of the [known values below](#<%=nameSlug %>-known-values). +<%=i18n.__('nestedPropertySchemaEnum',{enum:nameSlug})%> <% } else { %> -##### <%=name %> Type +##### <%=name %> <%=i18n.__('nestedPropertyHeaderType')%> <% if (schema.type==="string") { %> -<%- include("string-type",{schema:schema,_:_}) %> +<%- include("string-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="number"||schema.type==="integer") { %> -<%- include("number-type",{schema:schema,_:_}) %> +<%- include("number-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="boolean") { %> -<%- include("boolean-type",{schema:schema,_:_}) %> +<%- include("boolean-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="object") { %> -<%- include("object-type",{schema:schema,_:_}) %> +<%- include("object-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="array") { %> -<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs}) %> +<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs,i18n:i18n}) %> <% } else if (schema.$ref!==undefined) { %> <%- include("referenced-type",{schema:schema,_:_}) %> <% } else if (schema.anyOf!==undefined || schema.allOf!==undefined || schema.oneOf!==undefined) { %> -<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs}) %> +<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs,i18n:i18n}) %> <% } else { %> -Unknown type `<%= schema.type %>`. +<%=i18n.__('nestedPropertyUnknownType')%> `<%= schema.type %>`. ```json @@ -68,9 +68,9 @@ Unknown type `<%= schema.type %>`. <% }} %> <% if (schema.enum!==undefined||schema["meta:enum"]!==undefined) { %> -##### <%=name %> Known Values +##### <%=name %> <%=i18n.__('nestedPropertyEnumKnownVaules')%> -| Value | Description | +| <%=i18n.__('nestedPropertyEnum.tabel.value')%> | <%=i18n.__('nestedPropertyEnum.tabel.description')%> | |-------|-------------| <% _.forIn(schema["meta:enum"], (value, key, object) => { %> | `<%= key %>` | <%= value %> | @@ -80,14 +80,14 @@ Unknown type `<%= schema.type %>`. <% if (examples && examples.length == 1) { %> -##### <%=name %> Example +##### <%=name %> <%=i18n.__('nestedPropertyExample')%> ```json <%- examples[0] %> ``` <% } else if (examples && examples.length > 1) { %> -##### <%=name %> Examples +##### <%=name %> <%=i18n.__('nestedPropertyExamples')%> <% _.forEach(examples, example => { %> ```json diff --git a/templates/md/null-type.ejs b/templates/md/null-type.ejs index f65aa15..e9330ae 100644 --- a/templates/md/null-type.ejs +++ b/templates/md/null-type.ejs @@ -7,4 +7,4 @@ `null` -This property can only have the value `null`. \ No newline at end of file +<%=i18n.__('nullType')%> \ No newline at end of file diff --git a/templates/md/number-type.ejs b/templates/md/number-type.ejs index dcc2d57..772949e 100644 --- a/templates/md/number-type.ejs +++ b/templates/md/number-type.ejs @@ -9,12 +9,12 @@ <% if(schema.exclusiveMinumum!==undefined) { - %>* value must not be smaller or equal than: `<%=schema.exclusiveMinumum %>`<% + %>* <%=i18n.__('numberTypeExclusiveMinumum')%> `<%=schema.exclusiveMinumum %>`<% } else if(schema.minimum!==undefined) { - %>* minimum value: `<%=schema.minimum %>`<% } %> + %>* <%=i18n.__('numberTypeMinimum')%> `<%=schema.minimum %>`<% } %> <% if(schema.exclusiveMaximum!==undefined) { - %>* value must not be greater or equal than: `<%=schema.exclusiveMaximum %>`<% + %>* <%=i18n.__('numberTypeExclusiveMaximum')%> `<%=schema.exclusiveMaximum %>`<% } if(schema.maximum!==undefined) { - %>* maximum value: `<%=schema.maximum %>`<% } %> + %>* <%=i18n.__('numberTypeMaximum')%> `<%=schema.maximum %>`<% } %> <% if(schema.multipleOf!==undefined) { - %>* must be a multiple of `<%=schema.multipleOf %>`<% } %> + %>* <%=i18n.__('numberTypeMultipleOf')%> `<%=schema.multipleOf %>`<% } %> diff --git a/templates/md/object-type.ejs b/templates/md/object-type.ejs index 7b79942..08c6412 100644 --- a/templates/md/object-type.ejs +++ b/templates/md/object-type.ejs @@ -5,9 +5,9 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -`object`<%=schema.nullable ? ", nullable," : "" %> with following properties: +`<%=i18n.__('objectTypeObject')%>`<%=schema.nullable ? ", nullable," : "" %> <%=i18n.__('objectTypeObjectFollowing')%> -<%- include("nested-properties",{outer:schema,props: schema.properties,_:_, nested:true}) %> +<%- include("nested-properties",{outer:schema,props: schema.properties,_:_, nested:true,i18n:i18n}) %> <% _.keys(schema.properties).sort().forEach(property => { const inner = schema.properties[property]; @@ -21,7 +21,8 @@ schema: inner, required: required, examples: inner.examples, - nameSlug:nameSlug + nameSlug:nameSlug, + i18n:i18n }) %> <% diff --git a/templates/md/pattern-property.ejs b/templates/md/pattern-property.ejs index e98c577..9e2a241 100644 --- a/templates/md/pattern-property.ejs +++ b/templates/md/pattern-property.ejs @@ -5,9 +5,9 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -## Pattern: `<%=name %>` +## <%=i18n.__('patternPropertyPattern')%> `<%=name %>` -Applies to all properties that match the regular expression `<%=name %>` +<%=i18n.__('patternPropertyExpression')%> `<%=name %>` <% if (schema.title) { %>### <%= schema.title %><% } %> @@ -18,18 +18,18 @@ Applies to all properties that match the regular expression `<%=name %>` `<%=name %>` -* is a property pattern -* type: <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> (nested array)<% } %><% if (schema.type==='array') { -%> -<% if (schema.maxItems!==undefined&&schema.minItems!==undefined) { %>* between `<%=schema.minItems %>` and `<%=schema.maxItems %>` items in the array<% } -else if (schema.maxItems!==undefined ) { %>* no more than `<%=schema.maxItems %>` items in the array<% } -else if (schema.minItems!==undefined ) { %>* at least `<%=schema.minItems %>` items in the array<% } %> +* <%=i18n.__('patternPropertyIsPropertyPattern')%> +* <%=i18n.__('patternPropertyType')%> <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> <%=i18n.__('patternPropertyNestedArray')%><% } %><% if (schema.type==='array') { -%> +<% if (schema.maxItems!==undefined&&schema.minItems!==undefined) { %>* <%=i18n.__('patternPropertyBetween')%> `<%=schema.minItems %>` <%=i18n.__('patternPropertyBetweenAnd')%> `<%=schema.maxItems %>` <%=i18n.__('nestedPropertyEnumKnownVaules')%><% } +else if (schema.maxItems!==undefined ) { %>* <%=i18n.__('patternPropertyMaxItemsPrefix')%> `<%=schema.maxItems %>` <%=i18n.__('patternPropertyMaxItemsSuffix')%><% } +else if (schema.minItems!==undefined ) { %>* <%=i18n.__('patternPropertyMinItemsPrefix')%> `<%=schema.minItems %>` <%=i18n.__('patternPropertyMinItemsSuffix')%><% } %> <% } %><% if (schema.default!==undefined) { %> -* default: `<%- JSON.stringify(schema.default) %>` +* <%=i18n.__('patternPropertySchemaDefault')%> `<%- JSON.stringify(schema.default) %>` <% } %> -* defined in <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= name %>)<% } else { %>this schema<% } %> +* <%=i18n.__('patternPropertySchemaDefinedIn')%> <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= name %>)<% } else { %><%=i18n.__('patternPropertySchemaDefinedSelf')%><% } %> <% if (schema.const!==undefined) { %> -The value of this property **must** be equal to: +<%=i18n.__('patternPropertySchemaConst')%> ```json @@ -37,25 +37,25 @@ The value of this property **must** be equal to: ``` <% } else if (schema.enum!==undefined) { %> -The value of this properties with this pattern **must** be equal to one of the [known values below](#<%=name %>-known-values). +<%=i18n.__('propertySchemaEnum',{enum:name})%> <% } else { %> -### Pattern <%=name %> Type +### <%=i18n.__('patternPropertyHeaderPattern')%> <%=name %> <%=i18n.__('patternPropertyHeaderType')%> <% if (schema.type==="string") { %> -<%- include("string-type",{schema:schema,_:_}) %> +<%- include("string-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="number"||schema.type==="integer") { %> -<%- include("number-type",{schema:schema,_:_}) %> +<%- include("number-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="boolean") { %> -<%- include("boolean-type",{schema:schema,_:_}) %> +<%- include("boolean-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="array") { %> -<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs}) %> +<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs,i18n:i18n}) %> <% } else if (schema.$ref!==undefined) { %> -<%- include("referenced-type",{schema:schema,_:_}) %> +<%- include("referenced-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.anyOf!==undefined || schema.allOf!==undefined || schema.oneOf!==undefined) { %> -<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs}) %> +<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs,i18n:i18n}) %> <% } else { %> -Unknown type `<%= schema.type %>`. +<%=i18n.__('patternPropertyUnknownType')%> `<%= schema.type %>`. ```json @@ -65,9 +65,9 @@ Unknown type `<%= schema.type %>`. <% }} %> <% if (schema.enum!==undefined||schema["meta:enum"]!==undefined) { %> -### Pattern <%=name %> Known Values +### <%=i18n.__('patternPropertyEnumPattern')%> <%=name %> <%=i18n.__('patternPropertyEnumKnownVaules')%> -| Value | Description | +| <%=i18n.__('patternPropertyEnum.tabel.value')%> | <%=i18n.__('patternPropertyEnum.tabel.description')%> | |-------|-------------| <% _.forIn(schema["meta:enum"], (value, key, object) => { %> | `<%= key %>` | <%= value %> | @@ -77,14 +77,14 @@ Unknown type `<%= schema.type %>`. <% if (examples && examples.length == 1) { %> -### <%=name %> Example +### <%=name %> <%=i18n.__('patternPropertyExample')%> ```json <%- examples[0] %> ``` <% } else if (examples && examples.length > 1) { %> -### Pattern <%=name %> Examples +### <%=i18n.__('patternPropertyPatternExamples')%> <%=name %> <%=i18n.__('patternPropertyExamples')%> <% _.forEach(examples, example => { %> ```json diff --git a/templates/md/properties.ejs b/templates/md/properties.ejs index 73cdec1..3ef1be0 100644 --- a/templates/md/properties.ejs +++ b/templates/md/properties.ejs @@ -4,30 +4,30 @@ * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -# <%=title %> Properties +# <%=title %> <%=i18n.__('propertiesTitel')%> <% const hasDefault = _.keys(props).filter(property => _.has(props, property + '.default')).length > 0; %> -| Property | Type | Required | Nullable |<% if(hasDefault) { %> Default |<% } %> Defined by | +| <%=i18n.__('properties.tabel.property')%> | <%=i18n.__('properties.tabel.type')%> | <%=i18n.__('properties.tabel.required')%> | <%=i18n.__('properties.tabel.nullable')%> |<% if(hasDefault) { %> <%=i18n.__('properties.tabel.default')%> |<% } %> <%=i18n.__('properties.tabel.definedBy')%> |----------|------|----------|----------|<% if(hasDefault) { %>---------|<% } %>------------| <% _.keys(props).sort().forEach(property => { const schema = props[property]; %> -| [<%= property %>](#<%= propertiesSlugs[property] %>) | <%= schema.simpletype %> | <%= schema.isrequired === true ? "**Required**" : "Optional" %> | <%= schema.nullable === true ? "Yes" : "No" %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% +| [<%= property %>](#<%= propertiesSlugs[property] %>) | <%= schema.simpletype %> | <% if (schema.isrequired) { %> <%=i18n.__('propertiesRequired')%> <% }else{%> <%=i18n.__('propertiesOptional')%> <% } %> | <% if (schema.nullable) { %> <%=i18n.__('propertiesNullableYes')%> <% }else{%> <%=i18n.__('propertiesNullableNo')%> <% } %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= propertiesSlugs[property] %>)<% } else { - %><%= title %> (this schema)<% } %> | + %><%= title %> <%=i18n.__('propertiesSchema')%><% } %> | <% }); %><% _.keys(pprops).forEach(property => { const schema = pprops[property]; %> -| `<%= property.replace(':', '') %>` | <%= schema.simpletype %> | Pattern | <%= schema.nullable === true ? "Yes" : "No" %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% +| `<%= property.replace(':', '') %>` | <%= schema.simpletype %> | <%=i18n.__('propertiesPattern')%> | <% if (schema.nullable) { %> <%=i18n.__('propertiesNullableYes')%> <% }else{%> <%=i18n.__('propertiesNullableNo')%> <% } %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= property.replace(':', '').toLowerCase() %>)<% } else { - %><%= title %> (this schema)<% } %> | + %><%= title %> <%=i18n.__('propertiesSchema')%><% } %> | <% }); %><% if (additional!==false||additional===undefined) { %> -| `*` | any | Additional | Yes | this schema *allows* additional properties | +| `*` | <%=i18n.__('propertiesAny')%> | <%=i18n.__('propertiesAdditional')%> | <%=i18n.__('propertiesAdditionalYes')%> | <%=i18n.__('propertiesPatternAdditionalText')%> | <% } %> \ No newline at end of file diff --git a/templates/md/property.ejs b/templates/md/property.ejs index 45c56b7..3bbc8ce 100644 --- a/templates/md/property.ejs +++ b/templates/md/property.ejs @@ -18,23 +18,23 @@ `<%=name %>` - -* is <% if (required) { %>**required**<% } else { %>optional<% } %> -* type: <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> (nested array)<% } %> +* <%=i18n.__('propertyIs')%> <% if (required) { %> <%=i18n.__('propertyRequired')%><% } else { %><%=i18n.__('propertyOptional')%><% } %> +* <%=i18n.__('propertyType')%> <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> <%=i18n.__('propertyNestedArray')%><% } %> <% if (schema.type==='array') { %><% if (schema.maxItems!==undefined&&schema.minItems!==undefined) { %> -* between `<%=schema.minItems %>` and `<%=schema.maxItems %>` items in the array +* <%=i18n.__('propertyBetween')%> `<%=schema.minItems %>` <%=i18n.__('propertyBetweenAnd')%> `<%=schema.maxItems %>` <%=i18n.__('propertyBetweenItems')%> <% } else if (schema.maxItems!==undefined) { %> -* no more than `<%=schema.maxItems %>` items in the array +* <%=i18n.__('propertyBetweenMaxItemsPrefix')%> `<%=schema.maxItems %>` <%=i18n.__('propertyBetweenMaxItemsSuffix')%> <% } else if (schema.minItems!==undefined) { %> -* at least `<%=schema.minItems %>` items in the array<% } %> +* <%=i18n.__('propertyBetweenMinItemsPrefix')%> `<%=schema.minItems %>` <%=i18n.__('propertyBetweenMinItemsSuffix')%><% } %> <% } -%> <% if (schema.default!==undefined) { %> -* default: `<%- JSON.stringify(schema.default) %>` +* <%=i18n.__('propertySchemaDefault')%>: `<%- JSON.stringify(schema.default) %>` <% } -%> -* defined in <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= nameSlug %>)<% } else { %>this schema<% } %> +* <%=i18n.__('propertySchemaDefinedIn')%> <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= nameSlug %>)<% } else { %><%=i18n.__('propertySchemaDefinedSelf')%><% } %> <% if (schema.const!==undefined) { %> -The value of this property **must** be equal to: +<%=i18n.__('propertySchemaConst')%> + ```json @@ -42,31 +42,31 @@ The value of this property **must** be equal to: ``` <% } else if (schema.enum!==undefined) { %> -The value of this property **must** be equal to one of the [known values below](#<%=nameSlug %>-known-values). +<%=i18n.__('propertySchemaEnum',{enum:nameSlug})%> <% } else { %> -### <%=name %> Type +### <%=name %> <%=i18n.__('propertyHeaderType')%> <% if (schema.type==="string") { %> -<%- include("string-type",{schema:schema,_:_}) %> +<%- include("string-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="number"||schema.type==="integer") { %> -<%- include("number-type",{schema:schema,_:_}) %> +<%- include("number-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="null") { %> -<%- include("null-type",{schema:schema,_:_}) %> +<%- include("null-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="boolean") { %> -<%- include("boolean-type",{schema:schema,_:_}) %> +<%- include("boolean-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.type==="object") { %> -<%- include("object-type",{schema:schema,_:_,nameSlug:nameSlug}) %> +<%- include("object-type",{schema:schema,_:_,nameSlug:nameSlug,i18n:i18n}) %> <% } else if (schema.type==="array") { %> -<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs}) %> +<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs,i18n:i18n}) %> <% } else if (schema.$ref!==undefined) { %> -<%- include("referenced-type",{schema:schema,_:_}) %> +<%- include("referenced-type",{schema:schema,_:_,i18n:i18n}) %> <% } else if (schema.anyOf!==undefined || schema.allOf!==undefined || schema.oneOf!==undefined) { %> -<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs}) %> +<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs,i18n:i18n}) %> <% } else if (schema.simpletype==="multiple") { %> -<%- include("multiple-type",{schema:schema,_:_}) %> +<%- include("multiple-type",{schema:schema,_:_,i18n:i18n}) %> <% } else { %> -Unknown type `<%= schema.type %>`. +<%=i18n.__('propertyUnknownType')%> `<%= schema.type %>`. ```json @@ -76,9 +76,9 @@ Unknown type `<%= schema.type %>`. <% }} %> <% if (schema.enum!==undefined||schema["meta:enum"]!==undefined) { %> -### <%=name %> Known Values +### <%=name %> <%=i18n.__('propertyEnumKnownVaules')%> -| Value | Description | +| <%=i18n.__('propertyEnum.tabel.value')%> | <%=i18n.__('propertyEnum.tabel.description')%> | |-------|-------------| <% _.forIn(schema["meta:enum"], (value, key, object) => { %> | `<%= key %>` | <%= value %> | @@ -88,14 +88,14 @@ Unknown type `<%= schema.type %>`. <% if (examples && examples.length == 1) { %> -### <%=name %> Example +### <%=name %> <%=i18n.__('propertyExample')%> ```json <%- examples[0] %> ``` <% } else if (examples && examples.length > 1) { %> -### <%=name %> Examples +### <%=name %> <%=i18n.__('propertyExamples')%> <% _.forEach(examples, example => { %> ```json diff --git a/templates/md/readme.ejs b/templates/md/readme.ejs index 0e8ecae..8531ff7 100644 --- a/templates/md/readme.ejs +++ b/templates/md/readme.ejs @@ -5,7 +5,7 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> - # Readme + # <%=i18n.__('readmeHead')%> <% _.forIn(groups, (schemas, group) => { %> diff --git a/templates/md/string-type.ejs b/templates/md/string-type.ejs index 6edcbdf..6282948 100644 --- a/templates/md/string-type.ejs +++ b/templates/md/string-type.ejs @@ -9,31 +9,31 @@ <% - if (schema.format==="uri") { %>* format: `uri` – Uniformous Resource Identifier (according to [RFC3986](http://tools.ietf.org/html/rfc3986))<% } -else if (schema.format==="date-time") { %>* format: `date-time` – date and time (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))<% } -else if (schema.format==="email") { %>* format: `email` – email address (according to [RFC 5322, section 3.4.1](https://tools.ietf.org/html/rfc5322))<% } -else if (schema.format==="ipv4") { %>* format: `ipv4` – IP (v4) address (according to [RFC 2673, section 3.2](https://tools.ietf.org/html/rfc2673))<% } -else if (schema.format==="ipv6") { %>* format: `ipv6` – IP (v6) address (according to [RFC 4291, section 2.2](https://tools.ietf.org/html/rfc4291))<% } -else if (schema.format==="date") { %>* format: `date` – date, without time (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))<% } -else if (schema.format==="time") { %>* format: `time` – time, without date (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))<% } -else if (schema.format==="idn-email") { %>* format: `idn-email` – international email address (according to [RFC 6531](https://tools.ietf.org/html/rfc6531))<% } -else if (schema.format==="idn-hostname") { %>* format: `idn-hostname` – Internationalized Domain Name (according to [RFC 5890, section 2.3.2.3](https://tools.ietf.org/html/rfc5890))<% } -else if (schema.format==="uri-reference") { %>* format: `uri-reference` – URI Reference (according to [RFC3986](https://tools.ietf.org/html/rfc3986))<% } -else if (schema.format==="iri") { %>* format: `iri` – Internationalized Resource Identifier (according to [RFC3987](https://tools.ietf.org/html/rfc3987))<% } -else if (schema.format==="iri-reference") { %>* format: `iri-reference` – IRI Reference (according to [RFC3987](https://tools.ietf.org/html/rfc3987))<% } -else if (schema.format==="uri-template") { %>* format: `uri-template` – URI Template (according to [RFC6570](https://tools.ietf.org/html/rfc6570))<% } -else if (schema.format==="json-pointer") { %>* format: `json-pointer` – JSON Pointer (according to [RFC 6901, section 5](https://tools.ietf.org/html/rfc6901))<% } -else if (schema.format==="regex") { %>* format: `regex` – Regular Expression (according to [ECMA 262](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf))<% } -else if (schema.format==="relative-json-pointer") { %>* format: `relative-json-pointer` – Relative JSON Pointer (according to [Relative JSON Pointer](http://tools.ietf.org/html/draft-handrews-relative-json-pointer-00))<% } -else if (schema.format==="hostname") { %>* format: `hostname` – Domain Name (according to [RFC 1034, section 3.1](https://tools.ietf.org/html/rfc1034))<% } %> -<% if(schema.minLength) { %>* minimum length: <%=schema.minLength %> characters<% } %> -<% if(schema.maxLength) { %>* maximum length: <%=schema.maxLength %> characters<% } %> + if (schema.format==="uri") { %>* <%=i18n.__('stringTypeUri')%><% } +else if (schema.format==="date-time") { %>* <%=i18n.__('stringTypeDateTime')%><% } +else if (schema.format==="email") { %>* <%=i18n.__('stringTypeEmail')%><% } +else if (schema.format==="ipv4") { %>* <%=i18n.__('stringTypeIPv4')%><% } +else if (schema.format==="ipv6") { %>* <%=i18n.__('stringTypeIPv6')%><% } +else if (schema.format==="date") { %>* <%=i18n.__('stringTypeDate')%><% } +else if (schema.format==="time") { %>* <%=i18n.__('stringTypeTime')%><% } +else if (schema.format==="idn-email") { %>* <%=i18n.__('stringTypeIdnEmail')%><% } +else if (schema.format==="idn-hostname") { %>* <%=i18n.__('stringTypeIdnHostname')%><% } +else if (schema.format==="uri-reference") { %>* <%=i18n.__('stringTypeUriReference')%><% } +else if (schema.format==="iri") { %>* <%=i18n.__('stringTypeIRI')%><% } +else if (schema.format==="iri-reference") { %>* <%=i18n.__('stringTypeIRIReference')%><% } +else if (schema.format==="uri-template") { %>* <%=i18n.__('stringTypeURITemplate')%><% } +else if (schema.format==="json-pointer") { %>* <%=i18n.__('stringTypeJSONPointer')%><% } +else if (schema.format==="regex") { %>* <%=i18n.__('stringTypeRegex')%><% } +else if (schema.format==="relative-json-pointer") { %>* <%=i18n.__('stringTypeRelativeJsonPointer')%><% } +else if (schema.format==="hostname") { %>* <%=i18n.__('stringTypeHostname')%><% } %> +<% if(schema.minLength) { %>* <%=i18n.__('stringTypeMinimum')%> <%=schema.minLength %> <%=i18n.__('stringTypeMinimumCharacters')%><% } %> +<% if(schema.maxLength) { %>* <%=i18n.__('stringTypeMaximum')%> <%=schema.maxLength %> <%=i18n.__('stringTypeMaximumCharacters')%><% } %> <% if(schema.pattern) { %> -All instances must conform to this regular expression +<%=i18n.__('stringTypePattern')%> <% if(schema['examples']===undefined) { %> -(test examples [here](https://regexr.com/?expression=<%- encodeURIComponent(schema.pattern) %>)): +<%=i18n.__('stringTypePatternExampleUndefined',{pattern:encodeURIComponent(schema.pattern)})%> <% } else if((typeof schema['examples'])==="string") { %> -(test example: [<%= schema['examples']%>](https://regexr.com/?expression=<%- encodeURIComponent(schema.pattern) %>&text=<%- encodeURIComponent(schema['examples']) %>)): +<%=i18n.__('stringTypePatternExampleString',{example:schema['examples'],pattern:encodeURIComponent(schema.pattern),text:encodeURIComponent(schema['examples'])})%> <% } %> ```regex <%- schema.pattern %> @@ -41,7 +41,8 @@ All instances must conform to this regular expression <% if (schema['examples']!==undefined&&(typeof schema['examples'])!=="string") { for (let i=0;i<schema['examples'].length;i++) { %> -* test example: [<%= schema['examples'][i] %>](https://regexr.com/?expression=<%- encodeURIComponent(schema.pattern) %>&text=<%- encodeURIComponent(schema['examples'][i]) %>)<% } +<%=i18n.__('stringTypePatternExampleNotString',{example:schema['examples'][i],pattern:encodeURIComponent(schema.pattern),text:encodeURIComponent(schema['examples'][i])})%> +<% } } %> <% } %> \ No newline at end of file -- GitLab