-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotating strings in Javascript code #19
Comments
You're not the first person to get hit by this, I should probably clarify the documentation for this one. Not returning a translated string is intentional: You want to pass the original string to the view and translate it there. That way it can keep responding to language changes. If you really want the translated string in your controller, use Edit (2014/07/09): Nowadays you can just use Here's what your probably want to be doing:
And then in your view:
|
Thanks a lot for your quick reply ! As I don't really need the translated string in my controller, I would use your second option which is wayyyy better for my eyes ;) If you want to improve your documentation, just add the 2 last sentence. It is clear enough to me now ! Thanks again. |
Also, if you don't need the string at all in your controller, just put it directly into the view:
Or even nicer:
Enjoy! |
I too got confused and had to check the source code.
Then how do you treat this case? : app.service('HelloHttpService', function($http, Alert) {
this.query = function() {
$http.get('hello.json').then(
function(response) {
Alert.success('Everything OK'); <====
},
function(response) {
Alert.error('Something went wrong: ' + error + ', please reload'); <====
}
);
};
}); A function to translate text would be nice here: tr('Something went wrong: {{error}}, please reload', {error: error}); Note: |
@tkrotoff did you find a solution for this? |
In the javascript code, the call to gettext() does nothing except annotates the string for extraction by l10n-extract. This has been necessary in the past but nowadays call to gettextCatalog.getString() does that automatically. Hence, all the calls to gettext() were just unnecessary clutter. See e.g. rubenv/angular-gettext#19
Hello,
Thanks a lot for this useful work ! I always enjoyed the use of gettext, and using it with angular is awesome.
According to the documentation, we can use gettext factory to annotate strings in Javascript code
My current string Hello is well find after grunt extraction, translated with Poedit and compiled to be added to the translation.js file. Unfortunately, writing those lines won't actually translate the string Hello. The log message keeps to say "Hello" instead of "Hallo"
I checked the source code and I might found the problem. The factory called gettext simply returns the string. A comment explains that it enables grunt to extract strings without translations
I tried to use the gettextCatalog to find the translation and its seems to work fine.
Is there a problem in Javascript annotation ? Does my changes in your gettext factory a nice solution to you ?
The text was updated successfully, but these errors were encountered: