Bonjour,
Je suis actuellement confronté à un problème de changement de langues. J'ai mis en place un systeme en suivant le tutoriel de sun concernant les changement de langues http://java.sun.com/docs/books/tutorial/i18n/TOC.html qui marche merveilleusement bien pour le passage Français Anglais et inversement. Cependant, j'ai une troisième langue à ajouter, qui est le japonais.
Tout d'abbord, voici ma classe de gestion des langues :
Donc quand j'appelle via mon interface graphique setCurrentLanguage() avec en paramètre "English" ou "French" tout se passe bien, il va bien chercher dans les fichiers "Facturation_en_US.properties" et "Facturation_fr_FR.properties". Quand je passe Japanese, il ne va pas chercher dans le fichier "Facturation_ja_JP.properties" mais dans le fichier "Facturation.properties".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 import java.util.Locale; import java.util.ResourceBundle; /** * This class is to manage all languages switches **/ public class LanguageManager { public static final Locale ENGLISH_LANGUAGE; public static final Locale FRENCH_LANGUAGE; public static final Locale JAPANESE_LANGUAGE; private static final String[] languagesList; private static Locale currentLanguage; private static ResourceBundle messages; private static String currentLanguageString; /** *Init static variables and constants **/ static { languagesList=new String[] { "Francais", "English", "Japanese" }; ENGLISH_LANGUAGE=new Locale("en","US"); FRENCH_LANGUAGE=new Locale("fr","FR"); JAPANESE_LANGUAGE=new Locale("ja","JP"); currentLanguage=ENGLISH_LANGUAGE; messages=ResourceBundle.getBundle("Facturation",currentLanguage); currentLanguageString = "English"; } /** * Returns the Languages that can be used by the software. * @returns a String array containing all languages **/ public static String[] getLanguagesList() { return languagesList; } /** * **/ public static String getLocalizedText(String text) { System.out.println(text+" "+messages.getString(text)); return messages.getString(text); } /** * This function is to change Language. * @param newLanguage The language to change to. The param should be one of the languages of the <a href="LanguageManager.html#getLanguagesList()">getLanguagesList()</a> array. If another String is given, nothing happens. **/ public static void setCurrentLanguage(final String newLanguage) { boolean change=false; if(newLanguage.equalsIgnoreCase("Francais")) { currentLanguage=FRENCH_LANGUAGE; currentLanguageString="Francais"; change=true; } else if (newLanguage.equalsIgnoreCase("English")) { currentLanguage=ENGLISH_LANGUAGE; currentLanguageString="English"; change=true; } else if (newLanguage.equalsIgnoreCase("Japanese")) // à changer en caractères japonais { currentLanguage=JAPANESE_LANGUAGE; currentLanguageString="Japonais"; change=true; } if(change) { messages=ResourceBundle.getBundle("Facturation",currentLanguage); } } /** *This functions returns the current language *@return The current language **/ public static Locale getCurrentLanguage() { return currentLanguage; } public static String getCurrentLanguageString() { return currentLanguageString; } }
Voici mon premier problème, pourquoi ne va-t-il pas chercher dans le fichier local et va-t-il dans le fichier par défaut ?
Ensuite, j'ai voulu tester de mettre des caractères japonais dans le fichier .properties par défaut encodé en UTF-8. Je vous le mets en fichier joint (j'ai chagé l'extension du fichier parceque sinon le forum ne l'acceptait pas). Java ne les affiche pas bien. Il affiche n'importe quoi, comme si il ne pouvait pas gérer ces caractères.
Je précise que mon affichage se fait sur des boutons, et que je fais un setText() sur ces boutons à chaque fois que je change de langue, ainsi qu'un setLocale juste avant à la locale définie dans mon fichier LanguageManager.
Comment remédier à ces problèmes ?
Voici quelques heures que j'y suis et je ne trouve pas de solution pour le japonais...
Merci
Fred
Partager