Angular翻译 - 控制器

时间:2016-10-26 10:59:12

标签: javascript angularjs angular-translate

我没有找到任何对我来说有用的东西如何在控制器中翻译某些东西,例如我在控制器中的数组。问题是我不知道如何翻译features数组中的标题键。这是数组的例子:

vm.features = [
            {
                title: "pregled partnera",
                salesbox: true,
                docbox: true,
                connectionbox: true,
                premiumbox: true
            },
            {
                title: "katalog proizvoda",
                salesbox: true,
                docbox: true,
                connectionbox: true,
                premiumbox: true
            },
            {
                title: "ponude",
                salesbox: true,
                docbox: true,
                connectionbox: true,
                premiumbox: true
            }
]

所以我需要翻译标题,我在html中的内容是ng-repeat,它看起来像这样:

<tr ng-repeat="feature in pricing.features">
    <td>{{feature.title}}</td>
    <td class="text-center salesbox"><span class="icon-checked" ng-if="feature.salesbox == true"></span></td>
    <td class="text-center docbox"><span class="icon-checked" ng-if="feature.docbox == true"></span></td>
    <td class="text-center connectionbox"><span class="icon-checked" ng-if="feature.connectionbox == true"></span></td>
    <td class="text-center premiumbox"><span class="icon-checked" ng-if="feature.premiumbox == true"></span></td>
</tr>

我如何翻译feature.title?我尝试使用$ filter,但我没有成功。

这也是我在angular中的配置,它显示我有所有翻译键的外部json:

$translateProvider.useStaticFilesLoader({
    prefix: 'app/languages/',
    suffix: '.json'
});
$translateProvider.preferredLanguage('hr');
$translateProvider.useLocalStorage();
$translateProvider.useSanitizeValueStrategy('escape');

0 个答案:

没有答案