Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have actually achieved a runtime i18n. I use .soy templates with <code>{msg}</code> tags in them. When you compile .soy to .js, these calls get compiled to goog.getMsg calls. What I had to do was:</p> <ol> <li>Find all <code>.js</code> files that had <code>goog.getMsg(</code> in them</li> <li>Prepend <code>goog.require("myApp.i18n");\n</code></li> <li>Replace all <code>goog.getMsg(</code> calls with <code>myApp.i18n.translate(</code></li> <li>Replace all <code>MSG_*</code> property names with <code>myprefix_MSG_*</code></li> </ol> <p>Why all this: One cannot override goog.getMsg directly, because it is considered a compiler primitive and does not allow any manipulation whatsoever. Same applies for <code>MSG_*</code> properties.</p> <p><code>myApp.i18n.translate</code> is a function that accepts string, tries to look it up in a locale map (which is passed in runtime) and returns <code>goog.getMsg</code> result using the localized string (<code>goog.getMsg</code> does some handy placeholder replacements).</p> <p>While this is not a very pretty solution, it works and allows me to change language in runtime, using only one compiled file for all languages.</p> <p>The actual code includes a few hacks that allows me to use the generated description and use JSON files instead of the strange-looking closure file format, but the gist is the same.</p> <h2>However!</h2> <p><strong>What you really should do is to compile several files from your app and load different .js file for every language.</strong></p> <p>I had to use this solution, because I need to support hundreds of different configurations and several languages: it would be insane to compile thousands of .js files, when one compilation takes 30+ seconds.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload