From 5bc2a5d818a0e3e34d97652d164c190d85ac4525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9A=D0=B0=D0=BB=D0=B8=D0=BD=D0=B8=D0=BD?= Date: Thu, 26 Feb 2015 15:38:27 +0300 Subject: [PATCH] codestyle --- .gitignore | 25 ++++++++++++----------- README.md | 19 +++++++++++++++++ dist/lang/en.js | 3 +-- dist/lang/translator.js | 6 +++--- dist/lib/swagger-client.js | 14 ++++++------- dist/swagger-ui.js | 42 +++++++++++++++++++------------------- 6 files changed, 64 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index d6ef6414..6b98d126 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,13 @@ -.DS_STORE -*.ipr -*.iml -*.iws -web/ -lib/*.zip -version.properties -.sass-cache -swagger-ui.sublime-workspace -.idea -.project -node_modules/* +.DS_STORE +*.ipr +*.iml +*.iws +web/ +lib/*.zip +version.properties +.sass-cache +swagger-ui.sublime-workspace +.idea +.project +node_modules/* +/nbproject/private/ \ No newline at end of file diff --git a/README.md b/README.md index c45e6e38..76d000bb 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstor You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories: - dist: Contains a distribution which you can deploy on a server or load from your local machine. +- dist/lang: The swagger localisation - lib: Contains javascript dependencies which swagger-ui depends on - node_modules: Contains node modules which swagger-ui uses for its development. - src @@ -123,6 +124,24 @@ window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX" Note! You can pass multiple header params on a single request, just use unique names for them (`key` is used in the above example). +### Localisation and translation +The localisation files are in the dist/lang directory. + +To enable translation you should append next two lines in your swagger's index.html (or another entry point you use) + + +The first line script is a translator and the second one is your language lexemes. + +If you wish to append support for new language you just need to create lang/your_lang.js and fill it like it's done in existing files. + +To append new lexemex for translation you shoul do two things: +1. Add lexeme into the language file. + Example of new line: "new sentence":"translation of new sentence" +2. Mark this lexeme in source html with attribute data-sw-translate. + Example of chenged source: new sentence + or +At this moment only inner html, title-attribute and value-attribute are going to be translated. + ## CORS Support CORS is a technique to prevent websites from doing bad things with your personal data. Most browsers + javascript toolkits not only support CORS but enforce it, which has implications for your API server which supports Swagger. diff --git a/dist/lang/en.js b/dist/lang/en.js index a7356d9c..a06e75f6 100644 --- a/dist/lang/en.js +++ b/dist/lang/en.js @@ -1,4 +1,4 @@ -SwaggerTranslator.learn({this._swaggerLang = { +SwaggerTranslator.learn({ "Warning: Deprecated":"Warning: Deprecated", "Implementation Notes":"Implementation Notes", "Response Class":"Response Class", @@ -18,7 +18,6 @@ SwaggerTranslator.learn({this._swaggerLang = { "Response Code":"Response Code", "Response Headers":"Response Headers", "Hide Response":"Hide Response", - "Response Messages":"Response Messages", "Try it out!":"Try it out!", "Show/Hide":"Show/Hide", "List Operations":"List Operations", diff --git a/dist/lang/translator.js b/dist/lang/translator.js index eabb5731..043a8060 100644 --- a/dist/lang/translator.js +++ b/dist/lang/translator.js @@ -7,8 +7,8 @@ * * If you wish to translate some new texsts you should do two things: * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. - * 2. Mark that text it templates this way New Phrase or . - * The main thing here is attribute data-swTarnslate. Only inner html, title-attribute and value-attribute are going to translate. + * 2. Mark that text it templates this way New Phrase or . + * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate. * */ SwaggerTranslator = { @@ -17,7 +17,7 @@ SwaggerTranslator = { translate: function() { var $this = this; - $("[data-swTarnslate]").each( + $("[data-sw-translate]").each( function() { $(this).html( $this._tryTranslate($(this).html()) diff --git a/dist/lib/swagger-client.js b/dist/lib/swagger-client.js index ad4892f5..884b4ba4 100644 --- a/dist/lib/swagger-client.js +++ b/dist/lib/swagger-client.js @@ -343,7 +343,7 @@ SwaggerClient.prototype.initialize = function (url, options) { SwaggerClient.prototype.build = function(mock) { if (this.isBuilt) return this; var self = this; - this.progress('fetching resource list: ' + this.url); + this.progress('fetching resource list: ' + this.url); var obj = { useJQuery: this.useJQuery, url: this.url, @@ -354,11 +354,11 @@ SwaggerClient.prototype.build = function(mock) { on: { error: function(response) { if (self.url.substring(0, 4) !== 'http') - return self.fail('Please specify the protocol for ' + self.url); + return self.fail('Please specify the protocol for ' + self.url); else if (response.status === 0) - return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); + return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); else if (response.status === 404) - return self.fail('Can\'t read swagger JSON from ' + self.url); + return self.fail('Can\'t read swagger JSON from ' + self.url); else return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url); }, @@ -1729,7 +1729,7 @@ var SwaggerResource = function (resourceObj, api) { } else { this.url = this.api.basePath + this.path.replace('{format}', 'json'); } - this.api.progress('fetching resource ' + this.name + ': ' + this.url); + this.api.progress('fetching resource ' + this.name + ': ' + this.url); var obj = { url: this.url, method: 'GET', @@ -1745,8 +1745,8 @@ var SwaggerResource = function (resourceObj, api) { }, error: function (response) { _this.api.resourceCount += 1; - return _this.api.fail('Unable to read api \'' + - _this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')'); + return _this.api.fail('Unable to read api \'' + + _this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')'); } } }; diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 7ef6dee2..5c3777e7 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -425,7 +425,7 @@ Handlebars.registerHelper('sanitize', function(html) { }); this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - return "
\n
\n
\n
Username
\n \n
Password
\n \n \n
\n
\n\n"; + return "
\n
\n
\n
Username
\n \n
Password
\n \n \n
\n
\n\n"; },"useData":true}); var ApiKeyButton, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -584,15 +584,15 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; return ""; + + "\" data-sw-translate>Terms of service"; },"4":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; - return ""; },"10":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; return "
api version: " + return " , api version: " + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.version : stack1), depth0)) + "\n "; },"14":function(depth0,helpers,partials,data) { @@ -631,7 +631,7 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
\n"; stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.info : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}); if (stack1 != null) { buffer += stack1; } - buffer += "
\n
\n
    \n\n
    \n
    \n
    \n

    [ base url: " + buffer += "

    \n
    \n
      \n\n
      \n
      \n
      \n

      [ base url: " + escapeExpression(((helper = (helper = helpers.basePath || (depth0 != null ? depth0.basePath : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"basePath","hash":{},"data":data}) : helper))) + "\n"; stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.version : stack1), {"name":"if","hash":{},"fn":this.program(12, data),"inverse":this.noop,"data":data}); @@ -673,9 +673,9 @@ ContentTypeView = (function(_super) { this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { return "deprecated"; },"3":function(depth0,helpers,partials,data) { - return "

      Warning: Deprecated

      \n"; + return "

      Warning: Deprecated

      \n"; },"5":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "

      Implementation Notes

      \n

      "; + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "

      Implementation Notes

      \n

      "; stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } return buffer + "

      \n"; @@ -699,17 +699,17 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function return "
      \n \n
      \n"; },"16":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return "

      Response Class (Status " + return "

      Response Class (Status " + escapeExpression(((helper = (helper = helpers.successCode || (depth0 != null ? depth0.successCode : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"successCode","hash":{},"data":data}) : helper))) + ")

      \n

      \n
      \n
      \n \n \n"; + return buffer + " \n \n
      \n \n \n"; },"useData":true}); var HeaderView, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -1635,7 +1635,7 @@ OperationView = (function(_super) { json = JSON.stringify(JSON.parse(content), null, " "); } catch (_error) { e = _error; - json = "can't parse JSON. Raw result:\n\n" + content; + json = "can't parse JSON. Raw result:\n\n" + content; } code = $('').text(json); pre = $('
      ').append(code);
      @@ -2082,7 +2082,7 @@ this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(
         var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
         return "
    • \n Raw\n
    • "; + + "' data-sw-translate>Raw\n "; },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, blockHelperMissing=helpers.blockHelperMissing, buffer = "
      \n

      \n Show/Hide\n \n
    • \n Show/Hide\n
    • \n
    • \n \n List Operations\n \n
    • \n
    • \n \n List Operations\n \n
    • \n
    • \n \n Expand Operations\n \n
    • \n "; + + "\">\n Expand Operations\n \n \n "; stack1 = ((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(options={"name":"url","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); if (!helpers.url) { stack1 = blockHelperMissing.call(depth0, stack1, options); } if (stack1 != null) { buffer += stack1; } @@ -2202,7 +2202,7 @@ this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({ },"4":function(depth0,helpers,partials,data) { return " \n"; },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, buffer = "\n\n"; stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data}); if (stack1 != null) { buffer += stack1; } return buffer + "\n"; @@ -2250,7 +2250,7 @@ StatusCodeView = (function(_super) { })(Backbone.View); this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n\n
      \n\n
      \n
      \n "; + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n\n
      \n\n
      \n
      \n "; stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } return buffer + "\n
      \n\n
      \n
      "