swagger.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. 'use strict';
  2. /**
  3. * Translator for documentation pages.
  4. *
  5. * To enable translation you should include one of language-files in your index.html
  6. * after <script src='lang/translator.js' type='text/javascript'></script>.
  7. * For example - <script src='lang/ru.js' type='text/javascript'></script>
  8. *
  9. * If you wish to translate some new texsts you should do two things:
  10. * 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.
  11. * 2. Mark that text it templates this way <anyHtmlTag data-sw-translate>New Phrase</anyHtmlTag> or <anyHtmlTag data-sw-translate value='New Phrase'/>.
  12. * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate.
  13. *
  14. */
  15. window.SwaggerTranslator = {
  16. _words: [],
  17. translate: function () {
  18. var $this = this;
  19. $('[data-sw-translate]').each(function () {
  20. $(this).html($this._tryTranslate($(this).html()));
  21. $(this).val($this._tryTranslate($(this).val()));
  22. $(this).attr('title', $this._tryTranslate($(this).attr('title')));
  23. });
  24. },
  25. _tryTranslate: function (word) {
  26. return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
  27. },
  28. learn: function (wordsMap) {
  29. this._words = wordsMap;
  30. },
  31. //setControllerSummary: function () {
  32. // var _str = $("#input_baseUrl").val();
  33. // $.ajax({
  34. // type: "get",
  35. // async: true,
  36. // url: $("#input_baseUrl").val(),
  37. // dataType: "json",
  38. // success: function (data) {
  39. // //console.log(data)
  40. // var toggleEndpointList = [];
  41. // var summaryDict = data.ControllerDescription;
  42. // var id, controllerName, strSummary;
  43. // $('body').append('<ul class="leftMenu"></ul>');
  44. // $("#resources .resource").each(function (i, item) {
  45. // id = $(item).attr("id");
  46. // if (id) {
  47. // controllerName = id.substring(9);
  48. // strSummary = summaryDict[controllerName];
  49. // if (strSummary) {
  50. // console.log($(item))
  51. // $(item).children(".heading").children("h2").children('a').text(strSummary);
  52. // $(item).children(".heading").children(".options").prepend('<li class="controller-summary" title="' + strSummary + '">' + strSummary + '</li>');
  53. // $('.leftMenu').append('<li class="menuLi" title="' + strSummary + '"><a href="" class="menuLiA">' + strSummary + '</a></li>');
  54. // toggleEndpointList.push($(item).attr('id'));
  55. // }
  56. // }
  57. // });
  58. // for (var i = 0; i < document.getElementsByClassName('menuLiA').length; i++) {
  59. // var menuLiA = document.getElementsByClassName('menuLiA');
  60. // menuLiA[i].setAttribute('href', '#' + toggleEndpointList[i])
  61. // }
  62. // }
  63. // });
  64. //},
  65. };
  66. window.SwaggerTranslator.learn({
  67. "Warning: Deprecated": "警告:已过时",
  68. "Implementation Notes": "实现备注",
  69. "Response Class": "响应类",
  70. "Status": "状态",
  71. "Parameters": "参数",
  72. "Parameter": "参数",
  73. "Value": "值",
  74. "Description": "描述",
  75. "Parameter Type": "参数类型",
  76. "Data Type": "数据类型",
  77. "Response Messages": "响应消息",
  78. "HTTP Status Code": "HTTP状态码",
  79. "Reason": "原因",
  80. "Response Model": "响应模型",
  81. "Request URL": "请求URL",
  82. "Response Body": "响应体",
  83. "Response Code": "响应码",
  84. "Response Headers": "响应头",
  85. "Hide Response": "隐藏响应",
  86. "Headers": "头",
  87. "Try it out!": "试一下!",
  88. "Show/Hide": "显示/隐藏",
  89. "List Operations": "显示操作",
  90. "Expand Operations": "展开操作",
  91. "Raw": "原始",
  92. "can't parse JSON. Raw result": "无法解析JSON. 原始结果",
  93. "Model Schema": "模型架构",
  94. "Model": "模型",
  95. "apply": "应用",
  96. "Username": "用户名",
  97. "Password": "密码",
  98. "Terms of service": "服务条款",
  99. "Created by": "创建者",
  100. "See more at": "查看更多:",
  101. "Contact the developer": "联系开发者",
  102. "api version": "api版本",
  103. "Response Content Type": "响应Content Type",
  104. "fetching resource": "正在获取资源",
  105. "fetching resource list": "正在获取资源列表",
  106. "Explore": "浏览",
  107. "Show Swagger Petstore Example Apis": "显示 Swagger Petstore 示例 Apis",
  108. "Can't read from server. It may not have the appropriate access-control-origin settings.": "无法从服务器读取。可能没有正确设置access-control-origin。",
  109. "Please specify the protocol for": "请指定协议:",
  110. "Can't read swagger JSON from": "无法读取swagger JSON于",
  111. "Finished Loading Resource Information. Rendering Swagger UI": "已加载资源信息。正在渲染Swagger UI",
  112. "Unable to read api": "无法读取api",
  113. "from path": "从路径",
  114. "server returned": "服务器返回"
  115. });
  116. setTimeout(function () {
  117. document.querySelector('link[rel="icon"]').href = "/img/favicon.ico";
  118. var toolBar = document.getElementsByClassName("topbar")[0];
  119. toolBar.style.backgroundColor = "#009ef7";
  120. toolBar.style.padding = "15px 0 17px";
  121. var link = document.getElementsByClassName("topbar-wrapper")[0];
  122. link.innerHTML = "开放性接口";
  123. link.style.color = "#fff";
  124. link.style.fontSize = "24px";
  125. link.href = "/";
  126. }, 100);