Le Sun, 17 Oct 2010 16:53:37 +0200 (CEST), bleny at users.labs.libre-entreprise.org a écrit :
Author: bleny Date: 2010-10-17 14:53:36 +0000 (Sun, 17 Oct 2010)
+ * This enumeration represents the different levels of trust that can accorded to + * a contact and to the data she provided. + * + * @author bleny + */ +public enum DataReliability { + + /** Data reliability has not been evaluated yet (?% trust). */ + UNKNOWN("wao.business.bean.DataReliability.unknown"), + + /** Data are not reliable (0% trust). */ + NOT_RELIABLE("wao.business.bean.DataReliability.not_reliable"), + + /** Data are doubtful (50% trust). */ + DOUBTFUL("wao.business.bean.DataReliability.doubtful"), + + /** Data are trustworthy (100% trust). */ + RELIABLE("wao.business.bean.DataReliability.reliable"); + + /** An i18n key to make enumeration printable in logs and UI. */ + protected String label; + + DataReliability(String label) { + this.label = label; + } + + /** Get a translated name for the current value. */ + public String getLabel() { + return _(label); + } + + public static DataReliability valueOf(int ordinal) { + for (DataReliability dataReliability : DataReliability.values()) { + if (dataReliability.ordinal() == ordinal) { + return dataReliability; + } + } + return null; + } +}
Je ne pense pas que ce soit bon pour l'i18n, il faut garder les clés jusqu'a l'UI pour passer par Tapestry pour la trad (switch anglais/francais). Donc il faudrait plutot ca :
+ UNKNOWN(n_("wao.business.bean.DataReliability.unknown")), ... + + /** Get a translated name for the current value. */ + public String getLabel() { + return label; + }
le n_ gardera la clé mais sera parsé par i18n. Avec le goal tapestry-bundle, les clés seront poussés dans le app.properties de Tapestry. Pour la trad il faut utiliser le moteur de Tapestry avec Messages : @Inject private Messages messages; ... public String getDataReliabilityLabel() { return messages.get(dataReliability.getLabel()); } Regarder dans Pollen pour plus d'exemple. L'alternative serait d'améliorer nuiton-i18n pour le support du switch à la volé des langues. Ainsi la trad pourra être fait dans le business. Il suffira de synchro le changement de langue d'i18n avec celui de Tapestry. -- Florian Desbois <fdesbois at codelutin.com> SSLL Code Lutin http://www.codelutin.com tel : 02 40 50 29 28 Réseau Libre-Entreprise