Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added Czech to list of built-in locacles

...

  • Using the "message:" binding expression in a component template
  • By injecting the component's Messages object
    In the first case, you may use the message: binding prefix with component parameters, or with template expansions:
Code Block
java
java

<t:layout title="message:page-title">

  ${message:greeting}, ${user.name}!
  
  . . .
</t:layout>

...

You would extend this with a set of properties files:

Code Block
java
java

page-title=Your Account
greeting=Welcome back

Or, perhaps, a French version:

Code Block
java
java

page-title=Votre Compte
greeting=Bienvenue en arriere

Programatically, you may inject your component message catalog into your class, as an instance of the Messages interface:

Code Block
java
java

  @Inject
  private Messages messages;

You could then get() messages, or format() them:

Code Block
java
java


  public String getCartSummary()     
  {
    if (items.isEmpty())
      return messages.get("no-items");
      
    return messages.format("item-summary", _items.size());
  }

The format() option works using a java.util.Formatter, with all the printf-style loveliness you've come to expect:

Code Block
java
java

no-items=Your shopping cart is empty.     
item-summary=You have %d items in your cart.

...

Code Block
java
titleToggle between English and German
java

@Inject 
private PersistentLocale persistentLocale;

void onActionFromLocaleToggle() {
    if ("en".equalsIgnoreCase(persistentLocale.get().getLanguage())) {
        persistentLocale.set(new Locale("de"));
    } else {
        persistentLocale.set(new Locale("en"));
    }
    return this;
}
public String getDisplayLanguage() {
    return persistentLocale.get().getDisplayLanguage();
}

...

While your application can support any locale (and thus any language) that you want, Tapestry provides only a limited set of translations for its own built-in messages. As of Tapestry 5.3, the following locales have translations provided:

en (English)

el (Greek)

it (Italian)

pl (Polish)

vi (Vietnamese)

bg (Bulgarian)

es (Spanish)

ja (Japanese)

pt (Portuguese)

zh (Chinese) bg

cs (BulgarianCzech)1

fi (Finnish)

mk (Macedonian)

ru (Russian)

 

da (Danish)

fr (French)

nl (Dutch)

sr (Serbian)

 

de (German)

hr (Croatian)

no (Norwegian)

sv (Swedish)

 

el (Greek)

it (Italian)

pl (Polish)

vi (Vietnamese)

 

as of Tapestry 5.3.8

Providing translations for Tapestry built-in messages

Fortunately, Tapestry uses all the same mechanisms for its own locale support as it provides for your application. So, to support other locales, just translate the built-in message catalog (property) files yourself:

 

HTML

...

<style type="text/css">table.sectionMacro { width: auto; }</style>
Section
widthauto
Column
Column

To have Tapestry use these new files, just put them in the corresponding package-named directory within your own app (for example, src/main/resources/org/apache/tapestry5/core.properties).

...