- self.fluent_bundle()
- .and_then(|bundle| translate_with_bundle(bundle))
- // If `translate_with_bundle` returns `None` with the primary bundle, this is likely
- // just that the primary bundle doesn't contain the message being translated, so
- // proceed to the fallback bundle.
- //
- // However, when errors are produced from translation, then that means the translation
- // is broken (e.g. `{$foo}` exists in a translation but `foo` isn't provided).
- //
- // In debug builds, assert so that compiler devs can spot the broken translation and
- // fix it..
- .inspect(|(_, errs)| {
- debug_assert!(
- errs.is_empty(),
- "identifier: {:?}, attr: {:?}, args: {:?}, errors: {:?}",
- identifier,
- attr,
- args,
- errs
- );
- })
- // ..otherwise, for end users, an error about this wouldn't be useful or actionable, so
- // just hide it and try with the fallback bundle.
- .filter(|(_, errs)| errs.is_empty())
- .or_else(|| translate_with_bundle(self.fallback_fluent_bundle()))
- .map(|(translated, errs)| {
- // Always bail out for errors with the fallback bundle.