Improve ability i18n algorithm

This commit is contained in:
juliancoffee 2022-08-07 16:20:45 +03:00
parent c10f722e25
commit 445b748e1a

View File

@ -361,9 +361,20 @@ pub fn ability_description<'a>(
) -> (Cow<'a, str>, Cow<'a, str>) {
// TODO: Use fluent attribute mechanic
let (name, desc) = (
format!("{}.name", ability_id),
format!("{}.desc", ability_id),
format!("{}.name", ability_id).replace('.', "-"),
format!("{}.desc", ability_id).replace('.', "-"),
);
(loc.get(&name), loc.get(&desc))
// 1) Try localize ability
// 2) If not, say that ability is unknown
// 3) If unknown key is missed, just return id
// TODO: better algorithm?
(
loc.try_msg(&name)
.or_else(|| loc.try_msg("common-abilities-unknown-name"))
.unwrap_or(Cow::Owned(name)),
loc.try_msg(&desc)
.or_else(|| loc.try_msg("common-abilities-unknown-desc"))
.unwrap_or(Cow::Owned(desc)),
)
}