...
- Follow the standards described in this guide
- Always use properties files for user interface text; never include displayable text in java, jsp, or templates (see Localizing Tools below)
- Use properties files only for user interface text and config files for configuration settings (see Config Properties below).
- Use a proper naming schema for keys in your resource bundles. The name of the keys should provide some information about the context of the displayed text. This helps the translators during the translation process. A naming schema could be
<view>.<type>.<name>
. Examples:edit.button.save
,edit.label.title
orlist.action.addnew
- Group keys by view, ie.
edit.title
,edit.instructions
,list.title
,list.instructions
,create.title
, etc - Never use displayable text when executing comparisons within the logic of the tool (separate codified values from displayable text)
- Always use the ResourceLoader (not ResourceBundle) class for retrieving properties values, and invoke ResourceLoader methods dynamically, to accommodate dynamic user preferences (see Resource Loader below).
- All dynamically constructed phrases must be sensitive to locale specific subject/verb/object ordering by using the Sakai ResourceLoader class: org.sakaiproject.util.ResourceLoader.getFormattedMessage() (see Structure messages appropriately below)
- All numbers and dates should be formatted specific to the user's locale (e.g. java.text.NumberFormat and java.text.DateFormat)
- Test tools in more than one language
...
Here's an example of creating a DateFormat object to format a date according to local conventions:
Code Block |
---|
DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT, (new ResourceLoader()).getLocale() );
|
Here's an example of creating a DateFormat object to format a date according to local conventions, and extracting the pattern string for later use:
Code Block |
---|
DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT, (new ResourceLoader()).getLocale() );
date_entry_format_description = ((SimpleDateFormat)df).toPattern();
|
Config Properties
Anchor | ||||
---|---|---|---|---|
|
...
Code Block |
---|
import java.util.Properties;
...
Properties p = new Properties();
p.load(this.getClass().getResourceAsStream("filename.config"));
|
...
The org.sakaiproject.util.java.ResourceLoader class is a wrapper class for the ResourceBundle class. It provides dynamic language/locale support for individual users, and is recommended for all Sakai tools.
The sakai-util.jar file (or sakai-util-java.jar file prior to Sakai 2.2) needs to be included with every tool during the maven build process, by including the following dependency in the tool's project.xml file:
Code Block |
---|
<dependency>
<groupId>org.sakaiproject</groupId>
<artifactId>sakai-util</artifactId>
<version>${sakai.version}</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
</dependency>
|
Since Sakai 2.6 (Kernel 1.0+), this is now sakai-kernel-util:
Code Block |
---|
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-util</artifactId>
</dependency>
|
Strings in the tool's properties file can be retrieved in the Java code using the ResourceLoader class:
Code Block |
---|
ResourceLoader rb = new ResourceLoader("_org.sakaiproject.tool.foobar.bundle.Messages_"); String foo = rb.getString("foo"); |