1,9 → 1,75 |
package org.tela_botanica.client.i18n; |
|
import org.tela_botanica.client.modeles.objets.Configuration; |
import com.google.gwt.i18n.client.Dictionary; |
|
/** |
* Interface to represent the constants contained in resource bundle: |
* '/home/aurelien/web/cel_GWT2/src/org/tela_botanica/client/i18n/Messages.properties'. |
* Gère l'internationalisation |
*/ |
public interface Messages extends com.google.gwt.i18n.client.Constants { |
|
public class Messages { |
|
/** singleton */ |
private static Messages instance; |
|
/** contient un dictionnaire de messages par langue */ |
//protected Map<String, Dictionary> langues; |
/** langue en cours */ |
protected String langue; |
/** langue par défaut */ |
protected String langueDefaut; |
/** langues disponibles */ |
protected String languesDisponibles; |
|
public Messages getInstance() { |
if (instance == null) { |
instance = new Messages(); |
} |
return instance; |
} |
|
private Messages() { |
//this.langues = new HashMap<String, Dictionary>(); |
// lire la config pour obtenir les langues |
languesDisponibles = "fr,en"; //Configuration.getLanguesDisponibles(); |
|
// lire la config et charger la langue par défaut |
langueDefaut = "fr"; //Configuration.getLangueDefaut(); |
setLangue(langueDefaut); |
} |
|
public void setLangue(String langue) { |
// @TODO vérifier que la langue est une clé de la Map |
this.langue = langue; |
} |
|
/** |
* Retourne un message dans la langue en cours |
* @param cle |
* @return |
*/ |
public String getMessage(String cle) { |
return getMessage(cle, langue); |
} |
|
/** |
* Retourne un message dans la langue demandée; s'il n'est pas trouvé, le cherche |
* dans la langue par défaut; en cas d'échec, retourne un terme générique d'avertissement |
* @param cle |
* @param langue |
* @return |
*/ |
public String getMessage(String cle, String langue) { |
String nomDictionnaire = "messages_" + langue; |
String message; |
try { |
message = Dictionary.getDictionary(nomDictionnaire).get(cle); |
} catch (Exception e) { |
try { |
message = Dictionary.getDictionary("messages_" + langueDefaut).get(cle); |
} catch (Exception me) { |
message = "hoho c'est la merde"; |
} |
} |
return message; |
} |
} |