Bonjour,
J'étudie GWT et j'ai un gros problème avec l'internationalisation.
Le projet ressemble à ça:
Mon fichier de config à ça (en gras ce qui est ajouté):
La classe de message:
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 <?xml version="1.0" encoding="UTF-8"?> <module rename-to='internationalisation'> <!-- Inherit the core Web Toolkit stuff. --> <inherits name='com.google.gwt.user.User'/> <inherits name="com.google.gwt.i18n.I18N"/> <extend-property name="locale" values="fr" /> <extend-property name="locale" values="en" /> <!-- Inherit the default GWT style sheet. You can change --> <!-- the theme of your GWT application by uncommenting --> <!-- any one of the following lines. --> <inherits name='com.google.gwt.user.theme.clean.Clean'/> <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> --> <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> --> <!-- Other module inherits --> <!-- Specify the app entry point class. --> <entry-point class='com.internationalisation.client.Internationalisation'/> <!-- Specify the paths for translatable code --> <source path='client'/> <source path='shared'/> </module>
Le fichier de properties français:
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 package com.internationalisation.client.donnee; import com.google.gwt.i18n.client.Messages; public interface MesMessages extends Messages{ public String bonjour(String nom); public String nom(); public String nombreDeChat(); public String chat(@PluralCount int nbChat); public String erreurNom(); public String notAInt(); public String negatif(); public String pasDeChat(); }
Le français:
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 bonjour=Hello, how are you {0}? nom=Name nombreDeChat=Number of cats chat=You have {0} cats chat[one]=You have a cat chat[zero]=You have no cats erreurNom=The name is required notAInt=The number of cats is a number negatif=The number of cats is not negative pasDeChat=The number of cat is required
Le handler:
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 bonjour=Boujour, comment allez vous {0}? nom=Nom nombreDeChat=Nombre de chats chat=Vous avez {0} chats chat[one]=Vous avez un chat chat[zero]=Vous ne possédez pas de chats. erreurNom=Le nom doit être renseigné notAInt=Le nombre de chats est un nombre negatif=Le nombre de chats ne peut pas etre négatif pasDeChat=Le nombre de chat n'est pas renseigné
Et la classe d'entrée:
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 package com.internationalisation.client.handler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.TextBox; import com.internationalisation.client.donnee.MesMessages; public class HandlerButton implements ClickHandler{ public TextBox textNom, textChat; public MesMessages mesMessages; public HandlerButton(TextBox textNom, TextBox textChat, MesMessages mesMessages){ this.textNom = textNom; this.textChat = textChat; this.mesMessages = mesMessages; } @Override public void onClick(ClickEvent event) { String sNom = textNom.getText(); if(sNom == null || sNom.equals("")){ Window.alert(mesMessages.erreurNom()); } else{ String sChat = textChat.getText(); if(sChat == null || sChat.equals("")){ Window.alert(mesMessages.pasDeChat()); } else{ int chat = 0; try{ chat = Integer.parseInt(sChat); } catch (Exception e) { Window.alert(mesMessages.notAInt()); return; } if(chat < 0){ Window.alert(mesMessages.negatif()); } else{ Window.alert(mesMessages.bonjour(sNom)); Window.alert(mesMessages.chat(chat)); } } } } }
***************
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 package com.internationalisation.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TextBox; import com.internationalisation.client.donnee.MesMessages; import com.internationalisation.client.handler.HandlerButton; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class Internationalisation implements EntryPoint { @Override public void onModuleLoad() { RootPanel rootPanel = RootPanel.get(); HorizontalPanel hp = new HorizontalPanel(); MesMessages messages = (MesMessages)GWT.create(MesMessages.class); hp.add(new Label(messages.nom())); TextBox textNom = new TextBox(); hp.add(textNom); rootPanel.add(hp); hp = new HorizontalPanel(); hp.add(new Label(messages.nombreDeChat())); TextBox textChat = new TextBox(); hp.add(textChat); rootPanel.add(hp); hp = new HorizontalPanel(); Button button = new Button("Test"); button.addClickHandler(new HandlerButton(textNom, textChat, messages)); hp.add(button); rootPanel.add(hp); } }
J'obtiens ça:
Avec dans l'ordre en gras l'erreur sur la console d'erreur d'Eclipse):
Si quelqu'un peu m'aider, merci d'avance, là, je bloque vraiment....[ERROR] [internationalisation] - Deferred binding failed for 'com.internationalisation.client.donnee.MesMessages'; expect subsequent failures
14:50:14.406 [ERROR] [internationalisation] Deferred binding failed for 'com.internationalisation.client.donnee.MesMessages'; expect subsequent failures
[ERROR] [internationalisation] - Unable to load module entry point class com.internationalisation.client.Internationalisation (see associated exception for details)
14:50:14.421 [ERROR] [internationalisation] Unable to load module entry point class com.internationalisation.client.Internationalisation (see associated exception for details)
java.lang.RuntimeException: Deferred binding failed for 'com.internationalisation.client.donnee.MesMessages' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.internationalisation.client.Internationalisation.onModuleLoad(Internationalisation.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.internationalisation.client.Internationalisation.onModuleLoad(Internationalisation.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
[ERROR] [internationalisation] - Failed to load module 'internationalisation' from user agent 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; InfoPath.1)' at localhost:1503
14:50:14.437 [ERROR] [internationalisation] Failed to load module 'internationalisation' from user agent 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; InfoPath.1)' at localhost:1503
Partager