【问题标题】:How to use dynamic variables with Angular Translate Rails?如何在 Angular Translate Rails 中使用动态变量?
【发布时间】:2015-11-11 09:16:10
【问题描述】:

我正在使用 gem angular-translate-rails,我正在尝试将变量传递给 rails,但它不起作用。后端是rails,前端是Angularjs。

到目前为止,这是我尝试过的:

1.控制器内:

$translate('analytics.show_review.directives.review_incomplete_message', {'number_of_not_empty_reviews': $scope.numberOfNotEmptyReviews,
  'number_of_reviews': $scope.numberOfReviews }).then(function (message) {
  $scope.reviewIncompleteMessage = message;
});

2.翻译yml:

en:
  home:
    message: "My variables are %{myFirstVariable} and %{ mySecondVariable }"

我得到一个空字符串作为回报 我尝试改变骆驼案和蛇案的组合,但效果不佳。

【问题讨论】:

    标签: ruby-on-rails ruby angularjs angular-translate


    【解决方案1】:

    在角度翻译中使用变量是这样的

    en:
      home:
        message: "My variables are {{ myFirstVariable }} and {{ mySecondVariable }}"
    

    使用它是这样的

    $translate('en.home.message', { myFirstVariable: 1, mySecondVariable: 2});
    

    【讨论】:

      猜你喜欢
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      相关资源
      最近更新 更多