Subversion Repositories eFlore/Applications.cel

Rev

Rev 997 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 997 Rev 2613
Line 1... Line 1...
1
package org.tela_botanica.client.i18n;
1
package org.tela_botanica.client.i18n;
Line -... Line 2...
-
 
2
 
-
 
3
import org.tela_botanica.client.modeles.objets.Configuration;
-
 
4
import com.google.gwt.i18n.client.Dictionary;
2
 
5
 
3
/**
6
/**
4
 * Interface to represent the constants contained in resource bundle:
-
 
5
 * 	'/home/aurelien/web/cel_GWT2/src/org/tela_botanica/client/i18n/Messages.properties'.
7
 * Gère l'internationalisation 
-
 
8
 */
-
 
9
public class Messages {
-
 
10
 
-
 
11
	/** singleton */
-
 
12
	private static Messages instance;
-
 
13
 
-
 
14
	/** contient un dictionnaire de messages par langue */
-
 
15
	//protected Map<String, Dictionary> langues;
-
 
16
	/** langue en cours */
-
 
17
	protected String langue;
-
 
18
	/** langue par défaut */
-
 
19
	protected String langueDefaut;
-
 
20
	/** langues disponibles */
-
 
21
	protected String languesDisponibles;
-
 
22
 
-
 
23
	public Messages getInstance() {
-
 
24
		if (instance == null) {
-
 
25
			instance = new Messages();
-
 
26
		}
-
 
27
		return instance;
-
 
28
	}
-
 
29
 
-
 
30
	private Messages() {
-
 
31
		//this.langues = new HashMap<String, Dictionary>();
-
 
32
		// lire la config pour obtenir les langues
-
 
33
		languesDisponibles = "fr,en"; //Configuration.getLanguesDisponibles();
-
 
34
 
6
 */
35
		// lire la config et charger la langue par défaut
-
 
36
		langueDefaut = "fr"; //Configuration.getLangueDefaut();
-
 
37
		setLangue(langueDefaut);
-
 
38
	}
-
 
39
 
-
 
40
	public void setLangue(String langue) {
-
 
41
		// @TODO vérifier que la langue est une clé de la Map
-
 
42
		this.langue = langue;
-
 
43
	}
-
 
44
 
-
 
45
	/**
-
 
46
	 * Retourne un message dans la langue en cours
-
 
47
	 * @param cle
-
 
48
	 * @return
-
 
49
	 */
-
 
50
	public String getMessage(String cle) {
-
 
51
		return getMessage(cle, langue);
7
public interface Messages extends com.google.gwt.i18n.client.Constants {
52
	}
-
 
53
 
-
 
54
	/**
-
 
55
	 * Retourne un message dans la langue demandée; s'il n'est pas trouvé, le cherche
-
 
56
	 * dans la langue par défaut; en cas d'échec, retourne un terme générique d'avertissement
-
 
57
	 * @param cle
-
 
58
	 * @param langue
-
 
59
	 * @return
-
 
60
	 */
-
 
61
	public String getMessage(String cle, String langue) {
-
 
62
		String nomDictionnaire = "messages_" + langue;
-
 
63
		String message;
-
 
64
		try {
-
 
65
			message = Dictionary.getDictionary(nomDictionnaire).get(cle);
-
 
66
		} catch (Exception e) {
-
 
67
			try {
-
 
68
				message = Dictionary.getDictionary("messages_" + langueDefaut).get(cle);
-
 
69
			} catch (Exception me) {
-
 
70
				message = "hoho c'est la merde";
-
 
71
			}
-
 
72
		}
-
 
73
		return message;
8
  
74
	}