gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.52k stars 376 forks source link

UIBinder doesn't reference LocalizableResource.properties for the default locale #5065

Open dankurka opened 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 5066

Found in GWT Release (e.g. 1.5.3, 1.6 RC): 2.0.3
Encountered on OS / Browser (e.g. WinXP, IE6-7, FF3): FF3.5.9
Detailed description (please be as specific as possible):

Let's say I have an internationalized message in a UIBinder.xml file, like this:

<ui:msg key='EMAIL_FIELD_LABEL'>Email</ui:msg>

If I create a file com.google.gwt.i18n.client.LocalizableResource_zz.properties with
content

EMAIL_FIELD_LABEL=zz_Email

Then when I display the application with locale="zz" (note that this is a dummy locale
I use for testing) then the application correctly displays "zz_Email" for the email
field.  In other words, it pulls it from the root LocalizableResource_zz.properties
file.

However, if I create a LocalizableResource.properties file for the *default* locale,
I would expect UIBinder to also use the value from this file.  It does *not* - it seems
to always use the value from the actual UIbinder.xml file.

The reason I want UIBinder to also pull the default value from the properties file
is that I may also reference these properties in Messages or Constants classes within
the application, and if I want to change the email field for the default locale (let's
say we decide to call it "Email/Username" instead of just "Email") I only want to have
to change it in one place.  With this approach I would need to change it in two places
- in the default LocalizableResource.properties file and then also in every UIBinder.xml
where it shows up.

Shortest code snippet which demonstrates issue (please indicate where
actual result differs from expected result): See above.

Workaround if you have one: None.

Links to relevant GWT Developer Forum posts:

Reported by constantin.tanno on 2010-06-28 15:29:58

dankurka commented 9 years ago
I don't think this has anything to do with UiBinder -- UiBinder generates a Messages
subtype that has the source in annotations, and the issue you are hitting is that LocalizableResourceGenerator
isn't consulting a properties file for the default locale preferentially over those
annotations.

Reported by jat@google.com on 2011-01-05 02:00:31

dankurka commented 9 years ago
I ran into the same problem and I think it is unexpected behavior. 

The UiBinder should overwrite its annotations with those from a default properties
file, if existing. 

Reported by robert.hoffmann.phd on 2012-06-14 09:10:56

dankurka commented 9 years ago
I don't think so. If you don't want to provide a @DefaultMessage (to fallback to using
a properties file), then I think you should use a <ui:msg> without content.
This however is not allowed currently.
(and I must say I disagree with John's analysis that properties files should override
annotations; but maybe I misunderstood)

Reported by t.broyer on 2012-06-14 10:25:34

dankurka commented 9 years ago
If we agree on the golden goal to separate competencies and logic from representation,
then we probably agree that it should be possible to manage textual appearance (in
general not just i18n) by writers or translators (‘texter’), without having to change
code or UiBinder xml. Also one would want only one place where texters get involved
(e.g. property files).

If one uses this as a guiding principle then the actual content of message annotations
in UiBinder is something that the user of an application should ideally never get to
see, because these messages are raw and not supervised by the texter.

This then identifies the purpose of message annotations in UiBinder as ‘natural language
variables/keys’. Indeed it seems a recommended practice to generate md5 keys (ui:generateKeys)
from these in annotations. https://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinderI18n

Also from a consistency point of view. Why should LocalizableResource_XX.properties
be able to overwrite the in-UIBinder annotations, but LocalizableResource_default.properties
not?

I think the hierarchy should be
1)  Use in-UiBinder annotations 
2)  Replace them, if the texter provides an alternative (i.e. via properties files).
Be it for a specific language or the default language (which might also be refined
over time independently from the xml).

Reported by robert.hoffmann.phd on 2012-06-14 12:17:11

dankurka commented 9 years ago
You can have the exact same reasoning about annotations in Constants or Messages itnerfaces,
so really UiBinder has nothing to do with the issue (besides currently forcing you
to generate these annotations).
Given your use case / organization, then I tend to agree with John that properties
files should override annotations, but this should probably be configurable (using
a <configuration-property>, defaulting to the current behavior of using annotations
over properties files).

Reported by t.broyer on 2012-06-14 13:21:22

dankurka commented 9 years ago
Exactly, doesn't the annotatin in UiBinder correspond to @defaultmessage in the Messages
interface? But this default annotation in Messages can indeed be overwritten by both
the LocalizedResources_LANGUAGE.properties and the LocalizedResources.properties. 
Just for uibinder LocalizedResources.properties doesn't overwrite. That's why I meant
that from the Messages mechanism perspective this behavior seems unexpected. Best Robert

Reported by robert.hoffmann.phd on 2012-06-14 14:21:14

dankurka commented 9 years ago
Right, this doesn't really have anything to do with UiBinder.  There is an open bug
(which I am unable to find at the moment) about translations in properties files not
overriding the annotations, which was intended so that localization could change them
without modifying the source.

So, the fix would be in the i18n generator's resource lookup instead of UiBinder. 
However, that code is getting completely rewritten so this would get fixed as part
of that rewrite.

Reported by jat@google.com on 2012-06-14 14:48:31