question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to get values using angular translate

See original GitHub issue

Hi!

I am trying angular-translate in my project and I successfully set up translations in HTML files using your library. Now I would like to translate messages used in my JavaScript scripts, but the browser reports error message “ReferenceError: $translate is not defined”. How translation service should be accessed from JavaScript?

My function defined in controller.js:

`$scope.sendCartByEmail = function() {
alert($translate('CART_SEND_EMAIL_SUCCESS'));
}

translate-angular imported in app.js as decribed in tutorial:

var app= angular.module('dutyfree', [
'pascalprecht.translate',
'ui.bootstrap',
'ngRoute',
'dutyfreeControllers'
]);

app.config(['$translateProvider', function($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: 'js/languages/',
suffix: '.json'
});
$translateProvider.preferredLanguage('en');
}]);

app.controller('TranslateCtrl', ['$translate', '$scope', function ($translate, $scope) {
$scope.changeLanguage = function (langKey) {
$app.uses(langKey);
};
}]);`

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
knallicommented, Jul 20, 2016

@mohanmanis Sorry. my fault. 😦

Sorry, too much mails in the inbox and I got something missed. Please provide a running demo at plnkr.co or jsfiddler. That helps a lot

0reactions
knallicommented, Sep 21, 2016

Hello,

I’m closing this issue due inactivity. We have asked for additional details, but you could not helped us. Therefore we close this issue as not reproducible.

If you still have an issue, please create a new issue because we cannot be sure to track closed issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to get dynamic translation of text using ngx translate ...
I tried wrapping above method inside Observables , Promises but it's not able to get translated version of text during page load. I...
Read more >
How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >
How to translate Angular apps: @angular/localize and xlf
Angular can only translate messaged found in your templates. You can't use translations in your source code (.ts files). If one of this...
Read more >
Prepare component for translation - Angular
To prepare your project for translation, complete the following actions. Use the i18n attribute to mark text in component templates; Use the i18n-...
Read more >
Using ngx-translate to switch the language of a Form in your ...
You need to import these modules in app.module.ts to make it work. App.module.ts import { TranslateLoader, TranslateModule } from '@ngx-translate/core ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found