特大喜訊,View and Data API 現在支持中文界面了


大家經常會問到,使用View and Data API怎么做界面的本地化,來顯示中文,現在好消息來了,從v1.2.19起,View and Data API開始支持多國語言界面了。你需要制定版本號為v1.2.19. 其實,總是推薦大家在引用viewer的Javascript類庫時要指定版本號,因為View and Data API一直在快速演進中,有些API難免會有變化,為了防止你的Web應用受被變化的API影響,建議你加上版本號,並且及時關注view and data API的最新進展情況,及時在新版本下測試您的應用,並在合適的時機升級到新版本。

目前支持中文的版本為v1.2.19.

    <link type="text/css" rel="stylesheet" href="https://developer.api.autodesk.com/viewingservice/v1/viewers/style.css?v=v1.2.19"/>
<script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js?v=v1.2.19"></script>

語言的判定來自於viewer類庫中的detectLanguage()函數,他首先讀取detectLngQ,其次是從cookie中讀取,在其次是從讀取瀏覽器的語言設置,默認是英語。 不過如果你就想指定您的應用使用指定的某種語言,你也可以通過代碼的方式在初始化viewer時指定語言,代碼如下:

       function initialize() {
           var options = {
               env: "AutodeskProduction",
               getAccessToken: getToken,
               refreshToken: getToken,
               language : 'zh-HANS' //Simplified Chinese
           };

            // Allows different urn to be passed as url parameter
            var paramUrn = Autodesk.Viewing.Private.getParameterByName('urn');
            var urn = (paramUrn !== '' ? paramUrn : defaultUrn);

            if (urn.indexOf('urn:') !== 0)
            urn = 'urn:' + urn;

           Autodesk.Viewing.Initializer(options, function () {
               initializeViewer('viewerDiv', urn, '3d');
           });
       }

其中支持的語言為 :

cs
de
en
es
fr
it
ja
ko
pl
pt-BR
ru
tr
zh-HANS   簡體中文
zh-HANT   繁體中文

Here is how it looks like if I set language to zh-HANS:
zh_HANS


免責聲明!

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



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