angular-translate

Get current language with angular-translate

﹥>﹥吖頭↗ 提交于 2019-11-28 15:54:30
问题 Is there a way to get the current used language in a controller (without $translateProvider )? Couldn't find anything in the $translate service. 回答1: $translate.use() is a getter and setter. See this demo found in links of docs: http://jsfiddle.net/PascalPrecht/eUGWJ/7/ 回答2: $translate.use() is the way to go. Also, when an asynchronous loader is executed, you might wanna use $translate.proposedLanguage() which returns the language key of the language that is currently loaded but not finished

Start Angular.js route-segment or ui-router after all translations are loaded

耗尽温柔 提交于 2019-11-28 14:30:51
Is there any way, how to start ui-router or route-segment just after translateProvider loads its translations? I'm using pascal prechts translate filter together with bind once {{:: }} notation. On localhost it works pretty good, but when I test it on remote server, bind once will remove watchers sooner than strings are translated. So I was wondering if there is some way how to delay routing a little bit. Radim Köhler Try to check the native, built-in feature: $urlRouterProvider.deferIntercept(defer) Disables (or enables) deferring location change interception. If you wish to customize the

How to load Angular-translate before any UI is displayed with ui-router resolve

那年仲夏 提交于 2019-11-28 06:32:46
问题 I used angular-translate for i18n. I want to use $translatePartialLoader service to modular language key as lazy load. Also I want to use ui-router resolve option for this. Now How to do this? Is possible add a code sample for me? Thanks 回答1: I find solutions and solve my problem. In config: $translatePartialLoaderProvider.addPart('index'); $translateProvider .useSanitizeValueStrategy(null) .fallbackLanguage('en-us') .registerAvailableLanguageKeys(['en-us','pt-br'], { 'en_*': 'en-us', 'pt_*':

AngularJS translate: Format dynamic dates

纵然是瞬间 提交于 2019-11-28 03:30:33
问题 Using AngularJS and angular-translate I am trying to insert a date as parameter in a translated text. The basic task is documented by the translate package: <p>{{ 'MyText' | translate:{myDate:someControllerDate} }}</p> with this in a localized json-file: (english)'MyText': 'This is the date: {{myDate}}.' (danish) 'MyText': 'Dette {{myDate}} er datoen.' This gives me: (english) This is the date: 2015-04-29T00:00:00. (danish) Dette 2015-04-29T00:00:00 er datoen. The problem: I would like to

Localize URL's with ui-router and angular-translate

允我心安 提交于 2019-11-27 18:32:57
I am using ui-router for routing and angular-translate for translations. What i would like to achieve is having the selected language bind to the url like so: www.mydomain.com/en/ www.mydomain.com/ru/ www.mydomain.com/en/about www.mydomain.com/ru/about and it will respond accordingly. Tried to look for examples, but did not find anything. If someone implemented similar solution, i would love to hear how you did it. Thanks I use something along these lines: CoffeeScript angular.module('app') .config([ '$stateProvider' ($stateProvider) -> $stateProvider.state 'app', abstract: true url: '/{locale

Exposing the current state name with ui router

青春壹個敷衍的年華 提交于 2019-11-27 11:53:14
问题 I'm trying to implement a language switcher where if a user clicks on "de" from any given page on an "en" side - it takes them to that page of the "de" side. If I console.dir the $state parameter, it exposes the values I'd want with the "current" property of the given $state. If I try to console.dir the $state.current to focus on the values I want, it only gives the parent state property (my current views are nested). My current thinking is, I'm on url/en/content, and dynamically I can then

How to ng-translate inside select box option in angularjs

╄→尐↘猪︶ㄣ 提交于 2019-11-27 10:07:25
问题 How do I apply ng-translate to translate options inside a select box. For example: Template: <select class="form-control" ng-model="me.gender" ng-options="gender.name for gender in genders"> </select> Controller: $scope.genders = [{code: "M", name:"TXT_MALE"}, {code: "F", name:"TXT_FEMALE"}] enUS.json: { "TXT_MALE": "Male", "TXT_FEMALE": "Female", } I tried adding filter like ng-options="gender.name for gender in genders | translate" but obviously it was adding filter to $scope.genders array

Start Angular.js route-segment or ui-router after all translations are loaded

六月ゝ 毕业季﹏ 提交于 2019-11-27 08:28:57
问题 Is there any way, how to start ui-router or route-segment just after translateProvider loads its translations? I'm using pascal prechts translate filter together with bind once {{:: }} notation. On localhost it works pretty good, but when I test it on remote server, bind once will remove watchers sooner than strings are translated. So I was wondering if there is some way how to delay routing a little bit. 回答1: Try to check the native, built-in feature: $urlRouterProvider.deferIntercept(defer)

Correct use for angular-translate in controllers

限于喜欢 提交于 2019-11-26 06:55:34
问题 I\'m using angular-translate for i18n in an AngularJS application. For every application view, there is a dedicated controller. In the controllers below, I set the value to be shown as the page title. Code HTML <h1>{{ pageTitle }}</h1> JavaScript .controller(\'FirstPageCtrl\', [\'$scope\', \'$filter\', function ($scope, $filter) { $scope.pageTitle = $filter(\'translate\')(\'HELLO_WORLD\'); }]) .controller(\'SecondPageCtrl\', [\'$scope\', \'$filter\', function ($scope, $filter) { $scope