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";/** * Include via: <script src="core.js"></script> * Access items like: am4core.Language */Inheritance
Language extends BaseObjectEvents.
Language is not extended by any other symbol.
Properties
adapterType
Adapter<this,ILanguageAdapters>Defaultnew Adapter(this)Adapter.
localeType
ILocaleCurrent locale.
5 inherited items
clonedFromType
$type.Optional<this>Inherited fromBaseObjectReference 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.
configType
objectInherited fromBaseObjectUse 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.
eventsType
EventDispatcher<AMEvent<this,IBaseObjectEvents>>Inherited fromBaseObjectEventsAn
EventDispatcherinstanceidType
$type.Optional<string>Inherited fromBaseObjectSets the user-defined id of the element.
uidType
stringInherited fromBaseObjectReturns object's internal unique ID.
Methods
constructor()Returns
LanguageConstructor
isDefault()Returns
booleanReturns
trueif the currently selected locale is a default locale.setTranslationAny(prompt:string,
translation:string,
locale?:ILocale)Returns
voidSince 4.9.35Sets a prompt translation.
translate(prompt:Key,
locale?:ILocale,
rest:Array<string>)Returns
stringReturns 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.5Non-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
stringTranslates 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 fromBaseObjectMakes 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 fromBaseObjectEventsCopies all parameters from another
Sprite.dispatch(eventType:Key,
data?:any)Returns
voidInherited fromBaseObjectEventsDispatches 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 fromBaseObjectEventsWorks like
dispatch, except event is triggered immediately, without waiting for the next frame cycle.dispose()Returns
voidInherited fromBaseObjectDestroys this object and all related data.
getCurrentThemes()Returns
ITheme[]Inherited fromBaseObjectReturns 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 fromBaseObjectReturns if this object has been already been disposed.
Events
localechangedParam { type:
"localechanged", target:Language, locale:ILocale}Invoked when locale is changed by user.