Not able to get values using angular translate
See original GitHub issueHi!
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:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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
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.