Bauke/cv
Bauke
/
cv
1
Fork 0

Add the localize utility function.

This commit is contained in:
Bauke 2024-01-16 12:40:02 +01:00
parent c1cbdaf7f9
commit a07d00e66d
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 24 additions and 0 deletions

24
utilities/localize.typ Normal file
View File

@ -0,0 +1,24 @@
// 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)
}