mxResources

Implements internationalization.  You can provide any number of resource files on the server using the following format for the filename: name[-en].properties.  The en stands for any lowercase 2-character language shortcut (eg. de for german, fr for french).

If the optional language extension is omitted, then the file is used as a default resource which is loaded in all cases.  If a properties file for a specific language exists, then it is used to override the settings in the default resource.  All entries in the file are of the form key=value.  The values may then be accessed in code via get.  Lines without equal signs in the properties files are ignored.

Resource files may either be added programmatically using add or via a resource tag in the UI section of the editor configuration file, eg:

<mxEditor>
  <ui>
    <resource basename="examples/resources/mxWorkflow"/>

The above element will load examples/resources/mxWorkflow.properties as well as the language specific file for the current language, if it exists.

Values may contain placeholders of the form {1}...{n} where each placeholder is replaced with the value of the corresponding array element in the params argument passed to mxResources.get.  The placeholder {1} maps to the first element in the array (at index 0).

See mxClient.language for more information on specifying the default language or disabling all loading of resources.

Special characters

To use unicode characters use %u as a prefix, eg.  %u20AC will display a Euro sign.  For normal hex encoded strings, use % as a prefix, eg.  %F6 will display a ö (&ouml;).

Summary
mxResourcesImplements internationalization.
Variables
resourcesAssociative array that maps from keys to values.
loadDefaultBundleSpecifies if the default file for a given basename should be loaded.
loadDefaultBundleSpecifies if the specific language file file for a given basename should be loaded.
Functions
isBundleSupportedHook for subclassers to disable support for a given language.
getDefaultBundleHook for subclassers to return the URL for the special bundle.
getSpecialBundleHook for subclassers to return the URL for the special bundle.
addAdds the default and current language properties file for the specified basename.
parseParses the key, value pairs in the specified text and stores them as local resources.
getReturns the value for the specified resource key.

Variables

resources

Associative array that maps from keys to values.

loadDefaultBundle

Specifies if the default file for a given basename should be loaded.  Default is true.

loadDefaultBundle

Specifies if the specific language file file for a given basename should be loaded.  Default is true.

Functions

isBundleSupported

Hook for subclassers to disable support for a given language.  This implementation always returns true.

Parameters

basenameThe basename for which the file should be loaded.
lanThe current language.

getDefaultBundle

getDefaultBundle: function(basename,
lan)

Hook for subclassers to return the URL for the special bundle.  This implementation returns basename + ‘.properties’ or null if loadDefaultBundle is false.

Parameters

basenameThe basename for which the file should be loaded.
lanThe current language.

getSpecialBundle

getSpecialBundle: function(basename,
lan)

Hook for subclassers to return the URL for the special bundle.  This implementation returns basename + ‘_’ + lan + ‘.properties’ or null if <loadSpecialBundle> is false or lan equals mxClient.defaultLanguage.

If <mxResources.languages> is not null and mxClient.language contains a dash, then this method checks if <isLanguageSupported> returns true for the full language (including the dash).  If that returns false the first part of the language (up to the dash) will be tried as an extension.

If <mxResources.language> is null then the first part of the language is used to maintain backwards compatibility.

Parameters

basenameThe basename for which the file should be loaded.
lanThe language for which the file should be loaded.

add

add: function(basename,
lan)

Adds the default and current language properties file for the specified basename.  Existing keys are overridden as new files are added.

Example

At application startup, additional resources may be added using the following code:

mxResources.add('resources/editor');

parse

parse: function(text)

Parses the key, value pairs in the specified text and stores them as local resources.

get

get: function(key,
params,
defaultValue)

Returns the value for the specified resource key.

Example

To read the value for ‘welomeMessage’, use the following:

var result = mxResources.get('welcomeMessage') || '';

This would require an entry of the following form in one of the English language resource files:

welcomeMessage=Welcome to mxGraph!

The part behind the || is the string value to be used if the given resource is not available.

Parameters

keyString that represents the key of the resource to be returned.
paramsArray of the values for the placeholders of the form {1}...{n} to be replaced with in the resulting string.
defaultValueOptional string that specifies the default return value.
getDefaultBundle: function(basename,
lan)
Hook for subclassers to return the URL for the special bundle.
getSpecialBundle: function(basename,
lan)
Hook for subclassers to return the URL for the special bundle.
add: function(basename,
lan)
Adds the default and current language properties file for the specified basename.
parse: function(text)
Parses the key, value pairs in the specified text and stores them as local resources.
get: function(key,
params,
defaultValue)
Returns the value for the specified resource key.
Defines the language of the client, eg.
Specifies if the default file for a given basename should be loaded.
Defines the default language which is used in the common resource files.
Close