AngularJS 下拉表翻译

  • A+
所属分类:Web前端

AngularJS 下拉表翻译

Html

  1. <html ng-app="app">    
  2. <head>    
  3.     <meta name="viewport" content="width=device-width" />    
  4.     <meta charset="utf-8">    
  5.     <title>Index</title>      
  6. </head>    
  7. <body>    
  8.     
  9.     <script src="bower_components/angular/angular.min.js"></script>    
  10.     <script src="bower_components/angular-translate/angular-translate.min.js"></script>    
  11.     <script src="bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js"></script>    
  12.     <script src="bower_components/ionic-v1.3.2/js/angular/angular-sanitize.min.js"></script>    
  13.     <script type="text/javascript">    
  14.         var app = angular.module("app", ['pascalprecht.translate']);    
  15.         app.config(['$translateProvider', function ($translateProvider) {    
  16.             var lang = window.localStorage.lang || 'cn';    
  17.             $translateProvider.useStaticFilesLoader({    
  18.                 prefix: 'il8n/',    
  19.                 suffix: '.json'    
  20.             });    
  21.             $translateProvider.preferredLanguage(lang);    
  22.         }]);    
  23.     
  24.     
  25.     
  26.         angular.module('app').controller('LanguageSwitchingCtrl', ['$scope', '$translate', function (scope, $translate) {    
  27.             scope.switching = function (lang) {    
  28.                 $translate.use(lang);    
  29.                 window.localStorage.lang = lang;    
  30.                window.location.reload();    
  31.             };    
  32.             scope.cur_lang = $translate.use();    
  33.         }]);    
  34.     
  35.         angular.module("app").filter("T", ['$translate', function ($translate) {    
  36.             return function (key) {    
  37.                 if (key) {    
  38.                     return $translate.instant(key);    
  39.                 }    
  40.             };    
  41.         }]);    
  42.     
  43.         angular.module('app').controller('LgoinCtrl', ['$scope', 'T',    
  44.     function ($scope, T) {    
  45.     
  46.         $scope.login_title = T.T(100001);    
  47.     
  48.     }    
  49.             ]);    
  50.         window.onload = function () {    
  51.             var obj = document.getElementById('select1');    
  52.             obj.options.length = 0;    
  53.             var obj = document.getElementById('select1');    
  54.             //添加一个选项     
  55.             obj.options.add(new Option("English""en")); //这个兼容IE与firefox     
  56.             obj.options.add(new Option("繁體中文""cn"));    
  57.             obj.options.add(new Option("日本语""riyu"));    
  58.             obj.options.add(new Option("한국어""hanyu"));    
  59.         }    
  60.     </script>    
  61.     <!--<select class="language-switching" ng-controller="LanguageSwitchingCtrl" ng-model="cur_lang" ng-change="switching(cur_lang)">    
  62.         <option value="en">English</option>    
  63.         <option value="cn">简体中文</option>    
  64.     </select>    
  65.     
  66.     
  67.     <h1>{{"100001" | translate}}</h1>    
  68.     <h1>{{"100002" | translate}}</h1>-->    
  69.     
  70.     <select class="weui-select" name="select1" ng-controller="LanguageSwitchingCtrl" ng-model="cur_lang" ng-change="switching(cur_lang)" id="select1">    
  71.         <option value="en">English</option>    
  72.         <option value="cn">繁體中文</option>    
  73.         <option value="riyu">日本语</option>    
  74.         <option value="hanyu">한국어</option>    
  75.     
  76.     </select>    
  77.     
  78.     <p class="weui-grid__label"><font face="Microsoft YaHei" size="3">{{"100001" | translate}}</font></p>    
  79.     <div>    
  80.         <p id="Button1">{{"100001" | translate}}</p>    
  81.     </div>    
  82. </body>    
  83. </html>    
钰玺

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: