ABP 使用SwaggerUI漢化


 

 

配置SweaggerUI

 1         private void ConfigureSwaggerUi()
 2         {
 3             Configuration.Modules.AbpWebApi().HttpConfiguration
 4                 .EnableSwagger(c =>
 5                 {
 6                     c.SingleApiVersion("v1", "Demo.WebApi");
 7                     c.IncludeXmlComments(string.Format(@"{0}\bin\{1}.XML", System.AppDomain.CurrentDomain.BaseDirectory, typeof(DemoApplicationModule).Assembly.GetName().Name));
 8                     c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
 9                 })
10                 .EnableSwaggerUi(c => {
11                     c.InjectJavaScript(Assembly.GetExecutingAssembly(), "Demo.WebApi.Swagger.translator.js");
12                 });
13         }

 

漢化文件

 1 'use strict';
 2 
 3 /**
 4  * Translator for documentation pages.
 5  *
 6  * To enable translation you should include one of language-files in your index.html
 7  * after <script src='lang/translator.js' type='text/javascript'></script>.
 8  * For example - <script src='lang/ru.js' type='text/javascript'></script>
 9  *
10  * If you wish to translate some new texsts you should do two things:
11  * 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.
12  * 2. Mark that text it templates this way <anyHtmlTag data-sw-translate>New Phrase</anyHtmlTag> or <anyHtmlTag data-sw-translate value='New Phrase'/>.
13  * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate.
14  *
15  */
16 window.SwaggerTranslator = {
17     _words: [],
18 
19     translate: function () {
20         var $this = this;
21         $('[data-sw-translate]').each(function () {
22             $(this).html($this._tryTranslate($(this).html()));
23             $(this).val($this._tryTranslate($(this).val()));
24             $(this).attr('title', $this._tryTranslate($(this).attr('title')));
25         });
26     },
27 
28     _tryTranslate: function (word) {
29         return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
30     },
31 
32     learn: function (wordsMap) {
33         this._words = wordsMap;
34     }
35 };
36 
37 
38 /* jshint quotmark: double */
39 window.SwaggerTranslator.learn({
40     "Warning: Deprecated": "警告:已過時",
41     "Implementation Notes": "實現備注",
42     "Response Class": "響應類",
43     "Status": "狀態",
44     "Parameters": "參數",
45     "Parameter": "參數",
46     "Value": "",
47     "Description": "描述",
48     "Parameter Type": "參數類型",
49     "Data Type": "數據類型",
50     "Response Messages": "響應消息",
51     "HTTP Status Code": "HTTP狀態碼",
52     "Reason": "原因",
53     "Response Model": "響應模型",
54     "Request URL": "請求URL",
55     "Response Body": "響應體",
56     "Response Code": "響應碼",
57     "Response Headers": "響應頭",
58     "Hide Response": "隱藏響應",
59     "Headers": "",
60     "Try it out!": "試一下!",
61     "Show/Hide": "顯示/隱藏",
62     "List Operations": "顯示操作",
63     "Expand Operations": "展開操作",
64     "Raw": "原始",
65     "can't parse JSON.  Raw result": "無法解析JSON. 原始結果",
66     "Model Schema": "模型架構",
67     "Model": "模型",
68     "apply": "應用",
69     "Username": "用戶名",
70     "Password": "密碼",
71     "Terms of service": "服務條款",
72     "Created by": "創建者",
73     "See more at": "查看更多:",
74     "Contact the developer": "聯系開發者",
75     "api version": "api版本",
76     "Response Content Type": "響應Content Type",
77     "fetching resource": "正在獲取資源",
78     "fetching resource list": "正在獲取資源列表",
79     "Explore": "瀏覽",
80     "Show Swagger Petstore Example Apis": "顯示 Swagger Petstore 示例 Apis",
81     "Can't read from server.  It may not have the appropriate access-control-origin settings.": "無法從服務器讀取。可能沒有正確設置access-control-origin。",
82     "Please specify the protocol for": "請指定協議:",
83     "Can't read swagger JSON from": "無法讀取swagger JSON於",
84     "Finished Loading Resource Information. Rendering Swagger UI": "已加載資源信息。正在渲染Swagger UI",
85     "Unable to read api": "無法讀取api",
86     "from path": "從路徑",
87     "server returned": "服務器返回"
88 });
89 
90 
91 $(function () {
92     window.SwaggerTranslator.translate();
93 });

 配置好上面那些之后在web api初始化的時候調用

 

顯示效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM