mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fall back to single message if variations don't exist for localisation
This commit is contained in:
parent
85a3d0bec4
commit
c69307557d
@ -116,7 +116,9 @@ impl Language {
|
|||||||
let msg = bundle.get_message(key)?;
|
let msg = bundle.get_message(key)?;
|
||||||
let mut attrs = msg.attributes();
|
let mut attrs = msg.attributes();
|
||||||
|
|
||||||
if attrs.len() != 0 {
|
let mut errs = Vec::new();
|
||||||
|
|
||||||
|
let msg = if attrs.len() != 0 {
|
||||||
let idx = usize::from(seed) % attrs.len();
|
let idx = usize::from(seed) % attrs.len();
|
||||||
// unwrap is ok here, because idx is bound to attrs.len()
|
// unwrap is ok here, because idx is bound to attrs.len()
|
||||||
// by using modulo operator.
|
// by using modulo operator.
|
||||||
@ -134,16 +136,17 @@ impl Language {
|
|||||||
// * len = 0
|
// * len = 0
|
||||||
// * no matter what seed is, we return None in code above
|
// * no matter what seed is, we return None in code above
|
||||||
let variation = attrs.nth(idx).unwrap();
|
let variation = attrs.nth(idx).unwrap();
|
||||||
let mut errs = Vec::new();
|
bundle.format_pattern(variation.value(), args, &mut errs)
|
||||||
let msg = bundle.format_pattern(variation.value(), args, &mut errs);
|
|
||||||
for err in errs {
|
|
||||||
tracing::error!("err: {err} for {key}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(msg)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
// Fall back to single message if there are no attributes
|
||||||
|
bundle.format_pattern(msg.value()?, args, &mut errs)
|
||||||
|
};
|
||||||
|
|
||||||
|
for err in errs {
|
||||||
|
tracing::error!("err: {err} for {key}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user