Skip to content

Language

Type class

Handles all language-related tasks, like loading and storing translations, translating prompts, lists of prompts and even functions.

Almost every object in amCharts4 universe will have a language property, which can be accessed for prompt translation.

More info: ILanguageAdapters for a list of available Adapters

Sources

Language can be used (imported) via one of the following packages.

/**
* Import from: "core.ts"
* Use like: am4core.Language
*/
import * as am4core from "@amcharts/amcharts4/core";

Inheritance

Language extends BaseObjectEvents.

Language is not extended by any other symbol.

Properties

adapter

Type Adapter <this, ILanguageAdapters>Default new Adapter(this)

Adapter.

locale

Type ILocale

Current locale.

5 inherited items
clonedFrom

Type $type.Optional <this>Inherited from BaseObject

Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.

config

Type objectInherited from BaseObject

Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.

Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.

events

Type EventDispatcher <AMEvent <this, IBaseObjectEvents>>Inherited from BaseObjectEvents

An EventDispatcher instance

id

Type $type.Optional <string>Inherited from BaseObject

Sets the user-defined id of the element.

uid

Type stringInherited from BaseObject

Returns object's internal unique ID.

Methods

constructor()

Returns Language

Constructor

isDefault()

Returns boolean

Returns true if the currently selected locale is a default locale.

setTranslationAny(prompt: string,
translation: string,
locale?: ILocale
)

Returns voidSince 4.9.35

Sets a prompt translation.

translate(prompt: Key,
locale?: ILocale,
rest: Array <string>
)

Returns string

Returns the translation of the string.

If the translation is empty, it will return untranslated prompt.

Third parameter and up are strings that can be used to replace "%X" placeholders in prompt.

E.g.:

// Results in "This is a first translation test"
chart.language.translate("This is a %1 translation %2", null, "first", "test");
// Results in "This is a first translation test"
chart.language.translate("This is a %1 translation %2", null, "first", "test");
translateAll(list: Array <Key>,
locale?: ILocale
)

Returns Array <string>

Translates a list of prompts in one go.

translateAny(prompt: string,
locale?: ILocale,
rest: Array <string>
)

Returns stringSince 4.5.5

Non-type-checked translation.

Can be used by plugins and other code that may have their own non-standard translation prompts.

translateEmpty(prompt: Key,
locale?: ILocale,
rest: Array <string>
)

Returns string

Translates prompt.

If translation is empty, it will return empty string, which is a different behavior than that of regular translate.

translateFunc(prompt: Key,
locale?: ILocale
)

Returns ILocaleFunctions[""]

Translates a function.

This method will return a function reference, but will not run it. It's up to the caller script to run the function.

7 inherited items
clone(cloneId?: string)

Returns thisInherited from BaseObject

Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.

copyFrom(source: this)

Returns voidInherited from BaseObjectEvents

Copies all parameters from another Sprite.

dispatch(eventType: Key,
data?: any
)

Returns voidInherited from BaseObjectEvents

Dispatches an event using own event dispatcher. Will automatically populate event data object with event type and target (this element).

It also checks if there are any handlers registered for this sepecific event.

dispatchImmediately(eventType: Key,
data?: any
)

Returns voidInherited from BaseObjectEvents

Works like dispatch, except event is triggered immediately, without waiting for the next frame cycle.

dispose()

Returns voidInherited from BaseObject

Destroys this object and all related data.

getCurrentThemes()

Returns ITheme[]Inherited from BaseObject

Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.

isDisposed()

Returns booleanInherited from BaseObject

Returns if this object has been already been disposed.

Events

localechanged

Param { type: "localechanged", target: Language, locale: ILocale }

Invoked when locale is changed by user.

Adapters

locale

Param { locale: ILocale }

Applied to result whenever retrieving currently set locale.

translate

Param { locale: ILocale, translation: string }

Applied to a translation.

translations

Param { locale: ILocale, translations: any }

Applied to all of the locale translations.