Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Language

JMap.Language

From this section you can manage the locale and translations used in JMap NG.

Index

Functions

addBundle

  • JMap.Language.addBundle

    This method lets you add your own translations into JMap NG translation engine (for instance, all translations needed for one of your extensions)

    Once added, a bundle cannot be overriden, and its identity must be unique (its id). You can specify a default locale for your bundle, in wich case the JMap NG translation engine will fall back to your bundle's default locale instead of on the system's default locale if a translation is not found in your bundle for the current locale.

    throws

    if bundle is invalid or already defined

    example
    
    // Supported locales can be retrieved by calling [[JMap.Language.getLocales()]]
    
    const bundle = {
     id: "my-custom-bundle-id",
     defaultLocale: "fr",
     translationsByLocale: {
       "fr" : {
         "my-custom-key": "Ceci est ma traduction personnalisée en français"
       },
       "en" : {
         "my-custom-key": "This is my custom translation in English"
       }
     }
    }
    JMap.Language.addBundle(bundle)
    JMap.Language.setLocale("fr")
    let params = {key: "my-custom-key", bundleId: "my-custom-bundle-id"}
    console.log(JMap.Language.translate(params))
    // "Ceci est ma traduction personnalisée en français"

    Parameters

    Returns void

bundleExitsById

  • bundleExitsById(bundleId: string): boolean
  • JMap.Language.bundleExitsById

    Returns true if the bundle exists in the JMap NG translation engine, false otherwise

    Parameters

    • bundleId: string

    Returns boolean

getAllBundleIds

  • getAllBundleIds(): string[]
  • JMap.Language.getAllBundleIds

    Returns the list of bundle ids used by the JMap NG translation engine

    example
    
    JMap.Language.getAllBundleIds()
    // ["jmap-core-js", "jmap-app-js", "my-custom-bundle", ...]

    Returns string[]

getBundleById

  • JMap.Language.getBundleById

    Returns the translation bundle identified by the id

    throws

    if bundle id is not correct or if bundle not found

    example
    
    JMap.Language.getBundleById("my-custom-bundle")
    // {id: "my-custom-bundle", defaultLocale: "fr",   ...}

    Parameters

    • bundleId: string

      the id of the bundle to retrieve

    Returns JTranslationBundle

getBundles

  • JMap.Language.getBundles

    Returns an bbject of all the translation bundles loaded in JMap NG at the moment of the call, indexed by id

    example
    
    JMap.Language.getBundles()
    // { "my-custom-bundle": {id: "my-custom-bundle", defaultLocale: "fr",   ...}, ....}

    Returns JTranslationBundleById

getDateFnsDateFormat

  • getDateFnsDateFormat(): string
  • JMap.Language.getDateFnsDateFormat

    Returns the date format associated with the current locale (specific to the date-fns JS library)

    example
    
    // returns the default locale
    JMap.Language.setLocale("fr")
    console.log(JMap.Language.getDateFnsDateFormat())
    // "dd/MM/yyyy"
    JMap.Language.setLocale("en")
    console.log(JMap.Language.getDateFnsDateFormat())
    // "MM/dd/yyyy"

    Returns string

getDateFnsLocale

  • getDateFnsLocale(displayTime?: undefined | false | true): any
  • JMap.Language.getDateFnsLocale

    Returns the format for date-fns library.

    example
    
    // returns the format for date-fns library without datetime
    JMap.Language.getDateFnsLocale()
    
    // returns the format for date-fns library without datetime
    JMap.Language.getDateFnsLocale(true)

    Parameters

    • Optional displayTime: undefined | false | true

      true to return the format including the time

    Returns any

getDefaultLocale

  • JMap.Language.getDefaultLocale

    Get the default locale used by JMap NG. This locale can be used when a translation is not available in the current locale, for instance.

    example
    
    // returns the default locale
    JMap.Language.getDefaultLocale()
    // "en"

    Returns JLOCALES

getLocale

  • JMap.Language.getLocale

    Get the current locale.

    example
    
    // returns the current locale
    JMap.Language.getLocale()
    // ex: "fr"

    Returns JLOCALES

getLocales

  • JMap.Language.getLocales

    Get the list of all available locales as an array of string.

    example
    
    JMap.Language.getLocales()
    // ["fr", "en", ......]

    Returns JLOCALES[]

is12HoursTimeFormat

  • is12HoursTimeFormat(): boolean
  • JMap.Language.is12HoursTimeFormat

    Returns true if the current locale has a AM/PM setting for time format (08:00 PM), as opposed to a 24 hours format (20:00)

    example
    
    // returns the default locale
    JMap.Language.setLocale("fr")
    console.log(JMap.Language.is12HoursTimeFormat())
    // false

    Returns boolean

isValidLocale

  • isValidLocale(locale: JLOCALES): boolean
  • JMap.Language.isValidLocale

    returns true is the passed locale is supported by JMap NG, false otherwise

    example
    
    console.log(JMap.Language.isValidLocale("fr"))
    // true
    console.log(JMap.Language.isValidLocale("ch"))
    // false

    Parameters

    • locale: JLOCALES

      the locale to be tested

    Returns boolean

setLocale

  • JMap.Language.setLocale

    Sets the current locale. JMap NG will automatically reload.

    throws

    if locale is invalid

    example
    
    // Supported locales can be retrieved by calling [[JMap.Language.getLocales()]]
    const locale = "fr"
    JMap.Language.setLocale(locale)

    Parameters

    • locale: JLOCALES

      the new locale to use

    Returns void

translate

  • JMap.Language.translate

    Returns a translated string from the speficied bundle, for the current local, or for a specified locale.

    Parameters are supported, and must be passed as an array (or a single param) which must have the same length as the number of parameters in the translated string. Parameters must be identified by numbers starting at zero, corresponding to the index of the param in the array supplied

    example
    
    // Supported locales can be retrieved by calling [[JMap.Language.getLocales()]]
    
    const bundle = {
     id: "my-custom-bundle-id",
     defaultLocale: "fr",
     translationsByLocale: {
       "fr" : {
         "my-custom-key": "Je parles {0} langues"
       },
       "en" : {
         "my-custom-key": "I speak {0} languages"
       }
     }
    }
    JMap.Language.addBundle(bundle)
    JMap.Language.setLocale("fr")
    let params = {key: "my-custom-key", bundleId: "my-custom-bundle-id", params: ["2"] }
    console.log(JMap.Language.translate(params))
    // "Je parles 2 langues"
    params = {key: "my-custom-key", bundleId: "my-custom-bundle-id", params: ["2"], locale: "en" }
    console.log(JMap.Language.translate(params))
    // "I speak 2 languages"
    

    Parameters

    Returns string