Google Closure templates generate multiple JavaScript files for each language instead of a separate JavaScript code base with separate resource files

I am using the Google Closure template to write the application interface using JavaScript. Have a look at this question to find out why I use the Google Closure template. I want him to be multilingual. I see that there is a switch --locales, and also looked at the samples presented in the project here and here . The README_FOR_EXAMPLES files say that

+ simple_generated_en.js, features_generated_en.js,
simple_generated_x-zz.js, features_generated_x-zz.js JS files created by SoyToJsSrcCompiler when they run on simple.soy and features.soy (locales are "en" and "x-zz with translated XLIFF files from examples of examples examples of common examples and with the above global glosses for compiling a file). We need both simple.soy and features.soy, because some of the templates in feature.soy call templates in simple.soy. Note. For an example of the Ant target (and the args command line) that generates these files, see the target "js-features-example" in the top level "build.xml".

I expected that it would generate only one JavaScript code base, which would use the necessary lines from the corresponding locale file based on the option provided at runtime, before calling the template function. Is this possible with closing patterns?

+1
source share
1 answer

As far as I can tell, you can use the object dictionary as a parameter for your template.

/**
 * @param dict
 */
{template .example}
    <h1>{$dict.title}</h1>
    <div>{$dict.content}</div>
{/template}

This object can be generated on the server side from your locale file and transferred to javascript via the script tag.

Otherwise, you can upload another file of the compiled template to the client side in accordance with the locale.

i18n , , imo.

+1

All Articles