【问题标题】:how to add localization in ionic popup如何在离子弹出窗口中添加本地化
【发布时间】:2017-04-03 17:55:44
【问题描述】:

我已经完成了 ionic 项目。我想更改此代码中的语言。项目标题、占位符、按钮已更改,但弹出窗口未更改。我在控制器和语言更改文件中使用了此代码。

farmer-ctrl.js:

function showPopup () {
  $scope.data = {};
  var myPopup = $ionicPopup.show({
    template: '<input type="text" ng-model="data.category">',
    title: '{{"farmers_message" | translate}}', //'Enter CoconutType',
    scope: $scope,
    buttons: [
     { text: 'Cancel' },
      {
        text: '<b>{{"save_message" | translate}}</b>',
        type: 'button-positive',
        onTap: function (e) {
          if (!$scope.data.category) {
            //don't allow the user to close unless he enters producttype
            e.preventDefault();

          } else {
            $log.log('yes clicked: ', $scope.data.category);
            addProductType();
            return $scope.data.category;
          }
        }
      },
    ]
  });
  myPopup.then(function (res) {
    $log.log('Tapped!', res);
  });
}

【问题讨论】:

    标签: angularjs html css ionic-framework


    【解决方案1】:

    我是通过添加 translate.instant 创建的

    function showPopup () {
      $scope.data = {};
      var myPopup = $ionicPopup.show({
        template: '<input type="text" ng-model="data.category">',
        // title: 'Enter CoconutType',
        title: $translate.instant('{{"farmers_message" | translate}}'),
        scope: $scope,
        buttons: [
         { text: 'Cancel' },
          {
            text: $translate.instant('{{"save_message" | translate}}'),
            type: 'button-positive',
            onTap: function (e) {
              if (!$scope.data.category) {
                //don't allow the user to close unless he enters producttype
                e.preventDefault();
    
              } else {
                $log.log('yes clicked: ', $scope.data.category);
                addProductType();
                return $scope.data.category;
              }
            }
          },
        ]
      });
      myPopup.then(function (res) {
        $log.log('Tapped!', res);
      });
    }
    

    【讨论】:

    • 所以我在 1 小时前添加了我的答案,然后您说您使用 $translate.instant 找到了解决方案。和我的回答一样。好吧,随便
    【解决方案2】:

    要在弹出窗口中添加本地化,​​您需要以下内容:

     var alertPopup = $ionicPopup.alert({
                  title: $translate.instant('networkerror'),
                    template: '<div><p  translate="onlinemessagepois"></p></div>'
          });
    

    networkerroronlinemessagepois 存在于您的本地 js 文件中。 (例如:"networkerror":"sometext","onlinemessagepois":"someothertext")

    注意:你必须在你的控制器中注入$translate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 2013-12-16
      相关资源
      最近更新 更多