diff --git a/src/macro_utils.rs b/src/macro_utils.rs index 71b97c4..00c9d22 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -254,7 +254,7 @@ impl MacroCtx { icu_format: &str, ) -> Vec { // todo: there might be more props then real choices. Id for example - let mut choices: Vec = Vec::with_capacity(props.len()); + let mut choices: Vec = Vec::with_capacity(props.len() + 1); for prop_or_spread in props { if let PropOrSpread::Prop(prop) = prop_or_spread { @@ -282,6 +282,17 @@ impl MacroCtx { } } + let no_other_case = !choices + .iter() + .any(|c| matches!(c, CaseOrOffset::Case(case) if case.key == "other")); + + if no_other_case { + choices.push(CaseOrOffset::Case(ChoiceCase { + tokens: vec![], + key: "other".into(), + })); + } + choices } } diff --git a/src/tests/js_icu.rs b/src/tests/js_icu.rs index c067fe9..c0bb99c 100644 --- a/src/tests/js_icu.rs +++ b/src/tests/js_icu.rs @@ -269,3 +269,24 @@ to!( }); "# ); + +to!( + js_should_handle_missing_other_in_select, + r#" + import { select } from '@lingui/macro' + select(value, { + offset: "..", + any: "..", + }); + "#, + r#" + import { i18n as $_i18n } from "@lingui/core"; + $_i18n._({ + id: "QHtFym", + message: "{value, select, offset {..} any {..} other {}}", + values: { + value: value + } + }); + "# +); diff --git a/src/tests/jsx_icu.rs b/src/tests/jsx_icu.rs index 78dc8cb..94937cb 100644 --- a/src/tests/jsx_icu.rs +++ b/src/tests/jsx_icu.rs @@ -251,6 +251,24 @@ to!( "# ); +to!( + jsx_select_without_other, + r#" + import { Select } from '@lingui/macro'; +