eEcho blog

is een halte van de gedachte

Constants, Messages, Dictionary

GWT biedt vier alternatieven voor de vertaalde tekst:

Constants
Dit type kan alleen worden gebruikt voor gegevens,
Zoals veld etiketten of de namen van menu-items. Het kan ook worden
Gebruikt voor nummers, Booleans, en Maps.

ConstantsWithLookup
Dit is hetzelfde als de Constants maar een constante met een dynamische string (later meer hierover).

Messages
Dit zijn algemene strings sjablonen die kunnen vervangt worden met argumenten.

Dictionary
De meest flexibele, maar minst efficiënte van alle keuzes.

Maak een bestand met constants die zullen vertaald worden MyConstants.java

public interface MyConstants extends Constants {
String helloWorld();
String goodbyeWorld();
}

Volgende bestand is MyConstants.properties met inhoud:

helloWorld = hello, world
goodbyeWorld = goodbye, world

Dan nog een bestand met eigenschappen maar in andere taal MyConstants_sp.properties :

helloWorld = hola, mundo
goodbyeWorld = adiós, mundo

Deze eigenschappen worden gebruikt:

public void useMyConstants() {
MyConstants myConstants = (MyConstants) GWT.create(MyConstants.class);
Window.alert(myConstants.helloWorld());
}

.properties zou moeten in UTF-8 opgeslagen worden.

Add A Comment

You must be logged in to post a comment.

Home | info@eecho.info | Voorwaarden | Blog