How to localize javascript files in gates

Hallo, Wicket i18n question: I have a javaScript file that contains lines that I want to localize. Ideally, I want to localize the entire file. Sort of

  • my.js
  • my_de.js
  • my_fr.js
  • ...

where the gate automatically selects the right js file, as happens with property files.

Does anyone know how to do this?

+5
source share
2 answers

Pass the locale to the resource link:

class MyPage extends WebPage implements IHeaderContributor {
    public void renderHead(IHeaderResponse response) {
        response.renderJavascriptReference(new ResourceReference(
        MyPage.class, "my.js", getLocale(), getStyle()));
    }
}
+8
source

, Javascript. , Javascript? XML YourPageJS.xml Javascript, .

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>

    <entry key="showModal">
    <![CDATA[ 

        $(''#{0}'').modal(''show'',{1});

    ]]>
    </entry>
</properties>

, , :

    public static String getJsByClass(Class clazz, String name, Object... params)
    {
        ResourceBundle resources = ResourceBundle.getBundle(clazz.getName()
                + "JS", Locale.getDefault(),
                new XMLResourceBundleControl());

        String mesaj = resources.getString(name);
        mesaj = MessageFormat.format(mesaj, params);

        return mesaj;
    }

:

YourUtils.getJsByClass(YourPage.class, "showModal" ,"firstParameter","secondParameter");

. . html- :

response.render(JavaScriptHeaderItem.forScript(YourUtils.getJsByClass(YourPage.class, "showModal" ,"firstParameter","secondParameter"), "yourJSid")); ( 6)

, XML : ' '' { '{' .

0

All Articles