简体   繁体   English

如何使用角度$ translate获取特定语言的键的翻译

[英]How to get the translations of a key in a particular language using angular $translate

Is there a way to get the translation in a particular language using angualar $translate from inside a controller? 有没有办法使用控制器内部的angualar $ translate获得特定语言的翻译? $translate.instant(KEY) return the translation of the key based on the selected language . $ translate.instant(KEY)返回基于所选语言的键的翻译。 What I need is something like For example if I have already defined the translations in two languages: english and spanish , then $translate.Somefunction(KEY,"languagekey") 我需要的是类似的东西,例如,如果我已经用两种语言定义了翻译:英语和西班牙语,然后$ translate.Somefunction(KEY,“ languagekey”)

I am not a $translate expert, but can you change the preferred language, do the translation, then switch the preferred language back? 我不是$translate专家,但是您可以更改首选语言,进行翻译,然后再切换回首选语言吗?

var preferred = $translate.preferredLanguage();
$translate.use('de')
$translate('HEADLINE').then(function(headline){
   $scope.translatedGerman = headline;
});
$translate.use(preferred);

Seems to be working in my simple demo at least: http://plnkr.co/edit/tPRbH7Oehy1nycBVopUw?p=preview 似乎至少在我的简单演示中起作用: http : //plnkr.co/edit/tPRbH7Oehy1nycBVopUw?p=preview

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 ngx translate to angular 将数据转换为 ts - How to translate data to ts using ngx translate to angular 如何在Angular Using API中获取特定ID的值(在Angular Using API中使用CRUD) - How to get values for the particular Id in Angular Using API (CRUD In Angular Using API) 如何使用 *ngFor 中的动态键获取数组:Angular 2+ - How to get the array using a dynamic key in *ngFor : Angular 2+ 使用Google翻译翻译另一个文本字段的语言内容 - Using Google Translate to translate the language contents of another textfield 如何使用参数动态翻译文本文件到 angular 中的 ngx-translate? - How to dynamic translate text file using parameter to the ngx-translate in angular? 如何通过jquery将div转换到特定位置 - how to translate a div to particular position via jquery 我在侧面数组中使用了不同的键的数组,我想使用角度6中的HTML端的特定键来获取特定的数组 - I have array in side array with different key I want fetch the particular array using particular key from HTML side in angular 6 如何使用IBM Bluemix语言翻译服务翻译包含HTML的文本? - How can I translate text containing HTML using IBM Bluemix language translation service? 如何获取本地存储中特定键的总数 - how to get total count of a particular key in local storage 从本地存储中获取数据并使用 ngx-translate 将其显示在视图中 | Angular - Get data from localstorage and display it in view using ngx-translate | Angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM