25 lines
848 B
Plaintext
25 lines
848 B
Plaintext
// Get the localized item of a given key inside a data dictionary, using the
|
|
// provided language.
|
|
#let localize(data, key, language) = {
|
|
// If the key is directly available in the data then it hasn't been localized.
|
|
if key in data {
|
|
return data.at(key)
|
|
}
|
|
|
|
// Then check for the key with the wanted language appended to it.
|
|
let key_with_language = key + "_" + language
|
|
if key_with_language in data {
|
|
return data.at(key_with_language)
|
|
}
|
|
|
|
// If a locale dictionary exists in the data, then run this function again
|
|
// using that dictionary for the same key and language.
|
|
if "locale" in data {
|
|
return localize(data.locale, key, language)
|
|
}
|
|
|
|
// And if the key nor locale exists in any way then panic, as we won't have
|
|
// any text to return.
|
|
panic("Data does not contain key in any localized way: " + key, data)
|
|
}
|