|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.j3d.util.I18nManager
public class I18nManager
Manager of all internationalisation in the toolkit.
This class acts as a singleton manager for internationalisation within j3d.org Code and all applications built on it. It may be used for any string resource that may require internationalisation - not just text on buttons but also error messages, log messages etc.
External Application Usage
An application should initialise this manager as soon as possible after startup - ideally before anything else happens. The initialisation ensures that the right resources are loaded before people start making queries. The initialisation process should provide an application name as a reference point for internationalisation preferences that are stored to preserve settings between runs of the application. In no application name is provided, then the preferences are not stored and it will need to be reset each time the application runs. The reason for the application name is that this manager is shared in a toolkit with many different potential end applications making use of it. The application names allows us to create separate sets of settings on a per-application basis rather than relying on global settings for the user's computer.
The second direct customisation point is to provide a base name for the
resource bundle to be loaded. If no name is provided, it will load the
resource bundle named config.i18n.j3dorgResources
from
the classpath. This class follows the normal naming conventions that are
defined in ResourceBundle
. Any application providing
their own resource bundle must provide values for every chefx3d resource
that is specified in the base file that comes with this toolkit. Failure
to do so will result in blank areas on the user interface and most
probably an unusable application.
If an application wishes to also internationalise other settings, such as numerical representations, then you can query this class for the Locale it actually loaded, rather than the one you requested (fairly typical issue).
Note:
Because this class just stores string values, it is entirely possible to use it to store non-text information as well for a more generic internationalisation system. For example, storing the names of icon files could be a valid use of this class, allowing localisation for more than just text, but also graphical resources.
Resource Bundle Property Naming Conventions
With a property file containing all the internationalisation of a probably very large application, naming conventions are a necessity. Properties that are internal to any j3d.org-specific user interface element will start with the package name, class name (case included) and finally the resource property name after that.
Method Summary | |
---|---|
void |
changeLocale(java.lang.String language,
java.lang.String country,
java.lang.String variant)
Manually change the locale to the given country and language settings to overrided the current settings. |
java.lang.String |
getApplication()
Get the currently set application string that langauge settings are being used for. |
java.util.Locale |
getFoundLocale()
Get the loaded locale that was used for the resources file This can be used to create matching other internationalisation implementation details such as currency and number formatters. |
static I18nManager |
getManager()
Get the global instance of the internationalisation manager for the given root class. |
java.lang.String |
getRequestedCountry()
Get the country code that is currently set. |
java.lang.String |
getRequestedLanguage()
Get the language code that is currently set. |
java.lang.String |
getRequestedLanguageVariant()
Get the language variant setting that is currently set. |
java.lang.String |
getResourceName()
Get the name of the resource file that is being loaded. |
java.lang.String |
getString(java.lang.String property)
Get the localised string for the given property name. |
void |
setApplication(java.lang.String appName,
java.lang.String resourceFile)
Set the manager to use the given application's set of localisation settings. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static I18nManager getManager()
public void setApplication(java.lang.String appName, java.lang.String resourceFile)
appName
- A name string describing the end user applicationresourceFile
- If not null, use this as the resource bundle
base name to be fetched, rather than the default file namepublic java.lang.String getApplication()
public java.lang.String getResourceName()
public void changeLocale(java.lang.String language, java.lang.String country, java.lang.String variant) throws java.lang.IllegalArgumentException
Setting the language value to null will reset the system back to the default platform setting. The other arguments may be null or specified. If null, the defaults for those are used from the local platform settings.
Language and country strings are required to be the 2 letter identifiers
used in the ISO specifications. See the documentation of
Locale
for more information about valid codes. The
method will check for appropriate length codes and issue an exception
if they are not two characters.
language
- The language identifier to loadcountry
- The optional country code to loadvariant
- The optional language variant to load
IllegalArgument
- exception if the country or language codes are
not correctly formated (length and case)
java.lang.IllegalArgumentException
Locale
,
http://www.loc.gov/standards/iso639-2/englangn.html,
http://www.davros.org/misc/iso3166.txtpublic java.util.Locale getFoundLocale()
public java.lang.String getRequestedLanguage()
public java.lang.String getRequestedCountry()
public java.lang.String getRequestedLanguageVariant()
public java.lang.String getString(java.lang.String property)
|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |