[cal10n-dev] Better annotations?

Ralph Goers ralph.goers at dslextreme.com
Fri Sep 4 18:20:19 CEST 2009


On Sep 4, 2009, at 3:35 AM, Ceki Gulcu wrote:

>
>
> As you can see, the @LocaleData annotation includes multiple @Locale
> annotations. This is more verbose than what we had previously but
> allows us to write:
>
> @BaseName("colors")
> @LocaleData(
>  defaultCharset="UTF8",
>  value = { @Locale("en_UK"),
>            @Locale("fr_FR"),
>            @Locale( value="tr_TR", charset = "ISO8859_3"),
>            @Locale( value="el_GR", charset = "ISO8859_7")
>           }
>   )
> public enum Colors {
> BLUE,
> RED,
> GREEN;
> }
>
> It would have been preferable to write
>
> @BaseName("colors")
> @Locale("en_UK")
> @Locale( value="fr_FR", charset = "ISO8859_1")  // compiler error
> @Locale( value="tr_TR", charset = "ISO8859_3")  // compiler error
> @Locale( value="el_GR", charset = "ISO8859_7")  // compiler error
> public enum Fruit {
>  APPLE, ORANGE;
> }

This is fragile as it will break if someone uses a different charset  
than what is now hardcoded in the software. This information should be  
obtained from the file itself.

>
> but the compiler forbids multiple instances of the same annotation.
>
> Can you think of a more elegant approach which still allows the user
> to designate the charset for a given locale?

Yes. At the risk of repeating myself, build your framework using XML  
files and let the XML parser use the encoding specified in the file.  
Property files were not designed for this.  If you insist on using  
ResourceBundles then require Java 6 and use XML prooperty files and  
ResourceBundle.Control as described at http://java.sun.com/javase/6/docs/api/java/util/ResourceBundle.Control.html 
  in Example 2.

Ralph



More information about the cal10n-dev mailing list