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

context support for extracting strings from javascript

Open mockingbird-z opened this issue 9 years ago • 4 comments

I know the extractor supports the externalizing the translate-context for the html file. Does it have the corresponding support for the javascript file?

Based on the api, I have gettextCatalog.getString("me", scope, "recipient") in my javascript. I did not see the generated .po file having the entry "msgctxt": "recipient".

Locally, I can make the extractor work for the js file by modifying the walkJs of Extractor.prototype.extractJs method.

if (isGettext(node) || isGetString(node)) {
    str = getJSExpression(node.arguments[0]);
    context = node.arguments[2] ? getJSExpression(node.arguments[2]) : null;
} else if (isGetPlural(node)) {
    singular = getJSExpression(node.arguments[1]);
    plural = getJSExpression(node.arguments[2]);
    context = node.arguments[4] ? getJSExpression(node.arguments[4]) : null;
}
if (str || singular) {
    var leadingComments = node.leadingComments || (parentComment ? parentComment.leadingComments : []);
    leadingComments.forEach(function (comment) {
        if (comment.value.match(/^\/ .*/)) {
            extractedComments.push(comment.value.replace(/^\/ /, ''));
        }
    });

    if (str) {
        self.addString(reference, str, plural, comments2String(extractedComments), context);
    } else if (singular) {
        self.addString(reference, singular, plural, comments2String(extractedComments), context);
    }
}

Can the similar fix be added into the next release?

mockingbird-z avatar Mar 27 '15 17:03 mockingbird-z

any updates for the same? how to provide context for strings extracted from javascript file?

NVK15 avatar Jun 04 '15 09:06 NVK15

+1. Is this still unavailable?

pySilver avatar Nov 11 '15 02:11 pySilver

Is that merged or not?

pySilver avatar Jan 08 '16 07:01 pySilver

@mockingbird-z what is the status of this issue? pending? Because I encounter the same problem here...

EpokK avatar Apr 07 '16 09:04 EpokK