Monday, December 30, 2013

Re: Completely lost at internationalization (i18n)



On Monday, December 23, 2013 11:24:20 PM UTC+1, Qunit wrote:
I'm completely stumped on I18n. Any help would be greatly appreciated. Here's my info:
- Using mvn 3.0.5
- Using uiBinder
- GWT 2.5.1 with GWTBootstrap
- Eclipse 4.2 with maven integration

All working, except when trying to add I18n for dutch (nl, default) and english (en)

Part of .gwt.xml

<inherits name="com.google.gwt.i18n.I18N" />
<extend-property name="locale" values="nl" />
<extend-property name="locale" values="en" />
<set-property-fallback name="locale" value="en"/>
<set-property name="locale" value="nl"/>


That last line is saying that only "nl" locale will actually be compiled. You probably want value="nl,en", though I've been told that removing the 'default' locale might break a few things (haven't personally noticed anything though).
 
Example part of uiBinder:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys="com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator"
ui:generateLocales="default"

You disabled the 'default' locale, so maybe you'll want ui:generateLocales="en, nl"


…or maybe you meant ui:defaultLocale="en" ? (equivalent to @DefaultLocale)
 

>
<b:Container>
<b:Container ui:field="signupContainer">
<b:Row>
<b:Paragraph><ui:msg description="Enter user details">Please enter your details to signup</ui:msg></b:Paragraph>
</b:Row>

Part of pom.xml:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<i18nMessagesBundle>com.mongoasis.presentation.i18n.Messages</i18nMessagesBundle>
<runTarget>mongoasis.html</runTarget>
<draftCompile>true</draftCompile>
<optimizationLevel>1</optimizationLevel>
<extraParam>true</extraParam>
</configuration>
</plugin>

According to some documentation I should be able to generate property files using mvn install or mvn gwt:i18n.

"mvn gwt:i18n" is about generating com.google.gwt.i18n.client.Messages interfaces from existing .properties files (from your src/main/resources folder), so it's not what you want here.
 

However doing that results in errors/warnings the the com.mongoasis.presentation.i18n.Messages file could not be found.

This is probably because gwt:i18n cannot find a com/mongoasis/presentation/i18n/Messages.properties file in src/main/resources (that's the name you gave in i18nMessagesBundle, which is a configuration property for the gwt:i18n goal).
Because of that error, your build fails and the GWT compiler (that would generate properties files from your UiBinder templates) is not run (gwt:i18n runs a generate-sources while gwt:compile runs at prepare-package, which is much later in the Maven lifecycle)
 

So I create it manually after which it complains that it is ampty. Adding random key-value pairs stops the error message, but nowhere I find MD5 hashed properties to fill in. Event specifying the key manually does not result in the text being replaced with any translated text.

I'm felling lost and alone in a dark world... Who enlightens me?


First, don't use gwt:i18n unless you know you need it. It's only useful for a few specific cases, and even more-specific cases if you consider binding it to the build lifecycle.

The gwt:compile should then generate properties files the <extra> folder (which defaults to target/extra). You'll have to copy those files to your src/main/resources (keeping the same folder hierarchy and file name, possibly making copies for the different locales) and then tweak them. In the subsequent calls to gwt:compile, GWT will use them as sources so the correct translations will appear in the generated JavaScript code. You'll only see the result in DevMode or once compiled to JS.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment