diff --git a/package.json b/package.json index e5f5b07..f011335 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "trace": "^3.1.1" }, "dependencies": { + "i18n": "^0.15.1", "thought-plugin-jsdoc": "2" }, "scripts": { diff --git a/packages/bootprint-openapi/handlebars/helpers.js b/packages/bootprint-openapi/handlebars/helpers.js index 840db7f..cc7cf53 100644 --- a/packages/bootprint-openapi/handlebars/helpers.js +++ b/packages/bootprint-openapi/handlebars/helpers.js @@ -1,11 +1,27 @@ const _ = require('lodash') const highlight = require('highlight.js') +const i18n = require('i18n') +const handlebars = require('handlebars') +const path = require('path') + +i18n.configure({ + directory: path.join(__dirname, 'i18'), // Path to the directory containing language files + defaultLocale: 'ru', // Default language + queryParameter: 'lang', // Query parameter to specify the language (e.g., ?lang=ru) + cookie: 'language' // Cookie name to store the language preference +}) + +// Set the default language +i18n.setLocale('en') // todo: get from params highlight.configure({ useBR: true }) module.exports = { + i18n: function(key) { + return new handlebars.SafeString(i18n.__(key)) + }, 'swagger--collection-format': function(value, paramName) { return { csv: 'comma separated (`' + paramName + '=aaa,bbb`)', diff --git a/packages/bootprint-openapi/handlebars/i18/en.json b/packages/bootprint-openapi/handlebars/i18/en.json new file mode 100644 index 0000000..50436b2 --- /dev/null +++ b/packages/bootprint-openapi/handlebars/i18/en.json @@ -0,0 +1,21 @@ +{ + "baseURL": "Base URL", + "version": "Version", + "requestFormat": "Default request format", + "responseFormat": "Default response format", + "requestType": "Request Type:", + "protocolUsedObjects": "Schema definitions", + "scenarios": "Tags", + "descriptionOfParameters": "Parameter definitions", + "messages": "Paths", + "defaultFormat": "Uses default", + "descriptionOfResponse": "Response definitions", + "defaultContentType": "Uses default content-types", + "security": "Security", + "path": "Path", + "operations": "Operations", + "description": "Description", + "summary": "Summary", + "scenario": "Tag", + "operation": "operation" +} \ No newline at end of file diff --git a/packages/bootprint-openapi/handlebars/i18/ru.json b/packages/bootprint-openapi/handlebars/i18/ru.json new file mode 100644 index 0000000..d571660 --- /dev/null +++ b/packages/bootprint-openapi/handlebars/i18/ru.json @@ -0,0 +1,21 @@ +{ + "baseURL": "Базовый URL", + "version": "Версия", + "requestFormat": "Формат запросов по умолчанию", + "responseFormat": "Формат ответов по умолчанию", + "requestType": "Тип запросов:", + "protocolUsedObjects": "Используемые в протоколе объекты", + "scenarios": "Сценарии", + "descriptionOfParameters": "Описание параметров", + "messages": "Сообщения", + "defaultFormat": "Формат по умолчанию", + "descriptionOfResponse": "Описание ответа", + "defaultContentType": "Content-type по умолчанию", + "security": "Безопасность", + "path": "Путь", + "operations": "Сообщение", + "description": "Описание", + "summary": "Сводка", + "scenario": "Сценарий", + "operation": "operation" +} \ No newline at end of file diff --git a/packages/bootprint-openapi/handlebars/partials/base/body.hbs b/packages/bootprint-openapi/handlebars/partials/base/body.hbs index e9eb6bc..ead9989 100644 --- a/packages/bootprint-openapi/handlebars/partials/base/body.hbs +++ b/packages/bootprint-openapi/handlebars/partials/base/body.hbs @@ -5,26 +5,26 @@ --}}

{{info.title}}

- {{#if basePath}}Base URL: {{basePath}},{{/if}} - Version: {{info.version}}{{#if externalDocs}}, {{>swagger/externalDocs}}{{/if}} + {{#if basePath}}{{i18n "baseURL"}} {{basePath}},{{/if}} + {{i18n "version"}}: {{info.version}}{{#if externalDocs}}, {{>swagger/externalDocs}}{{/if}}

{{md info.description}}

{{#if consumes}}
- Default request content-types: + {{i18n "requestFormat"}} (content-type): {{#each consumes}}{{.}}{{#unless @last}}, {{/unless}}{{/each}}
{{/if}} {{#if produces}}
- Default response content-types: + {{i18n "responseFormat"}} (content-type): {{#each produces}}{{.}}{{#unless @last}}, {{/unless}}{{/each}}
{{/if}}
- Schemes: + {{i18n "requestType"}} {{#each schemes}}{{.}}{{#unless @last}}, {{/unless}}{{/each}}
diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/definitions.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/definitions.hbs index 9d38c41..f31238e 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/definitions.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/definitions.hbs @@ -5,7 +5,7 @@ --}} {{#if definitions}} -

Schema definitions

+

{{i18n "protocolUsedObjects"}}

{{#eachSorted definitions}} {{>swagger/model model=. title=@key anchor="/definitions" }} diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/operation.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/operation.hbs index b7868b3..cd6abcd 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/operation.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/operation.hbs @@ -10,7 +10,7 @@
{{md summary stripParagraph="true"}}

{{toUpperCase method}} {{path}}

{{#if tags}} - Tags: + {{i18n "scenarios"}}: {{#each tags}} {{.}}{{#unless @last}}, {{/unless}} {{/each}} diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/parameterDefinitions.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/parameterDefinitions.hbs index 502718b..9a4c0bd 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/parameterDefinitions.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/parameterDefinitions.hbs @@ -4,7 +4,7 @@ @api public --}} {{#if parameters}} -

Parameter definitions

+

{{i18n "descriptionOfParameters"}}

@@ -23,4 +23,4 @@
{{/if}} - \ No newline at end of file + diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/paths.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/paths.hbs index bb8e47f..b3192d4 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/paths.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/paths.hbs @@ -3,7 +3,7 @@ @params {Path[]} paths a list of Swagger Path-Objects @api public --}} -

Paths

+

{{i18n "messages"}}

{{#eachSorted paths}} {{>swagger/path pathItems=. path=@key}} diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/request-body.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/request-body.hbs index 8b4a617..64f5c4e 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/request-body.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/request-body.hbs @@ -10,7 +10,7 @@ {{#if consumes}}

{{>swagger/list-of-labels values=consumes}}

{{else if @root.consumes}} -

Uses default content-types: +

{{i18n "defaultFormat"}} (content-type): {{>swagger/list-of-labels values=@root.consumes}}

{{/if}} diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/responseDefinitions.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/responseDefinitions.hbs index e3f67c2..3ddeaa4 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/responseDefinitions.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/responseDefinitions.hbs @@ -2,7 +2,7 @@ Renders the response definitions --}} {{#if responses}} -

Response definitions

+

{{i18n "descriptionOfResponse"}}

{{#each responses}} diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/responses.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/responses.hbs index cc4a9fc..02fad1d 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/responses.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/responses.hbs @@ -10,7 +10,7 @@ {{#if produces}}

{{>swagger/list-of-labels values=produces}}

{{else if @root.produces}} -

Uses default content-types: +

{{i18n "defaultContentType"}}: {{>swagger/list-of-labels values=@root.produces}}

{{/if}} diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/securityDefinitions.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/securityDefinitions.hbs index 477ff11..640e8de 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/securityDefinitions.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/securityDefinitions.hbs @@ -5,7 +5,7 @@ --}} {{#if securityDefinitions}} -

Security

+

{{i18n "security"}}

{{#each securityDefinitions}}
diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/summary.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/summary.hbs index 76c779c..ed3048a 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/summary.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/summary.hbs @@ -3,13 +3,13 @@ @todo params @api public --}} -

Summary

+

{{i18n "summary"}}

- - - + + + diff --git a/packages/bootprint-openapi/handlebars/partials/swagger/tags.hbs b/packages/bootprint-openapi/handlebars/partials/swagger/tags.hbs index 941a347..5bc3247 100644 --- a/packages/bootprint-openapi/handlebars/partials/swagger/tags.hbs +++ b/packages/bootprint-openapi/handlebars/partials/swagger/tags.hbs @@ -4,9 +4,9 @@ @api public --}} -

Summary

+

{{i18n "summary"}}

{{#eachSorted tags}} -

Tag: {{name}}

+

{{i18n "scenario"}}: {{name}}

{{md description}}

{{>swagger/externalDocs}} @@ -14,8 +14,8 @@

PathOperationDescription{{i18n "path"}}{{i18n "operation"}}{{i18n "description"}}
- - + +
OperationDescription{{i18n "operation"}}{{i18n "description"}}