Internationalization / i18n
An internationalization of texts can be realized by using maps. The language code is the key and the text its associated value:
{"language_code1":"lang1_text","language_code2":"lang2_text",....}
The following examples demonstrate this.
Android
Android
final
String language_code=
"de"
;
final
Conference conference =
new
Conference();
Map<String, String> i18n_name =
new
HashMap<String,String>();
i18n_name.put(
"de"
,
"Wie benutzt man properties"
);
i18n_name.put(
"en"
,
"How to use properties"
);
conference.setI18n_name(i18n_name);
Map<String, String> i18ns_guests =
new
HashMap<String,String>();
i18ns_guests.put(
"de"
,
"Gastsprecher: John Doe"
);
i18ns_guests.put(
"en"
,
"Guest speaker: John Doe"
);
conference.setI18n_guests(i18ns_guests);
conference.saveAsync(
new
AOMEmptyCallback() {
@Override
public
void
isDone(ApiomatRequestException exception) {
//if exception != null an error occurred
if
(exception ==
null
) {
Log.i (
"Conference"
,conference.getI18n_name().get(language_code));
Log.i (
"Conference"
,conference.getI18n_guests().get(language_code));
}
}
});
JavaScript
JavaScript
var
LANGUAGE=
"de"
;
function
showConference (conference)
{
console.log(conference.getI18n_name()[LANGUAGE]);
console.log(conference.getI18n_guests()[LANGUAGE]);
}
function
initConference ()
{
var
conference=
new
Apiomat.Conference();
var
i18n_name = {
"de"
:
"Wie benutzt man properties"
,
"en"
:
"How to use properties"
}
conference.setI18n_name(i18n_name);
var
i18ns_guests = {
"de"
:
"Gastsprecher: John Doe"
,
"en"
:
"Guest speaker: John Doe"
}
conference.setI18n_guests(i18ns_guests);
var
saveCB = {
onOk:
function
() {
showConference(conference);
},
onError:
function
(error) {
console.log(
"error "
+error);
}
}
conference.save(saveCB);
}