angular-gettext
angular-gettext copied to clipboard
gettext function with context
Why in case of gettext context is set as comment?
angular.module("myApp").controller("helloController", function (gettext) {
/// Verb
var myString = gettext("File");
});
This is usually an inconvenient when comments are set to be removed by typescript. Is the following not considered good practice?
angular.module("myApp").controller("helloController", function (gettext) {
var myString = gettext("File","Verb");
or
var myString = gettext("File",{context:"Verb"});
});
angular.module("myApp").controller("helloController", function (gettext) {
/// Verb
var myString = gettext("File");
});
With this, Verb is not considered as context but really as comment.
As far as I know there is no way to add context using the gettext function in javascript.
It turns out I seem to be needing it in my project as I translate dynamic text in a directive view template so I have to declare all the possible texts in javascript controller for extraction and one of these texts needs context for french translation.
I found your first proposal appealing
angular.module("myApp").controller("helloController", function (gettext) {
var myString = gettext("File","Verb");
});
GNU gettext implements it in pgettext function https://www.gnu.org/software/gettext/manual/gettext.html#Contexts
Could this be added ?
I found solution
angular.module("myApp").controller("helloController", function (gettext) {
/// just comment
var myString = gettext("File", null, "Verb");
});
Parser uses 3 arguments:
1- string for translation
2 - scope, but for gettext function it never uses
3 - context
You may figure out it at angular-gettext-tools https://github.com/rubenv/angular-gettext-tools This is how parser works https://github.com/rubenv/angular-gettext-tools/blob/master/lib/extract.js#L264