Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/macro_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl MacroCtx {
icu_format: &str,
) -> Vec<CaseOrOffset> {
// todo: there might be more props then real choices. Id for example
let mut choices: Vec<CaseOrOffset> = Vec::with_capacity(props.len());
let mut choices: Vec<CaseOrOffset> = Vec::with_capacity(props.len() + 1);

for prop_or_spread in props {
if let PropOrSpread::Prop(prop) = prop_or_spread {
Expand Down Expand Up @@ -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
}
}
21 changes: 21 additions & 0 deletions src/tests/js_icu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
"#
);
18 changes: 18 additions & 0 deletions src/tests/jsx_icu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ to!(
"#
);

to!(
jsx_select_without_other,
r#"
import { Select } from '@lingui/macro';
<Select
value={count}
_male="He"
_female={`She`}
/>;
"#,
r#"
import { Trans as Trans_ } from "@lingui/react";
<Trans_ message={"{count, select, male {He} female {She} other {} id={"Imwef9"} values={{
count: count
}} />;
"#
);

to!(
jsx_select_with_expressions_in_cases,
r#"
Expand Down