$translate 的用法
translate 的用法 1.在html页面:文本的翻译 <h1 translate>hello world</h1> <h1 translate = 'hello world '></h1> <h1> 'hello world '|translate </h1> 2. placeholder= {{var|translate}} aria-label={{var|translate}} tooltip = {{var|translate}} ng-bind= {{var|translate}} ng-bind= {{key|translate}} <p translate = 'key' translate-values= ' { index:' {{var}}'}' --json key:".....{{index}}" 3.$translate.use(); define(function (require) { return function SavedObjectFactory(es, kbnIndex, Promise, Private, Notifier, safeConfirm, indexPatterns,$translate) { var angular = require('angular'); //luochunxiang@eisoo.com var message ; var lang = $translate.use(); if(lang === 'zh-cn'){ message = '你确定你想要覆盖 ' }else if(lang === 'zh-tw'){ message = '你確定你想要覆蓋 ' }else{ message = 'Are you sure you want to overwrite ' } $ 4.$translate.instant(key) var a = $translate.instant("Are you sure you want to delete the selected"); var b = $translate.instant("Are you sure you want to delete the selected"); var aaa = `trgutyr ${a}${currentTab.title}${b}`; 'rtguiyi' var bbb = aaa; ---.js var option = { "Seconds": $translate.instant("Seconds ago"), "Minutes":$translate.instant("Minutes ago"), "Hours": $translate.instant("Hours ago"), "Days": $translate.instant("Days ago"), "Weeks": $translate.instant("Weeks ago"), "Months": $translate.instant("Months ago"), "Years": $translate.instant("Years ago") }; $scope.relativeOptions = [ {text: option.Seconds, value: 's'}, {text: option.Hours, value: 'm'}, {text: option.Days, value: 'h'}, {text: option.Days, value: 'd'}, {text: option.Weeks, value: 'w'}, {text: option.Months, value: 'M'}, {text: option.Years, value: 'y'}, ]; ---.html <div class="form-group"> <select ng-model="relative.unit" ng-options="opt.value as opt.text for opt in relativeOptions" translate-values ng-change="formatRelative()" class="form-control col-xs-2"> </select> </div> 5直接使用window.localStorage.lang; //luochunxiang@eisoo.com var message ; var lang = window.localStorage.lang; if(lang === 'en-us'){ message = 'MMMM Do YYYY, HH:mm:ss.SSS' }else if(lang === 'zh-tw'){ message = 'YYYY年MM月DD日, HH:mm:ss.SSS' }else{ message = 'YYYY年MM月DD日, HH:mm:ss.SSS' } 6 ng-show = "lang === 'en-us'" <div ng-show = "lang === 'en-us'"> <saved-object-finder title="Saved Searches" type="searches" make-url="step2WithSearchUrl"> </saved-object-finder> </div> <div ng-show = "lang === 'zh-tw'"> <saved-object-finder title="已存搜索" type="searches" make-url="step2WithSearchUrl"> </saved-object-finder> </div> <div ng-show = "lang === 'zh-cn'"> <saved-object-finder title="已存搜索" type="searches" make-url="step2WithSearchUrl"> </saved-object-finder> </div> 7 <div ng-if="aggParam.name"> <span><label>{{ aggParam.name | translate }}</span> <span translate>Pattern</span></label> </div> <div ng-if="label"> <label>{{ label | translate }} <span translate>Pattern</span></label> </div> <!-- <label>{{ aggParam.name | label }} <span translate>Pattern</span></label> -->