• 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

    Parameters

    Returns string

    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"