Options
All
  • Public
  • Public/Protected
  • All
Menu

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 . Lines without equal signs in the properties files are ignored.

Resource files may either be added programmatically using 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 {@link mxClient.language} for more information on specifying the default language or disabling all loading of resources.

Lines that start with a # sign will be ignored.

Special characters

To use unicode characters, use the standard notation (eg. \u8fd1) or %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 "o umlaut" (ö).

See resourcesEncoded to disable this. If you disable this, make sure that your files are UTF-8 encoded.

Asynchronous loading

By default, the core adds two resource files synchronously at load time. To load these files asynchronously, set mxLoadResources to false before loading mxClient.js and use mxResources.loadResources instead.

Hierarchy

  • mxResources

Index

Constructors

constructor

Properties

Static extension

extension: string | boolean

Specifies the extension used for language files. Default is mxResourceExtension.

Static loadDefaultBundle

loadDefaultBundle: boolean

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

default

true

Static loadSpecialBundle

loadSpecialBundle: boolean

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

default

true

Static resources

resources: {}

Object that maps from keys to values.

Type declaration

Static resourcesEncoded

resourcesEncoded: boolean

Specifies whether or not values in resource files are encoded with \u or percentage. Default is false.

default

false

Methods

Static add

  • add(basename: string, lan: string, callback?: Function): void
  • Adds the default and current language properties file for the specified basename. Existing keys are overridden as new files are added. If no callback is used then the request is synchronous.

    example

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

    mxResources.add('resources/editor');
    

    Parameters

    • basename: string

      The basename for which the file should be loaded.

    • lan: string

      The language for which the file should be loaded.

    • Optional callback: Function

      Optional callback for asynchronous loading.

    Returns void

Static get

  • get(key: string, params?: (string | number | boolean)[], defaultValue?: string): string
  • 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

    • key: string

      String that represents the key of the resource to be returned.

    • Optional params: (string | number | boolean)[]

      Array of the values for the placeholders of the form {1}...{n} to be replaced with in the resulting string.

    • Optional defaultValue: string

      Optional string that specifies the default return value.

    Returns string

Static getDefaultBundle

  • getDefaultBundle(basename: string, lan: string): any
  • Hook for subclassers to return the URL for the special bundle. This implementation returns basename + extension or null if loadDefaultBundle is false.

    Parameters

    • basename: string

      The basename for which the file should be loaded.

    • lan: string

      The current language.

    Returns any

Static getSpecialBundle

  • getSpecialBundle(basename: string, lan: string): any
  • Hook for subclassers to return the URL for the special bundle. This implementation returns basename + '_' + lan + extension or null if loadSpecialBundle is false or lan equals {@link mxClient.defaultLanguage}.

    If {@link mxResources.languages} is not null and {@link 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 {@link mxResources.language} is null then the first part of the language is used to maintain backwards compatibility.

    Parameters

    • basename: string

      The basename for which the file should be loaded.

    • lan: string

      The current language.

    Returns any

Static isLanguageSupported

  • isLanguageSupported(lan: string): boolean
  • Hook for subclassers to disable support for a given language. This implementation returns true if lan is in {@link mxClient.languages}.

    Parameters

    • lan: string

      The current language.

    Returns boolean

Static loadResources

  • loadResources(callback: Function): void
  • Loads all required resources asynchronously. Use this to load the graph and editor resources if mxLoadResources is false.

    Parameters

    • callback: Function

      Callback function for asynchronous loading.

    Returns void

Static parse

  • parse(text: string): void
  • Parses the key, value pairs in the specified text and stores them as local resources.

    Parameters

    • text: string

    Returns void

Static replacePlaceholders

  • replacePlaceholders(value: string, params: (string | number | boolean)[]): string
  • Replaces the given placeholders with the given parameters.

    Parameters

    • value: string

      String that contains the placeholders.

    • params: (string | number | boolean)[]

      Array of the values for the placeholders of the form {1}...{n} to be replaced with in the resulting string.

    Returns string

Generated using TypeDoc