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 @@ --}}
- {{#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}}{{>swagger/list-of-labels values=consumes}}
{{else if @root.consumes}} -{{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}} -{{>swagger/list-of-labels values=produces}}
{{else if @root.produces}} -{{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}} -Path | -Operation | -Description | +{{i18n "path"}} | +{{i18n "operation"}} | +{{i18n "description"}} |
---|
Operation | -Description | +{{i18n "operation"}} | +{{i18n "description"}} |
---|