Translation with XTB files

426 views
Skip to first unread message

Edo

unread,
Jan 18, 2012, 11:31:31 AM1/18/12
to Closure Compiler Discuss, edo...@gmail.com
I've tried to localize scripts with Closure Compiler, unsuccessfully.

In JavaScript, strings to be translated should be marked this way:
/** @desc Search results header. */ var MSG_SEARCH_RESULTS =
goog.getMsg('Search results');

(The @desc annotation is required, but I'm not sure what it is about).

Then, I created a XTB file called 'fr.xtb':
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE translationbundle SYSTEM "translationbundle.dtd">
<translationbundle lang="fr">
<translation id="7639678437384034548">Résultats de la recherche</
translation>
</translationbundle>

Finally, I passed the XTB as a parameter to the compiler:
--translations_file=fr.xtb

But this doesn't work as the 'Search results' string stays as is in
the compiled script.
My problem is in the generation of the id attribute of
translationbundle tags in the XTB file. This is ID is generated from
the original string (and an optional Project ID string that can be
passed to the compiler using "--translations_project" parameter).

How can I compute the correct value for ID. What is the typical
workflow of localization used internally by Google (software used,
flow of data...)?

Chihiro Ito

unread,
Jan 21, 2012, 11:55:25 PM1/21/12
to Closure Compiler Discuss
> My problem is in the generation of the id attribute of
> translationbundle tags in the XTB file. This is ID is generated from
> the original string (and an optional Project ID string that can be
> passed to the compiler using "--translations_project" parameter).

I have modified the source of Closure Compiler to generate a proper
XTB file. It just an ugly patch for my private use, but I can open the
source code if you want it.
Message has been deleted

Edo

unread,
Feb 16, 2012, 2:39:39 PM2/16/12
to Closure Compiler Discuss
Hi,

January meeting note states that i18n is badly documented, so we might
get some enlightenment from Google soon (http://code.google.com/p/
closure-compiler/wiki/MeetingNotes).

But in the meantime, I would love to see your code so that I can use
this feature.
Thank you.

tep...@gmail.com

unread,
Mar 5, 2012, 11:30:57 PM3/5/12
to closure-comp...@googlegroups.com
Linking against compiler.jar, minimal code would be 

    // args[0]: project name
    // args[1]: file name
    public static void main(String[] args) throws IOException
    {        
        JsMessageExtractor extractor = new JsMessageExtractor(new GoogleJsMessageIdGenerator(args[0]), JsMessage.Style.CLOSURE);
        Collection<JsMessage> messages = extractor.extractMessages(SourceFile.fromFile(args[1]));
        for (JsMessage message : messages) {
            System.out.println("<translation id=\"" + message.getId() + "\">" + message.toString() + "</translation>");
        }
    }

You'll need to add the <translationbundle> wrapper, set the output encoding, and escape the message for serious usage. Placeholders not included (but see JsMessage.java if you want to implement support)
Reply all
Reply to author
Forward
0 new messages