On Fri, 2006-12-22 at 00:04 +0100, Joel Uckelman wrote:
> Internationalization support is something we
> something we probably should add. (I'm not sure
> what facilities Java provides for this
Check out java.util.ResourceBundle
Here's a quick example:
1. Create a text file named Test_en_US.properties with:
myapp.Prompt1=Hello
myapp.Prompt2=Goodbye
2. Create a text file named Test_es_SP.properties with:
myapp.Prompt1=Hola
myapp.Prompt2=Adios
3. A class to use them:
import java.util.ResourceBundle;
import java.util.Locale;
public class TranslatedPrompts {
public static void main(String[] args) {
// show en_US versions
ResourceBundle rb =
ResourceBundle.getBundle("Test",new Locale("en","US"));
System.out.println(rb.getString("myapp.Prompt1"));
System.out.println(rb.getString("myapp.Prompt2"));
// switch to es_SP versions
rb = ResourceBundle.getBundle("Test",new Locale("en","US"));
System.out.println(rb.getString("myapp.Prompt1"));
System.out.println(rb.getString("myapp.Prompt2"));
}
}
4. Compile and enjoy living in an internationalized world.
--
Exile In Paradise
"The porcupine with the sharpest quills gets stuck on a tree more
often."