org.stellarium
Class Translator

java.lang.Object
  extended by java.util.ResourceBundle
      extended by org.stellarium.Translator

public class Translator
extends java.util.ResourceBundle

Class used to translate strings to any language. Implements a nice interface to gettext which is UTF-8 compliant and is somewhat multiplateform All its operations do not modify the global locale. The purpose of this class is to remove all non-OO C locale functions from stellarium. It could be extended for all locale management using e.g the portable IBM ICU library.

Changes: - Reimplementation of getext in Java by Jerome Beau Reading the .po files and make a map of language (Locale), englishMsgId, translation - Full usage of Java ResourceBundle for Locale and cache management by Fred Simon

Version:
24 oct. 2006 01:07:47
Author:
Fabien Chereau for original C++ version, Jerome Beau, Frederic Simon

Nested Class Summary
(package private) static class Translator.POResourceControl
           
 
Nested classes/interfaces inherited from class java.util.ResourceBundle
java.util.ResourceBundle.Control
 
Field Summary
private static java.util.TreeSet<java.lang.String> availableLanguages
          All languages supported by Stellarium
private static Translator currentTranslator
          The currently used translator
private static java.lang.String PO_COMMENT_START
           
static java.util.List<java.lang.String> PO_FORMATS
          Supports po files
private static java.lang.String PO_KEY
           
private static java.lang.String PO_VALUE
           
private static Translator.POResourceControl poControl
           
private  java.io.File poFile
           
private  java.util.Map<java.lang.String,java.lang.String> properties
           
private static java.util.Map<java.util.Locale,java.io.File> supportedLocales
          Contains the set of locales (lang,country) supported by stellarium With the File containing the translations.
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
private Translator(java.io.File poFile)
           
 
Method Summary
static java.util.Locale codeToLocale(java.lang.String localeCode)
           
static Translator getCurrentTranslator()
           
 java.util.Enumeration<java.lang.String> getKeys()
           
static java.util.Set<java.lang.String> getNamesOfAvailableLanguages()
          Get available language codes from directory tree
static java.util.Set<java.util.Locale> getSupportedLocales()
           
static Translator getTranslator(java.util.Locale locale)
           
 java.lang.String getTrueLocaleName()
           
protected  java.lang.Object handleGetObject(java.lang.String key)
          Gets an object for the given key from this resource bundle.
static void initSystemLanguage()
          Try to determine system language from system configuration
private  java.lang.String interpretValue(java.lang.String currentValue)
           
private static java.util.Locale langToLocale(java.lang.String language)
           
private  java.lang.String normalizeKey(java.lang.String key)
           
private  void processComment(java.lang.String comment)
           
private  void processKeyValue(java.lang.String currentKey, java.lang.String currentValue)
           
private  void read()
           
static void setCurrentTranslator(java.util.Locale locale)
           
 java.lang.String translate(java.lang.String s)
          Translate input message.
 
Methods inherited from class java.util.ResourceBundle
clearCache, clearCache, containsKey, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PO_FORMATS

public static final java.util.List<java.lang.String> PO_FORMATS
Supports po files


supportedLocales

private static final java.util.Map<java.util.Locale,java.io.File> supportedLocales
Contains the set of locales (lang,country) supported by stellarium With the File containing the translations. TODO: Use URL instead of File


availableLanguages

private static final java.util.TreeSet<java.lang.String> availableLanguages
All languages supported by Stellarium


poControl

private static final Translator.POResourceControl poControl

currentTranslator

private static Translator currentTranslator
The currently used translator


PO_KEY

private static final java.lang.String PO_KEY
See Also:
Constant Field Values

PO_VALUE

private static final java.lang.String PO_VALUE
See Also:
Constant Field Values

PO_COMMENT_START

private static final java.lang.String PO_COMMENT_START
See Also:
Constant Field Values

properties

private final java.util.Map<java.lang.String,java.lang.String> properties

poFile

private final java.io.File poFile
Constructor Detail

Translator

private Translator(java.io.File poFile)
Method Detail

initSystemLanguage

public static void initSystemLanguage()
Try to determine system language from system configuration


getTranslator

public static Translator getTranslator(java.util.Locale locale)

codeToLocale

public static java.util.Locale codeToLocale(java.lang.String localeCode)

langToLocale

private static java.util.Locale langToLocale(java.lang.String language)

getSupportedLocales

public static java.util.Set<java.util.Locale> getSupportedLocales()

getNamesOfAvailableLanguages

public static java.util.Set<java.lang.String> getNamesOfAvailableLanguages()
Get available language codes from directory tree


getCurrentTranslator

public static Translator getCurrentTranslator()

setCurrentTranslator

public static void setCurrentTranslator(java.util.Locale locale)

getTrueLocaleName

public java.lang.String getTrueLocaleName()

translate

public java.lang.String translate(java.lang.String s)
Translate input message.

Parameters:
s - input string in english.
Returns:
The translated string in wide characters.

normalizeKey

private java.lang.String normalizeKey(java.lang.String key)

read

private void read()

interpretValue

private java.lang.String interpretValue(java.lang.String currentValue)

processKeyValue

private void processKeyValue(java.lang.String currentKey,
                             java.lang.String currentValue)

processComment

private void processComment(java.lang.String comment)

handleGetObject

protected java.lang.Object handleGetObject(java.lang.String key)
Gets an object for the given key from this resource bundle. Returns the key if this resource bundle does not contain an object for the given key.

Specified by:
handleGetObject in class java.util.ResourceBundle
Parameters:
key - the key for the desired object
Returns:
the object for the given key, or the key if object is not found
Throws:
java.lang.NullPointerException - if key is null

getKeys

public java.util.Enumeration<java.lang.String> getKeys()
Specified by:
getKeys in class java.util.ResourceBundle