.translate

Things to know

It is recommended for better support of types by code assistance in IDEs to usegetFrappeTranslationController()in order to get the instance of FrappeTranslationController instead of renovation.translate which is TranslationController if the backend is Frappè, for instance. In this guide we will use Frappé as an example and use getFrappeTranslationController()

.loadTranslations() ★

Returns the translations of the selected language from the backend of Frappe.

Input

property

type

required

description

lang

String

no

Langue translation to be returned from the backend, default “en” for english

Output

RequestResponse<Map<String,String>>

Example

RequestResponse<Map<String,String>> translate =
await getFrappeTranslationController().loadTranslations(lang: "ar");
if (translate.isSuccess) {
print("TEST in arabic : ${translate.data['TEST']}");
} else {
print(translate.error);
}

.getMessage()

Gets the translation of a text specified by language (optionally) or the current set language.

Input

property

type

required

description

txt

String

yes

The source text to get the translation for.

lang

String

no

The target language to load the translations for. Defaults to the current set language of the user.

Output

String

Example

String sourceText = getFrappeTranslationController().getMessage(
txt: "Name",
lang: "ar"
);
print("Translation: $sourceText");

.setMessagesDict()

Sets the translation dictionary replacing the existing one, if any, for a specific language.

Input

property

type

required

description

dict

Map<String,String>

yes

The dictionary that will be set for the language.

lang

String

no

The target language to set the translations dictionary for. Defaults to the current set language of the user.

Output

void

Example

getFrappeTranslationController().setMessageDict(
dict: {
"Name": "الاسم"
},
lang: "ar"
);

.extendDictionary()

Appends the translation dictionary replacing the existing keys (source texts), if any, for a specific language.

Input

property

type

required

description

dict

Map<String,String>

yes

The dictionary that will be appended for the language.

lang

String

no

The target language to extend the translations dictionary for. Defaults to the current set language of the user.

Output

void

Example

getFrappeTranslationController().extendDictionary(
dict: {
"Name": "الاسم",
"Age": "العمر"
},
lang: "ar"
);

.setCurrentLanguage()

Sets the current language (locally only) of the current user, Defaults to 'en'

Input

property

type

required

description

lang

String

yes

The language to set for the current user.

Output

void

Example

getFrappeTranslationController().setCurrentLanguage(
"ar" // lang
);

.getCurrentLanguage()

Gets the current language (locally only) of the current user.

Output

String

Example

String currentLang = getFrappeTranslationController().getCurrentLanguage();

.clearCache()

Removes all translations saved in messages dictionary.

Output

void

Example

getFrappeTranslationController().clearCache();