angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

gettext function with context

Open MigFerreira opened this issue 9 years ago • 2 comments

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"});
});

MigFerreira avatar Jun 28 '16 13:06 MigFerreira

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 ?

tpenne avatar Aug 25 '16 09:08 tpenne

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

vorant avatar Sep 14 '16 07:09 vorant