Renovation
Search…
.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

1
RequestResponse<Map<String,String>> translate =
2
await getFrappeTranslationController().loadTranslations(lang: "ar");
3
4
if (translate.isSuccess) {
5
print("TEST in arabic : ${translate.data['TEST']}");
6
} else {
7
print(translate.error);
8
}
Copied!

.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

1
String sourceText = getFrappeTranslationController().getMessage(
2
txt: "Name",
3
lang: "ar"
4
);
5
print("Translation: $sourceText");
Copied!

.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

1
getFrappeTranslationController().setMessageDict(
2
dict: {
3
"Name": "الاسم"
4
},
5
lang: "ar"
6
);
Copied!

.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

1
getFrappeTranslationController().extendDictionary(
2
dict: {
3
"Name": "الاسم",
4
"Age": "العمر"
5
},
6
lang: "ar"
7
);
Copied!

.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

1
getFrappeTranslationController().setCurrentLanguage(
2
"ar" // lang
3
);
Copied!

.getCurrentLanguage()

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

Output

String

Example

1
String currentLang = getFrappeTranslationController().getCurrentLanguage();
Copied!

.clearCache()

Removes all translations saved in messages dictionary.

Output

void

Example

1
getFrappeTranslationController().clearCache();
Copied!
Last modified 1yr ago