+ where
+ E: serde::de::Error,
+ {
+ Ok(Literal::String(v.to_string()))
+ }
+
+ fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(
+ formatter,
+ "a litteral such as a number, a string or a boolean"
+ )
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -916,7 +1217,10 @@ mod tests {
fn parse_normal_string() {
let value = new_parsed_value("test");
- assert_eq!(value, ParsedValue::String("test".to_string()));
+ assert_eq!(
+ value,
+ ParsedValue::Literal(Literal::String("test".to_string()))
+ );
}
#[test]
@@ -926,12 +1230,12 @@ mod tests {
assert_eq!(
value,
ParsedValue::Bloc(vec![
- ParsedValue::String("before ".to_string()),
+ ParsedValue::Literal(Literal::String("before ".to_string())),
ParsedValue::Variable {
key: new_key("var_var"),
formatter: Formatter::None
},
- ParsedValue::String(" after".to_string())
+ ParsedValue::Literal(Literal::String(" after".to_string()))
])
)
}
@@ -943,12 +1247,12 @@ mod tests {
assert_eq!(
value,
ParsedValue::Bloc(vec![
- ParsedValue::String("before ".to_string()),
+ ParsedValue::Literal(Literal::String("before ".to_string())),
ParsedValue::Component {
key: new_key("comp_comp"),
- inner: Box::new(ParsedValue::String("inner".to_string()))
+ inner: Box::new(ParsedValue::Literal(Literal::String("inner".to_string())))
},
- ParsedValue::String(" after".to_string())
+ ParsedValue::Literal(Literal::String(" after".to_string()))
])
)
}
@@ -962,19 +1266,21 @@ mod tests {
assert_eq!(
value,
ParsedValue::Bloc(vec![
- ParsedValue::String("before ".to_string()),
+ ParsedValue::Literal(Literal::String("before ".to_string())),
ParsedValue::Component {
key: new_key("comp_comp"),
inner: Box::new(ParsedValue::Bloc(vec![
- ParsedValue::String("inner before".to_string()),
+ ParsedValue::Literal(Literal::String("inner before".to_string())),
ParsedValue::Component {
key: new_key("comp_comp"),
- inner: Box::new(ParsedValue::String("inner inner".to_string()))
+ inner: Box::new(ParsedValue::Literal(Literal::String(
+ "inner inner".to_string()
+ )))
},
- ParsedValue::String("inner after".to_string()),
+ ParsedValue::Literal(Literal::String("inner after".to_string())),
]))
},
- ParsedValue::String(" after".to_string())
+ ParsedValue::Literal(Literal::String(" after".to_string()))
])
)
}
@@ -986,12 +1292,14 @@ mod tests {
assert_eq!(
value,
ParsedValue::Bloc(vec![
- ParsedValue::String("test".to_string()),
+ ParsedValue::Literal(Literal::String("
test".to_string())),
ParsedValue::Component {
key: new_key("comp_h3"),
- inner: Box::new(ParsedValue::String("this is a h3".to_string()))
+ inner: Box::new(ParsedValue::Literal(Literal::String(
+ "this is a h3".to_string()
+ )))
},
- ParsedValue::String("not closing p".to_string())
+ ParsedValue::Literal(Literal::String("not closing p".to_string()))
])
)
}
diff --git a/leptos_i18n_macro/src/load_locales/plurals.rs b/leptos_i18n_macro/src/load_locales/plurals.rs
index 39c66a22..8dc22dfd 100644
--- a/leptos_i18n_macro/src/load_locales/plurals.rs
+++ b/leptos_i18n_macro/src/load_locales/plurals.rs
@@ -1,11 +1,28 @@
-use std::collections::HashMap;
+use std::{
+ collections::{HashMap, HashSet},
+ rc::Rc,
+};
+use fixed_decimal::{FixedDecimal, FloatPrecision};
+use icu::plurals::{PluralCategory, PluralOperands, PluralRuleType as IcuRuleType, PluralRules};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
+use std::fmt::Display;
-use crate::{load_locales::interpolate::CACHED_LOCALE_FIELD_KEY, utils::key::KeyPath};
+use crate::{
+ load_locales::{
+ error::{Error, Result},
+ interpolate::CACHED_LOCALE_FIELD_KEY,
+ locale::LiteralType,
+ parsed_value::{InterpolOrLit, Literal},
+ },
+ utils::key::{Key, KeyPath},
+};
-use super::parsed_value::ParsedValue;
+use super::{
+ parsed_value::ParsedValue,
+ warning::{emit_warning, Warning},
+};
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum PluralRuleType {
@@ -13,6 +30,24 @@ pub enum PluralRuleType {
Ordinal,
}
+impl Display for PluralRuleType {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ PluralRuleType::Cardinal => write!(f, "cardinal"),
+ PluralRuleType::Ordinal => write!(f, "ordinal"),
+ }
+ }
+}
+
+impl From for IcuRuleType {
+ fn from(value: PluralRuleType) -> Self {
+ match value {
+ PluralRuleType::Cardinal => IcuRuleType::Cardinal,
+ PluralRuleType::Ordinal => IcuRuleType::Ordinal,
+ }
+ }
+}
+
impl ToTokens for PluralRuleType {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(self.to_token_stream())
@@ -40,6 +75,19 @@ pub enum PluralForm {
Other,
}
+impl Display for PluralForm {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ PluralForm::Zero => write!(f, "_zero"),
+ PluralForm::One => write!(f, "_one"),
+ PluralForm::Two => write!(f, "_two"),
+ PluralForm::Few => write!(f, "_few"),
+ PluralForm::Many => write!(f, "_many"),
+ PluralForm::Other => write!(f, "_other"),
+ }
+ }
+}
+
impl PluralForm {
pub fn try_from_str(s: &str) -> Option {
match s {
@@ -52,6 +100,17 @@ impl PluralForm {
_ => None,
}
}
+
+ pub fn from_icu_category(cat: PluralCategory) -> Self {
+ match cat {
+ PluralCategory::Zero => PluralForm::Zero,
+ PluralCategory::One => PluralForm::One,
+ PluralCategory::Two => PluralForm::Two,
+ PluralCategory::Few => PluralForm::Few,
+ PluralCategory::Many => PluralForm::Many,
+ PluralCategory::Other => PluralForm::Other,
+ }
+ }
}
impl ToTokens for PluralForm {
@@ -76,6 +135,7 @@ impl ToTokens for PluralForm {
#[derive(Debug, Clone, PartialEq)]
pub struct Plurals {
pub rule_type: PluralRuleType,
+ pub count_key: Rc,
// Box to be used inside the `ParsedValue::Plurals` variant without size recursion,
// we could have `ParsedValue::Plurals(Box)`
// but that makes `ParsedValue::Plurals(Plurals { .. })` impossible in match patterns.
@@ -84,7 +144,29 @@ pub struct Plurals {
}
impl Plurals {
- pub fn as_string_impl(&self) -> TokenStream {
+ fn get_plural_rules(&self, locale: &Rc) -> PluralRules {
+ let locale = locale.name.parse::().unwrap();
+ PluralRules::try_new(&locale.into(), self.rule_type.into()).unwrap()
+ }
+
+ pub fn check_categories(&self, locale: &Rc, key_path: &KeyPath) {
+ let plural_rules = self.get_plural_rules(locale);
+ let categs = self.forms.keys().copied().collect::>();
+ let used_categs = plural_rules
+ .categories()
+ .map(PluralForm::from_icu_category)
+ .collect::>();
+ for cat in categs.difference(&used_categs) {
+ emit_warning(Warning::UnusedCategory {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ category: *cat,
+ rule_type: self.rule_type,
+ })
+ }
+ }
+
+ pub fn as_string_impl(&self, count_key: &Key) -> TokenStream {
let match_arms = self.forms.iter().map(|(form, value)| {
let ts = value.as_string_impl();
quote!(#form => #ts)
@@ -98,12 +180,146 @@ impl Plurals {
quote! {{
let _plural_rules = l_i18n_crate::__private::get_plural_rules(*#locale_field, #rule_type);
- match _plural_rules.category_for(core::clone::Clone::clone(plural_count)) {
+ match _plural_rules.category_for(core::clone::Clone::clone(#count_key)) {
#(#match_arms,)*
_ => #other,
}
}}
}
+
+ fn populate_with_new_key(
+ &self,
+ new_key: Rc,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ let other = self.other.populate(args, foreign_key, locale, key_path)?;
+ let mut forms = HashMap::new();
+ for (form, value) in &self.forms {
+ let value = value.populate(args, foreign_key, locale, key_path)?;
+ forms.insert(*form, value);
+ }
+
+ Ok(ParsedValue::Plurals(Plurals {
+ rule_type: self.rule_type,
+ count_key: new_key,
+ other: Box::new(other),
+ forms,
+ }))
+ }
+
+ pub fn find_variable(
+ values: &[ParsedValue],
+ locale: &Rc,
+ key_path: &KeyPath,
+ foreign_key: &KeyPath,
+ ) -> Result> {
+ let mut iter = values.iter().peekable();
+ while let Some(next) = iter.peek() {
+ match next {
+ ParsedValue::Literal(Literal::String(s)) if s.trim().is_empty() => {
+ iter.next();
+ }
+ ParsedValue::Variable { .. } => break,
+ _ => {
+ return Err(Error::InvalidCountArg {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ })
+ }
+ }
+ }
+ let Some(ParsedValue::Variable { key, .. }) = iter.next() else {
+ return Err(Error::InvalidCountArg {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ });
+ };
+
+ for next in iter {
+ match next {
+ ParsedValue::Literal(Literal::String(s)) if s.trim().is_empty() => continue,
+ _ => {
+ return Err(Error::InvalidCountArg {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ })
+ }
+ }
+ }
+
+ Ok(key.clone())
+ }
+
+ fn populate_with_count_arg(
+ &self,
+ count_arg: &ParsedValue,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ fn get_category>(
+ plurals: &Plurals,
+ locale: &Rc,
+ input: I,
+ ) -> PluralCategory {
+ let plural_rules = plurals.get_plural_rules(locale);
+ plural_rules.category_for(input)
+ }
+
+ let category = match count_arg {
+ ParsedValue::Literal(Literal::Float(count)) => {
+ let count = FixedDecimal::try_from_f64(*count, FloatPrecision::Floating).unwrap();
+ get_category(self, locale, &count)
+ }
+ ParsedValue::Literal(Literal::Unsigned(count)) => get_category(self, locale, *count),
+ ParsedValue::Literal(Literal::Signed(count)) => get_category(self, locale, *count),
+ ParsedValue::Bloc(values) => {
+ let new_key = Self::find_variable(values, locale, key_path, foreign_key)?;
+ return self.populate_with_new_key(new_key, args, foreign_key, locale, key_path);
+ }
+ ParsedValue::Variable { key, .. } => {
+ return self.populate_with_new_key(key.clone(), args, foreign_key, locale, key_path)
+ }
+ _ => {
+ return Err(Error::InvalidCountArg {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ })
+ }
+ };
+
+ match PluralForm::from_icu_category(category) {
+ PluralForm::Other => self.other.populate(args, foreign_key, locale, key_path),
+ other_cat => self.forms.get(&other_cat).unwrap_or(&self.other).populate(
+ args,
+ foreign_key,
+ locale,
+ key_path,
+ ),
+ }
+ }
+
+ pub fn populate(
+ &self,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ if let Some(count_arg) = args.get("var_count") {
+ return self.populate_with_count_arg(count_arg, args, foreign_key, locale, key_path);
+ }
+
+ self.populate_with_new_key(self.count_key.clone(), args, foreign_key, locale, key_path)
+ }
}
impl ToTokens for Plurals {
@@ -120,16 +336,16 @@ impl ToTokens for Plurals {
let locale_field = CACHED_LOCALE_FIELD_KEY.with(Clone::clone);
let other = &*self.other;
- let mut captured_values = None;
+ let mut captured_values = InterpolOrLit::Lit(LiteralType::String);
let mut key_path = KeyPath::new(None);
for value in self.forms.values().chain(Some(other)) {
value
- .get_keys_inner(&mut key_path, &mut captured_values)
+ .get_keys_inner(&mut key_path, &mut captured_values, false)
.unwrap();
}
- let captured_values = captured_values.map(|keys| {
+ let captured_values = captured_values.is_interpol().map(|keys| {
let keys = keys
.iter_keys()
.map(|key| quote!(let #key = core::clone::Clone::clone(key);));
@@ -138,13 +354,15 @@ impl ToTokens for Plurals {
let rule_type = self.rule_type;
+ let count_key = &self.count_key;
+
quote! {
leptos::IntoView::into_view(
{
#captured_values
let _plural_rules = l_i18n_crate::__private::get_plural_rules(#locale_field, #rule_type);
move || {
- match _plural_rules.category_for(plural_count()) {
+ match _plural_rules.category_for(#count_key()) {
#(#match_arms,)*
_ => #other,
}
diff --git a/leptos_i18n_macro/src/load_locales/ranges.rs b/leptos_i18n_macro/src/load_locales/ranges.rs
index 3e07efff..0a264ffc 100644
--- a/leptos_i18n_macro/src/load_locales/ranges.rs
+++ b/leptos_i18n_macro/src/load_locales/ranges.rs
@@ -1,5 +1,7 @@
use std::{
+ collections::HashMap,
marker::PhantomData,
+ num::TryFromIntError,
ops::{Bound, Not},
rc::Rc,
str::FromStr,
@@ -9,13 +11,20 @@ use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::parse::ParseBuffer;
-use crate::load_locales::locale::LocalesOrNamespaces;
use crate::utils::key::{Key, KeyPath};
+use crate::{
+ load_locales::{
+ locale::{LiteralType, LocalesOrNamespaces},
+ parsed_value::Literal,
+ plurals::Plurals,
+ },
+ utils::key::CACHED_VAR_COUNT_KEY,
+};
use super::{
declare_locales::parse_range_pairs,
error::{Error, Result},
- parsed_value::{InterpolationKeys, ParsedValue, ParsedValueSeed},
+ parsed_value::{InterpolOrLit, ParsedValue, ParsedValueSeed},
};
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
@@ -85,7 +94,7 @@ impl RangeType {
pub type RangesInner = Vec<(Range, ParsedValue)>;
#[derive(Debug, Clone, PartialEq)]
-pub enum Ranges {
+pub enum UntypedRangesInner {
I8(RangesInner),
I16(RangesInner),
I32(RangesInner),
@@ -98,19 +107,254 @@ pub enum Ranges {
F64(RangesInner),
}
+#[derive(Debug, Clone, PartialEq)]
+pub struct Ranges {
+ pub count_key: Rc,
+ pub inner: UntypedRangesInner,
+}
+
impl Ranges {
+ pub fn populate_with_count_arg(
+ &self,
+ count_arg: &ParsedValue,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ fn find_value(
+ v: &RangesInner,
+ count: T,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ for (range, value) in v {
+ if range.do_match(count) {
+ return value.populate(args, foreign_key, locale, key_path);
+ }
+ }
+ unreachable!("plurals validity should already have been checked.");
+ }
+ fn try_from>(count: T) -> Result {
+ TryFrom::try_from(count).map_err(|_| todo!())
+ }
+ match count_arg {
+ ParsedValue::Literal(Literal::Float(count)) => {
+ let count = *count;
+ match &self.inner {
+ UntypedRangesInner::F32(v) => {
+ find_value(v, count as f32, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::F64(v) => {
+ find_value(v, count, args, foreign_key, locale, key_path)
+ }
+ _ => Err(Error::InvalidCountArgType {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ input_type: RangeType::F64,
+ range_type: self.get_type(),
+ }),
+ }
+ }
+ ParsedValue::Literal(Literal::Unsigned(count)) => {
+ let count = *count;
+ match &self.inner {
+ UntypedRangesInner::U64(v) => {
+ find_value(v, count, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I8(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I16(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I32(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I64(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::U8(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::U16(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::U32(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ _ => Err(Error::InvalidCountArgType {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ input_type: RangeType::U64,
+ range_type: self.get_type(),
+ }),
+ }
+ }
+ ParsedValue::Literal(Literal::Signed(count)) => {
+ let count = *count;
+ match &self.inner {
+ UntypedRangesInner::U64(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I8(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I16(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I32(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::I64(v) => {
+ find_value(v, count, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::U8(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::U16(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ UntypedRangesInner::U32(v) => {
+ find_value(v, try_from(count)?, args, foreign_key, locale, key_path)
+ }
+ _ => Err(Error::InvalidCountArgType {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ input_type: RangeType::I64,
+ range_type: self.get_type(),
+ }),
+ }
+ }
+ ParsedValue::Bloc(values) => {
+ let new_key = Plurals::find_variable(values, locale, key_path, foreign_key)?;
+ self.populate_with_new_key(new_key, args, foreign_key, locale, key_path)
+ }
+ ParsedValue::Variable { key, .. } => {
+ self.populate_with_new_key(key.clone(), args, foreign_key, locale, key_path)
+ }
+ _ => Err(Error::InvalidCountArg {
+ locale: locale.clone(),
+ key_path: key_path.to_owned(),
+ foreign_key: foreign_key.to_owned(),
+ }),
+ }
+ }
+
+ fn populate_with_new_key(
+ &self,
+ new_key: Rc,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ fn inner(
+ v: &RangesInner,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result> {
+ let mut values = Vec::with_capacity(v.len());
+ for (range, value) in v {
+ let range = Clone::clone(range);
+ let value = value.populate(args, foreign_key, locale, key_path)?;
+ values.push((range, value));
+ }
+ Ok(values)
+ }
+ let ranges = match &self.inner {
+ UntypedRangesInner::I8(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::I8)
+ }
+ UntypedRangesInner::I16(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::I16)
+ }
+ UntypedRangesInner::I32(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::I32)
+ }
+ UntypedRangesInner::I64(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::I64)
+ }
+ UntypedRangesInner::U8(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::U8)
+ }
+ UntypedRangesInner::U16(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::U16)
+ }
+ UntypedRangesInner::U32(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::U32)
+ }
+ UntypedRangesInner::U64(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::U64)
+ }
+ UntypedRangesInner::F32(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::F32)
+ }
+ UntypedRangesInner::F64(v) => {
+ inner(v, args, foreign_key, locale, key_path).map(UntypedRangesInner::F64)
+ }
+ };
+ ranges
+ .map(|inner| Ranges {
+ count_key: new_key,
+ inner,
+ })
+ .map(ParsedValue::Ranges)
+ }
+
+ pub fn populate(
+ &self,
+ args: &HashMap,
+ foreign_key: &KeyPath,
+ locale: &Rc,
+ key_path: &KeyPath,
+ ) -> Result {
+ if let Some(count_arg) = args.get("var_count") {
+ self.populate_with_count_arg(count_arg, args, foreign_key, locale, key_path)
+ } else {
+ self.populate_with_new_key(self.count_key.clone(), args, foreign_key, locale, key_path)
+ }
+ }
+
pub fn as_string_impl(&self) -> TokenStream {
- match self {
- Ranges::I8(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::I16(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::I32(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::I64(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::U8(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::U16(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::U32(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::U64(ranges) => Self::to_tokens_integers_string(ranges),
- Ranges::F32(ranges) => Self::to_tokens_floats_string(ranges),
- Ranges::F64(ranges) => Self::to_tokens_floats_string(ranges),
+ match &self.inner {
+ UntypedRangesInner::I8(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::I16(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::I32(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::I64(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::U8(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::U16(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::U32(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::U64(ranges) => {
+ Self::to_tokens_integers_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::F32(ranges) => {
+ Self::to_tokens_floats_string(ranges, &self.count_key)
+ }
+ UntypedRangesInner::F64(ranges) => {
+ Self::to_tokens_floats_string(ranges, &self.count_key)
+ }
}
}
@@ -126,32 +370,28 @@ impl Ranges {
})
}
- pub fn get_keys_inner(
- &self,
- key_path: &mut KeyPath,
- keys: &mut Option,
- ) -> Result<()> {
+ pub fn get_keys_inner(&self, key_path: &mut KeyPath, keys: &mut InterpolOrLit) -> Result<()> {
fn inner(
v: &RangesInner,
key_path: &mut KeyPath,
- keys: &mut Option,
+ keys: &mut InterpolOrLit,
) -> Result<()> {
for (_, value) in v {
- value.get_keys_inner(key_path, keys)?;
+ value.get_keys_inner(key_path, keys, false)?;
}
Ok(())
}
- match self {
- Ranges::I8(v) => inner(v, key_path, keys),
- Ranges::I16(v) => inner(v, key_path, keys),
- Ranges::I32(v) => inner(v, key_path, keys),
- Ranges::I64(v) => inner(v, key_path, keys),
- Ranges::U8(v) => inner(v, key_path, keys),
- Ranges::U16(v) => inner(v, key_path, keys),
- Ranges::U32(v) => inner(v, key_path, keys),
- Ranges::U64(v) => inner(v, key_path, keys),
- Ranges::F32(v) => inner(v, key_path, keys),
- Ranges::F64(v) => inner(v, key_path, keys),
+ match &self.inner {
+ UntypedRangesInner::I8(v) => inner(v, key_path, keys),
+ UntypedRangesInner::I16(v) => inner(v, key_path, keys),
+ UntypedRangesInner::I32(v) => inner(v, key_path, keys),
+ UntypedRangesInner::I64(v) => inner(v, key_path, keys),
+ UntypedRangesInner::U8(v) => inner(v, key_path, keys),
+ UntypedRangesInner::U16(v) => inner(v, key_path, keys),
+ UntypedRangesInner::U32(v) => inner(v, key_path, keys),
+ UntypedRangesInner::U64(v) => inner(v, key_path, keys),
+ UntypedRangesInner::F32(v) => inner(v, key_path, keys),
+ UntypedRangesInner::F64(v) => inner(v, key_path, keys),
}
}
@@ -168,17 +408,17 @@ impl Ranges {
}
Ok(())
}
- match self {
- Ranges::I8(v) => inner(v, f),
- Ranges::I16(v) => inner(v, f),
- Ranges::I32(v) => inner(v, f),
- Ranges::I64(v) => inner(v, f),
- Ranges::U8(v) => inner(v, f),
- Ranges::U16(v) => inner(v, f),
- Ranges::U32(v) => inner(v, f),
- Ranges::U64(v) => inner(v, f),
- Ranges::F32(v) => inner(v, f),
- Ranges::F64(v) => inner(v, f),
+ match &self.inner {
+ UntypedRangesInner::I8(v) => inner(v, f),
+ UntypedRangesInner::I16(v) => inner(v, f),
+ UntypedRangesInner::I32(v) => inner(v, f),
+ UntypedRangesInner::I64(v) => inner(v, f),
+ UntypedRangesInner::U8(v) => inner(v, f),
+ UntypedRangesInner::U16(v) => inner(v, f),
+ UntypedRangesInner::U32(v) => inner(v, f),
+ UntypedRangesInner::U64(v) => inner(v, f),
+ UntypedRangesInner::F32(v) => inner(v, f),
+ UntypedRangesInner::F64(v) => inner(v, f),
}
}
@@ -195,48 +435,51 @@ impl Ranges {
}
Ok(())
}
- match self {
- Ranges::I8(v) => inner(v, f),
- Ranges::I16(v) => inner(v, f),
- Ranges::I32(v) => inner(v, f),
- Ranges::I64(v) => inner(v, f),
- Ranges::U8(v) => inner(v, f),
- Ranges::U16(v) => inner(v, f),
- Ranges::U32(v) => inner(v, f),
- Ranges::U64(v) => inner(v, f),
- Ranges::F32(v) => inner(v, f),
- Ranges::F64(v) => inner(v, f),
+ match &mut self.inner {
+ UntypedRangesInner::I8(v) => inner(v, f),
+ UntypedRangesInner::I16(v) => inner(v, f),
+ UntypedRangesInner::I32(v) => inner(v, f),
+ UntypedRangesInner::I64(v) => inner(v, f),
+ UntypedRangesInner::U8(v) => inner(v, f),
+ UntypedRangesInner::U16(v) => inner(v, f),
+ UntypedRangesInner::U32(v) => inner(v, f),
+ UntypedRangesInner::U64(v) => inner(v, f),
+ UntypedRangesInner::F32(v) => inner(v, f),
+ UntypedRangesInner::F64(v) => inner(v, f),
}
}
pub const fn get_type(&self) -> RangeType {
- match self {
- Ranges::I8(_) => RangeType::I8,
- Ranges::I16(_) => RangeType::I16,
- Ranges::I32(_) => RangeType::I32,
- Ranges::I64(_) => RangeType::I64,
- Ranges::U8(_) => RangeType::U8,
- Ranges::U16(_) => RangeType::U16,
- Ranges::U32(_) => RangeType::U32,
- Ranges::U64(_) => RangeType::U64,
- Ranges::F32(_) => RangeType::F32,
- Ranges::F64(_) => RangeType::F64,
+ match &self.inner {
+ UntypedRangesInner::I8(_) => RangeType::I8,
+ UntypedRangesInner::I16(_) => RangeType::I16,
+ UntypedRangesInner::I32(_) => RangeType::I32,
+ UntypedRangesInner::I64(_) => RangeType::I64,
+ UntypedRangesInner::U8(_) => RangeType::U8,
+ UntypedRangesInner::U16(_) => RangeType::U16,
+ UntypedRangesInner::U32(_) => RangeType::U32,
+ UntypedRangesInner::U64(_) => RangeType::U64,
+ UntypedRangesInner::F32(_) => RangeType::F32,
+ UntypedRangesInner::F64(_) => RangeType::F64,
}
}
- fn to_tokens_integers(ranges: &[(Range, ParsedValue)]) -> TokenStream {
+ fn to_tokens_integers(
+ ranges: &[(Range, ParsedValue)],
+ count_key: &Key,
+ ) -> TokenStream {
let match_arms = ranges.iter().map(|(range, value)| quote!(#range => #value));
- let mut captured_values = None;
+ let mut captured_values = InterpolOrLit::Lit(LiteralType::String);
let mut key_path = KeyPath::new(None);
for (_, value) in ranges {
value
- .get_keys_inner(&mut key_path, &mut captured_values)
+ .get_keys_inner(&mut key_path, &mut captured_values, false)
.unwrap();
}
- let captured_values = captured_values.map(|keys| {
+ let captured_values = captured_values.is_interpol().map(|keys| {
let keys = keys
.iter_keys()
.map(|key| quote!(let #key = core::clone::Clone::clone(key);));
@@ -244,8 +487,7 @@ impl Ranges {
});
let match_statement = quote! {
{
- let plural_count = plural_count();
- match plural_count {
+ match #count_key() {
#(
#match_arms,
)*
@@ -266,6 +508,7 @@ impl Ranges {
fn to_tokens_integers_string(
ranges: &[(Range, ParsedValue)],
+ count_key: &Key,
) -> TokenStream {
let match_arms = ranges.iter().map(|(range, value)| {
let value = value.as_string_impl();
@@ -274,8 +517,7 @@ impl Ranges {
quote! {
{
- let plural_count = *plural_count;
- match plural_count {
+ match *#count_key {
#(
#match_arms,
)*
@@ -299,7 +541,10 @@ impl Ranges {
}
}
- fn to_tokens_floats(ranges: &[(Range, ParsedValue)]) -> TokenStream {
+ fn to_tokens_floats(
+ ranges: &[(Range, ParsedValue)],
+ count_key: &Key,
+ ) -> TokenStream {
let mut ifs = ranges
.iter()
.map(|(range, value)| match Self::to_condition(range) {
@@ -312,16 +557,16 @@ impl Ranges {
#(else #ifs)*
};
- let mut captured_values = None;
+ let mut captured_values = InterpolOrLit::Lit(LiteralType::String);
let mut key_path = KeyPath::new(None);
for (_, value) in ranges {
value
- .get_keys_inner(&mut key_path, &mut captured_values)
+ .get_keys_inner(&mut key_path, &mut captured_values, false)
.unwrap();
}
- let captured_values = captured_values.map(|keys| {
+ let captured_values = captured_values.is_interpol().map(|keys| {
let keys = keys
.iter_keys()
.map(|key| quote!(let #key = core::clone::Clone::clone(key);));
@@ -333,7 +578,7 @@ impl Ranges {
{
#captured_values
move || {
- let plural_count = plural_count();
+ let plural_count = #count_key();
#ifs
}
},
@@ -342,7 +587,10 @@ impl Ranges {
}
}
- fn to_tokens_floats_string(ranges: &[(Range, ParsedValue)]) -> TokenStream {
+ fn to_tokens_floats_string(
+ ranges: &[(Range, ParsedValue)],
+ count_key: &Key,
+ ) -> TokenStream {
let mut ifs = ranges.iter().map(|(range, value)| {
let value = value.as_string_impl();
match Self::to_condition(range) {
@@ -358,7 +606,7 @@ impl Ranges {
quote! {
{
- let plural_count = *plural_count;
+ let plural_count = *#count_key;
#ifs
}
}
@@ -368,32 +616,52 @@ impl Ranges {
where
A: ParseRanges<'a, 'de>,
{
- match self {
- Ranges::I8(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::I16(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::I32(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::I64(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::U8(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::U16(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::U32(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::U64(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::F32(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
- Ranges::F64(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
+ match &mut self.inner {
+ UntypedRangesInner::I8(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
+ UntypedRangesInner::I16(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::I32(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::I64(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::U8(ranges) => ParseRanges::deserialize_all_pairs(seq, ranges, seed),
+ UntypedRangesInner::U16(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::U32(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::U64(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::F32(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
+ UntypedRangesInner::F64(ranges) => {
+ ParseRanges::deserialize_all_pairs(seq, ranges, seed)
+ }
}
}
pub fn from_type(range_type: RangeType) -> Self {
- match range_type {
- RangeType::I8 => Self::I8(vec![]),
- RangeType::I16 => Self::I16(vec![]),
- RangeType::I32 => Self::I32(vec![]),
- RangeType::I64 => Self::I64(vec![]),
- RangeType::U8 => Self::U8(vec![]),
- RangeType::U16 => Self::U16(vec![]),
- RangeType::U32 => Self::U32(vec![]),
- RangeType::U64 => Self::U64(vec![]),
- RangeType::F32 => Self::F32(vec![]),
- RangeType::F64 => Self::F64(vec![]),
+ let inner = match range_type {
+ RangeType::I8 => UntypedRangesInner::I8(vec![]),
+ RangeType::I16 => UntypedRangesInner::I16(vec![]),
+ RangeType::I32 => UntypedRangesInner::I32(vec![]),
+ RangeType::I64 => UntypedRangesInner::I64(vec![]),
+ RangeType::U8 => UntypedRangesInner::U8(vec![]),
+ RangeType::U16 => UntypedRangesInner::U16(vec![]),
+ RangeType::U32 => UntypedRangesInner::U32(vec![]),
+ RangeType::U64 => UntypedRangesInner::U64(vec![]),
+ RangeType::F32 => UntypedRangesInner::F32(vec![]),
+ RangeType::F64 => UntypedRangesInner::F64(vec![]),
+ };
+ Ranges {
+ count_key: CACHED_VAR_COUNT_KEY.with(Clone::clone),
+ inner,
}
}
@@ -411,7 +679,10 @@ impl Ranges {
let mut ranges = match type_or_range {
TypeOrRange::Type(range_type) => Self::from_type(range_type),
- TypeOrRange::Range(range) => Ranges::I32(vec![range]),
+ TypeOrRange::Range(range) => Ranges {
+ count_key: CACHED_VAR_COUNT_KEY.with(Clone::clone),
+ inner: UntypedRangesInner::I32(vec![range]),
+ },
};
ranges.deserialize_inner(seq, parsed_value_seed)?;
@@ -440,34 +711,54 @@ impl Ranges {
}
pub fn check_deserialization(&self) -> (bool, usize, bool) {
- match self {
- Ranges::I8(ranges) => Self::check_de_inner(ranges),
- Ranges::I16(ranges) => Self::check_de_inner(ranges),
- Ranges::I32(ranges) => Self::check_de_inner(ranges),
- Ranges::I64(ranges) => Self::check_de_inner(ranges),
- Ranges::U8(ranges) => Self::check_de_inner(ranges),
- Ranges::U16(ranges) => Self::check_de_inner(ranges),
- Ranges::U32(ranges) => Self::check_de_inner(ranges),
- Ranges::U64(ranges) => Self::check_de_inner(ranges),
- Ranges::F32(ranges) => Self::check_de_inner(ranges),
- Ranges::F64(ranges) => Self::check_de_inner(ranges),
+ match &self.inner {
+ UntypedRangesInner::I8(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::I16(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::I32(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::I64(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::U8(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::U16(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::U32(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::U64(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::F32(ranges) => Self::check_de_inner(ranges),
+ UntypedRangesInner::F64(ranges) => Self::check_de_inner(ranges),
}
}
}
impl ToTokens for Ranges {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
- match self {
- Ranges::I8(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::I16(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::I32(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::I64(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::U8(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::U16(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::U32(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::U64(ranges) => Self::to_tokens_integers(ranges).to_tokens(tokens),
- Ranges::F32(ranges) => Self::to_tokens_floats(ranges).to_tokens(tokens),
- Ranges::F64(ranges) => Self::to_tokens_floats(ranges).to_tokens(tokens),
+ match &self.inner {
+ UntypedRangesInner::I8(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::I16(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::I32(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::I64(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::U8(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::U16(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::U32(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::U64(ranges) => {
+ Self::to_tokens_integers(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::F32(ranges) => {
+ Self::to_tokens_floats(ranges, &self.count_key).to_tokens(tokens)
+ }
+ UntypedRangesInner::F64(ranges) => {
+ Self::to_tokens_floats(ranges, &self.count_key).to_tokens(tokens)
+ }
}
}
}
@@ -495,6 +786,24 @@ pub trait RangeInteger: RangeNumber {}
pub trait RangeFloats: RangeNumber {}
impl Range {
+ fn do_match(&self, count: T) -> bool {
+ match self {
+ Range::Exact(v) => *v == count,
+ Range::Bounds { start, end } => {
+ if matches!(start, Some(s) if *s > count) {
+ return false;
+ }
+ match end {
+ Bound::Included(e) => *e >= count,
+ Bound::Excluded(e) => *e > count,
+ Bound::Unbounded => true,
+ }
+ }
+ Range::Multiple(ranges) => ranges.iter().any(|range| range.do_match(count)),
+ Range::Fallback => true,
+ }
+ }
+
fn flatten(self) -> Self {
let Range::Multiple(ranges) = self else {
return self;
diff --git a/leptos_i18n_macro/src/load_locales/warning.rs b/leptos_i18n_macro/src/load_locales/warning.rs
index 5ce685c8..d6fe205c 100644
--- a/leptos_i18n_macro/src/load_locales/warning.rs
+++ b/leptos_i18n_macro/src/load_locales/warning.rs
@@ -5,6 +5,8 @@ use quote::{format_ident, quote};
use crate::utils::key::{Key, KeyPath};
use std::{cell::RefCell, fmt::Display, rc::Rc};
+use super::plurals::{PluralForm, PluralRuleType};
+
#[derive(Debug)]
pub enum Warning {
MissingKey {
@@ -15,6 +17,12 @@ pub enum Warning {
locale: Rc,
key_path: KeyPath,
},
+ UnusedCategory {
+ locale: Rc,
+ key_path: KeyPath,
+ category: PluralForm,
+ rule_type: PluralRuleType,
+ },
#[cfg(feature = "track_locale_files")]
NonUnicodePath {
locale: Rc,
@@ -44,6 +52,9 @@ impl Display for Warning {
"Key \"{}\" is present in locale {:?} but not in default locale, it is ignored",
key_path, locale
),
+ Warning::UnusedCategory { locale, key_path, category, rule_type } => {
+ write!(f, "at key \"{}\", locale {:?} does not use {} category {}, it is still kept but is useless.", key_path, locale, rule_type, category)
+ },
#[cfg(feature = "track_locale_files")]
Warning::NonUnicodePath { locale, namespace: None, path } => write!(f, "File path for locale {:?} is not valid Unicode, can't add it to proc macro depedencies. Path: {:?}", locale, path),
#[cfg(feature = "track_locale_files")]
diff --git a/leptos_i18n_macro/src/t_macro/interpolate.rs b/leptos_i18n_macro/src/t_macro/interpolate.rs
index 5134dfa0..5483372a 100644
--- a/leptos_i18n_macro/src/t_macro/interpolate.rs
+++ b/leptos_i18n_macro/src/t_macro/interpolate.rs
@@ -23,17 +23,6 @@ pub enum InterpolatedValue {
comp_name: Ident,
attrs: TokenStream,
},
- // intermidiate value, not constructible by the user
- Count {
- key: Ident,
- foreign_count: Option,
- },
- // form t!(i18n, key, $ = ..)
- AssignedCount {
- foreign_count: Option,
- key: Ident,
- value: Expr,
- },
}
fn check_component_end(input: Cursor) -> bool {
@@ -72,28 +61,6 @@ impl syn::parse::Parse for InterpolatedValue {
if is_comp {
input.parse::()?;
}
- let is_count = !is_comp && input.peek(Token![$]);
- if is_count {
- input.parse::()?;
- let foreign_count = if input.peek(Token![:]) {
- input.parse::()?;
- let foreign_count = input.parse::()?;
- Some(foreign_count)
- } else {
- None
- };
- input.parse::()?;
- let value = input.parse::()?;
- let ident = foreign_count
- .as_ref()
- .map(|ident| format_ident!("__plural_count_{}__", ident))
- .unwrap_or_else(|| format_ident!("__plural_count__"));
- return Ok(InterpolatedValue::AssignedCount {
- key: ident,
- value,
- foreign_count,
- });
- }
let key = input.parse::()?;
if is_comp {
input.parse::]>()?;
@@ -127,13 +94,10 @@ impl syn::parse::Parse for InterpolatedValue {
impl InterpolatedValue {
pub fn get_ident(&self) -> Option<&Ident> {
match self {
- InterpolatedValue::Var(ident)
- | InterpolatedValue::Count { key: ident, .. }
- | InterpolatedValue::Comp(ident) => Some(ident),
+ InterpolatedValue::Var(ident) | InterpolatedValue::Comp(ident) => Some(ident),
InterpolatedValue::AssignedVar { .. }
| InterpolatedValue::AssignedComp { .. }
- | InterpolatedValue::DirectComp { .. }
- | InterpolatedValue::AssignedCount { .. } => None,
+ | InterpolatedValue::DirectComp { .. } => None,
}
}
@@ -173,22 +137,6 @@ impl InterpolatedValue {
*self = InterpolatedValue::Comp(key.clone());
(key.clone(), ts)
}
- InterpolatedValue::AssignedCount {
- key,
- value,
- foreign_count,
- } => {
- let key = key.clone();
- let ts = quote!(#value);
- *self = InterpolatedValue::Count {
- key: key.clone(),
- foreign_count: foreign_count.take(),
- };
- (key, ts)
- }
- InterpolatedValue::Count { .. } => {
- unreachable!("This is an intermidiate state, can't be constructed by the user.")
- }
}
}
}
@@ -204,18 +152,9 @@ impl ToTokens for InterpolatedValue {
let comp_ident = Self::format_ident(ident, false);
quote!(#comp_ident(#ident))
}
- InterpolatedValue::Count { foreign_count, key } => {
- if let Some(foreign_count) = foreign_count {
- let builder_set_fn = format_ident!("plural_count_{}", foreign_count);
- quote!(#builder_set_fn(#key))
- } else {
- quote!(plural_count(#key))
- }
- }
InterpolatedValue::AssignedVar { .. }
| InterpolatedValue::AssignedComp { .. }
- | InterpolatedValue::DirectComp { .. }
- | InterpolatedValue::AssignedCount { .. } => {
+ | InterpolatedValue::DirectComp { .. } => {
unreachable!(
"Assigned values should have been transformed to normal var in the param step"
)
diff --git a/leptos_i18n_macro/src/t_macro/mod.rs b/leptos_i18n_macro/src/t_macro/mod.rs
index 29cf7f0d..38636677 100644
--- a/leptos_i18n_macro/src/t_macro/mod.rs
+++ b/leptos_i18n_macro/src/t_macro/mod.rs
@@ -69,7 +69,7 @@ pub fn t_macro_inner(
let inner = quote! {
{
#[allow(unused)]
- use leptos_i18n::__private::BuildStr;
+ use leptos_i18n::__private::BuildLit;
let _key = #get_key;
_key.#builder_fn().#build_fn()
}
diff --git a/leptos_i18n_macro/src/utils/key.rs b/leptos_i18n_macro/src/utils/key.rs
index 6dc11028..3e00ef63 100644
--- a/leptos_i18n_macro/src/utils/key.rs
+++ b/leptos_i18n_macro/src/utils/key.rs
@@ -8,7 +8,7 @@ use std::{
};
thread_local! {
- pub static CACHED_PLURAL_COUNT_KEY: Rc = Rc::new(Key::new("var_count").unwrap());
+ pub static CACHED_VAR_COUNT_KEY: Rc = Rc::new(Key::new("var_count").unwrap());
}
#[derive(Clone)]
diff --git a/tests/json/Cargo.toml b/tests/json/Cargo.toml
index 1630d04e..60ea1711 100644
--- a/tests/json/Cargo.toml
+++ b/tests/json/Cargo.toml
@@ -11,7 +11,10 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
leptos = "0.6"
common = { path = "../common" }
-leptos_i18n = { path = "../../leptos_i18n", features = ["interpolate_display"] }
+leptos_i18n = { path = "../../leptos_i18n", features = [
+ "interpolate_display",
+ "track_locale_files",
+] }
[package.metadata.leptos-i18n]
diff --git a/tests/json/locales/en.json b/tests/json/locales/en.json
index 3ed0e4f2..5b0370aa 100644
--- a/tests/json/locales/en.json
+++ b/tests/json/locales/en.json
@@ -38,12 +38,14 @@
["zero", 0],
["this range is declared in locale {{ locale }}"]
],
- "defaulted_foreign_key": "before {{ @click_to_inc }} after",
- "foreign_key_to_string": "before {{ @click_to_inc }} after",
- "foreign_key_to_interpolation": "before {{ @click_count }} after",
- "foreign_key_to_subkey": "before {{ @subkeys.subkey_1 }} after",
+ "defaulted_foreign_key": "before $t(click_to_inc) after",
+ "foreign_key_to_string": "before $t(click_to_inc) after",
+ "foreign_key_to_interpolation": "before $t(click_count) after",
+ "foreign_key_to_subkey": "before $t(subkeys.subkey_1) after",
"foreign_key_to_explicit_default": "no explicit default in default locale",
- "populated_foreign_key": "before {{ @click_count, count = '45' }} after",
+ "populated_foreign_key": "before $t(click_count, {\"count\": \"45\" }) after",
+ "populated_foreign_key_with_arg": "before $t(click_count, {\"count\": \"{{ new_count }}\" }) after",
+ "populated_foreign_key_with_foreign_key_arg": "before $t(click_count, {\"count\": \"$t(subkeys.subkey_1)\" }) after",
"interpolate_variable_and_comp": "{{ count }}",
"list_formatting": "{{ list, list(list_type: and; list_style: wide) }}",
"date_formatting": "{{ date, date }}",
@@ -55,5 +57,20 @@
"ordinal_plural_ordinal_one": "{{ count }}st place",
"ordinal_plural_ordinal_two": "{{ count }}nd place",
"ordinal_plural_ordinal_few": "{{ count }}rd place",
- "ordinal_plural_ordinal_other": "{{ count }}th place"
+ "ordinal_plural_ordinal_other": "{{ count }}th place",
+ "same_lit_type": true,
+ "mixed_lit_type": 59.89,
+ "range_with_arg_other_than_count": [
+ ["{{ arg }} zero", 0],
+ ["{{ arg }} {{ count }}", "_"]
+ ],
+ "args_to_range": "$t(range_with_arg_other_than_count, {\"arg\": \"en\"})",
+ "count_arg_to_range": "$t(range_with_arg_other_than_count, {\"count\": 0})",
+ "renamed_ranges_count": "$t(f32_range, {\"count\":\"{{ first_count }}\"}) $t(OR_range, {\"count\":\"{{ second_count }}\"})",
+ "plural_with_arg_other_than_count_one": "{{ arg }} singular",
+ "plural_with_arg_other_than_count_other": "{{ arg }} {{ count }}",
+ "args_to_plural": "$t(plural_with_arg_other_than_count, {\"arg\": \"en\"})",
+ "count_arg_to_plural": "$t(plural_with_arg_other_than_count, {\"count\": 1})",
+ "foreign_key_to_two_plurals": "$t(cardinal_plural) $t(plural_with_arg_other_than_count, {\"arg\": \"en\"})",
+ "renamed_plurals_count": "$t(cardinal_plural, {\"count\":\"{{ first_count }}\"}) $t(ordinal_plural, {\"count\":\"{{ second_count }}\"})"
}
diff --git a/tests/json/locales/fr.json b/tests/json/locales/fr.json
index 5f0420ba..942764cf 100644
--- a/tests/json/locales/fr.json
+++ b/tests/json/locales/fr.json
@@ -32,11 +32,13 @@
"defaulted_interpolation": null,
"defaulted_ranges": null,
"defaulted_foreign_key": null,
- "foreign_key_to_string": "before {{ @click_to_inc }} after",
- "foreign_key_to_interpolation": "before {{ @click_count }} after",
- "foreign_key_to_subkey": "before {{ @subkeys.subkey_1 }} after",
- "foreign_key_to_explicit_default": "before {{ @defaulted_string }} after",
- "populated_foreign_key": "before {{ @click_count, count = \"32\" }} after",
+ "foreign_key_to_string": "before $t(click_to_inc) after",
+ "foreign_key_to_interpolation": "before $t(click_count) after",
+ "foreign_key_to_subkey": "before $t(subkeys.subkey_1) after",
+ "foreign_key_to_explicit_default": "before $t(defaulted_string) after",
+ "populated_foreign_key": "before $t(click_count, {\"count\": \"32\" }) after",
+ "populated_foreign_key_with_arg": "before $t(click_count, {\"count\": \"{{ new_count }}\" }) after",
+ "populated_foreign_key_with_foreign_key_arg": "before $t(click_count, {\"count\": \"$t(subkeys.subkey_1)\" }) after",
"interpolate_variable_and_comp": "{{ count }}",
"list_formatting": "{{ list, list(list_type: or; list_style: short) }}",
"date_formatting": "{{ date, date }}",
@@ -45,5 +47,20 @@
"number_formatting": "{{ num, number }}",
"cardinal_plural": "{{ count }}",
"ordinal_plural_ordinal_one": "{{ count }}re place",
- "ordinal_plural_ordinal_other": "{{ count }}e place"
+ "ordinal_plural_ordinal_other": "{{ count }}e place",
+ "same_lit_type": false,
+ "mixed_lit_type": true,
+ "range_with_arg_other_than_count": [
+ ["{{ arg }} zero", 0],
+ ["{{ arg }} {{ count }}", "_"]
+ ],
+ "args_to_range": "$t(range_with_arg_other_than_count, {\"arg\": \"fr\"})",
+ "count_arg_to_range": "$t(range_with_arg_other_than_count, {\"count\": 0})",
+ "renamed_ranges_count": "$t(f32_range, {\"count\":\"{{ first_count }}\"}) $t(OR_range, {\"count\":\"{{ second_count }}\"})",
+ "plural_with_arg_other_than_count_one": "{{ arg }} singular",
+ "plural_with_arg_other_than_count_other": "{{ arg }} {{ count }}",
+ "args_to_plural": "$t(plural_with_arg_other_than_count, {\"arg\": \"fr\"})",
+ "count_arg_to_plural": "$t(plural_with_arg_other_than_count, {\"count\": 2})",
+ "foreign_key_to_two_plurals": "$t(cardinal_plural) $t(plural_with_arg_other_than_count, {\"arg\": \"fr\"})",
+ "renamed_plurals_count": "$t(cardinal_plural, {\"count\":\"{{ first_count }}\"}) $t(ordinal_plural, {\"count\":\"{{ second_count }}\"})"
}
diff --git a/tests/json/src/defaulted.rs b/tests/json/src/defaulted.rs
index 5c2a6810..62440438 100644
--- a/tests/json/src/defaulted.rs
+++ b/tests/json/src/defaulted.rs
@@ -20,16 +20,16 @@ fn defaulted_interpolation() {
#[test]
fn defaulted_ranges() {
let count = || 0;
- let en = td!(Locale::en, defaulted_ranges, locale = "en", $ = count);
+ let en = td!(Locale::en, defaulted_ranges, locale = "en", count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, defaulted_ranges, locale = "en", $ = count);
+ let fr = td!(Locale::fr, defaulted_ranges, locale = "en", count);
assert_eq_rendered!(fr, "zero");
for i in [-3, 5, 12] {
let count = move || i;
- let en = td!(Locale::en, defaulted_ranges, locale = "en", $ = count);
+ let en = td!(Locale::en, defaulted_ranges, locale = "en", count);
assert_eq_rendered!(en, "this range is declared in locale en");
- let fr = td!(Locale::fr, defaulted_ranges, locale = "en", $ = count);
+ let fr = td!(Locale::fr, defaulted_ranges, locale = "en", count);
assert_eq_rendered!(fr, "this range is declared in locale en");
}
}
diff --git a/tests/json/src/foreign.rs b/tests/json/src/foreign.rs
index 1143fa14..1a8d1912 100644
--- a/tests/json/src/foreign.rs
+++ b/tests/json/src/foreign.rs
@@ -58,3 +58,19 @@ fn populated_foreign_key() {
let fr = td!(Locale::fr, populated_foreign_key);
assert_eq_rendered!(fr, "before Vous avez cliqué 32 fois after");
}
+
+#[test]
+fn populated_foreign_key_with_arg() {
+ let en = td!(Locale::en, populated_foreign_key_with_arg, new_count = 12);
+ assert_eq_rendered!(en, "before You clicked 12 times after");
+ let fr = td!(Locale::fr, populated_foreign_key_with_arg, new_count = 67);
+ assert_eq_rendered!(fr, "before Vous avez cliqué 67 fois after");
+}
+
+#[test]
+fn populated_foreign_key_with_foreign_key_arg() {
+ let en = td!(Locale::en, populated_foreign_key_with_foreign_key_arg);
+ assert_eq_rendered!(en, "before You clicked subkey_1 times after");
+ let fr = td!(Locale::fr, populated_foreign_key_with_foreign_key_arg);
+ assert_eq_rendered!(fr, "before Vous avez cliqué subkey_1 fois after");
+}
diff --git a/tests/json/src/plurals.rs b/tests/json/src/plurals.rs
index d8a2595e..3665aa03 100644
--- a/tests/json/src/plurals.rs
+++ b/tests/json/src/plurals.rs
@@ -5,24 +5,24 @@ use common::*;
fn cardinal_plural() {
// count = 0
let count = move || 0;
- let en = td!(Locale::en, cardinal_plural, $ = count);
+ let en = td!(Locale::en, cardinal_plural, count);
assert_eq_rendered!(en, "0 items");
- let fr = td!(Locale::fr, cardinal_plural, $ = count);
+ let fr = td!(Locale::fr, cardinal_plural, count);
assert_eq_rendered!(fr, "0");
// count = 1
let count = move || 1;
- let en = td!(Locale::en, cardinal_plural, $ = count);
+ let en = td!(Locale::en, cardinal_plural, count);
assert_eq_rendered!(en, "one item");
- let fr = td!(Locale::fr, cardinal_plural, $ = count);
+ let fr = td!(Locale::fr, cardinal_plural, count);
assert_eq_rendered!(fr, "1");
// count = 2..
for i in [2, 5, 10, 1000] {
let count = move || i;
- let en = td!(Locale::en, cardinal_plural, $ = count);
+ let en = td!(Locale::en, cardinal_plural, count);
assert_eq_rendered!(en, format!("{} items", i));
- let fr = td!(Locale::fr, cardinal_plural, $ = count);
+ let fr = td!(Locale::fr, cardinal_plural, count);
assert_eq_rendered!(fr, i.to_string());
}
}
@@ -31,29 +31,71 @@ fn cardinal_plural() {
fn ordinal_plural() {
// count = 1
let count = move || 1;
- let en = td!(Locale::en, ordinal_plural, $ = count);
+ let en = td!(Locale::en, ordinal_plural, count);
assert_eq_rendered!(en, "1st place");
- let fr = td!(Locale::fr, ordinal_plural, $ = count);
+ let fr = td!(Locale::fr, ordinal_plural, count);
assert_eq_rendered!(fr, "1re place");
// count = 2
let count = move || 2;
- let en = td!(Locale::en, ordinal_plural, $ = count);
+ let en = td!(Locale::en, ordinal_plural, count);
assert_eq_rendered!(en, "2nd place");
- let fr = td!(Locale::fr, ordinal_plural, $ = count);
+ let fr = td!(Locale::fr, ordinal_plural, count);
assert_eq_rendered!(fr, "2e place");
// count = 3
let count = move || 3;
- let en = td!(Locale::en, ordinal_plural, $ = count);
+ let en = td!(Locale::en, ordinal_plural, count);
assert_eq_rendered!(en, "3rd place");
- let fr = td!(Locale::fr, ordinal_plural, $ = count);
+ let fr = td!(Locale::fr, ordinal_plural, count);
assert_eq_rendered!(fr, "3e place");
// count = 4
let count = move || 4;
- let en = td!(Locale::en, ordinal_plural, $ = count);
+ let en = td!(Locale::en, ordinal_plural, count);
assert_eq_rendered!(en, "4th place");
- let fr = td!(Locale::fr, ordinal_plural, $ = count);
+ let fr = td!(Locale::fr, ordinal_plural, count);
assert_eq_rendered!(fr, "4e place");
}
+
+#[test]
+fn args_to_plural() {
+ let count = move || 0;
+ let en = td!(Locale::en, args_to_plural, count);
+ assert_eq_rendered!(en, "en 0");
+ let fr = td!(Locale::fr, args_to_plural, count);
+ assert_eq_rendered!(fr, "fr singular");
+}
+
+#[test]
+fn count_arg_to_plural() {
+ let en = td!(Locale::en, count_arg_to_plural, arg = "en");
+ assert_eq_rendered!(en, "en singular");
+ let fr = td!(Locale::fr, count_arg_to_plural, arg = "fr");
+ assert_eq_rendered!(fr, "fr 2");
+}
+
+#[test]
+fn foreign_key_to_two_plurals() {
+ let count = move || 0;
+ let en = td!(Locale::en, foreign_key_to_two_plurals, count);
+ assert_eq_rendered!(en, "0 items en 0");
+ let fr = td!(Locale::fr, foreign_key_to_two_plurals, count);
+ assert_eq_rendered!(fr, "0 fr singular");
+
+ let count = move || 1;
+ let en = td!(Locale::en, foreign_key_to_two_plurals, count);
+ assert_eq_rendered!(en, "one item en singular");
+ let fr = td!(Locale::fr, foreign_key_to_two_plurals, count);
+ assert_eq_rendered!(fr, "1 fr singular");
+}
+
+#[test]
+fn renamed_plurals_count() {
+ let first_count = move || 0;
+ let second_count = move || 1;
+ let en = td!(Locale::en, renamed_plurals_count, first_count, second_count);
+ assert_eq_rendered!(en, "0 items 1st place");
+ let fr = td!(Locale::fr, renamed_plurals_count, first_count, second_count);
+ assert_eq_rendered!(fr, "0 1re place");
+}
diff --git a/tests/json/src/ranges.rs b/tests/json/src/ranges.rs
index 629cb669..7f796a92 100644
--- a/tests/json/src/ranges.rs
+++ b/tests/json/src/ranges.rs
@@ -5,26 +5,26 @@ use common::*;
fn f32_range() {
// count = 0
let count = move || 0.0;
- let en = td!(Locale::en, f32_range, $ = count);
+ let en = td!(Locale::en, f32_range, count);
assert_eq_rendered!(en, "You are broke");
- let fr = td!(Locale::fr, f32_range, $ = count);
+ let fr = td!(Locale::fr, f32_range, count);
assert_eq_rendered!(fr, "Vous êtes pauvre");
// count = ..0
for i in [-100.34, -57.69, 0.0 - 0.00001] {
let count = move || i;
- let en = td!(Locale::en, f32_range, $ = count);
+ let en = td!(Locale::en, f32_range, count);
assert_eq_rendered!(en, "You owe money");
- let fr = td!(Locale::fr, f32_range, $ = count);
+ let fr = td!(Locale::fr, f32_range, count);
assert_eq_rendered!(fr, "Vous devez de l'argent");
}
// count = _
for i in [100.34, 57.69, 0.0 + 0.00001] {
let count = move || i;
- let en = td!(Locale::en, f32_range, $ = count);
+ let en = td!(Locale::en, f32_range, count);
assert_eq_rendered!(en, format!("You have {}€", i));
- let fr = td!(Locale::fr, f32_range, $ = count);
+ let fr = td!(Locale::fr, f32_range, count);
assert_eq_rendered!(fr, format!("Vous avez {}€", i));
}
}
@@ -33,17 +33,17 @@ fn f32_range() {
fn u32_range() {
// count = 0
let count = move || 0;
- let en = td!(Locale::en, u32_range, $ = count);
+ let en = td!(Locale::en, u32_range, count);
assert_eq_rendered!(en, "0");
- let fr = td!(Locale::fr, u32_range, $ = count);
+ let fr = td!(Locale::fr, u32_range, count);
assert_eq_rendered!(fr, "0");
// count = 1..
for i in [1, 45, 72] {
let count = move || i;
- let en = td!(Locale::en, u32_range, $ = count);
+ let en = td!(Locale::en, u32_range, count);
assert_eq_rendered!(en, "1..");
- let fr = td!(Locale::fr, u32_range, $ = count);
+ let fr = td!(Locale::fr, u32_range, count);
assert_eq_rendered!(fr, "1..");
}
}
@@ -52,16 +52,16 @@ fn u32_range() {
fn u32_range_string() {
// count = 0
let count = 0;
- let en = td_string!(Locale::en, u32_range, $ = count);
+ let en = td_string!(Locale::en, u32_range, count);
assert_eq!(en.to_string(), "0");
- let fr = td_string!(Locale::fr, u32_range, $ = count);
+ let fr = td_string!(Locale::fr, u32_range, count);
assert_eq!(fr.to_string(), "0");
// count = 1..
for count in [1, 45, 72] {
- let en = td_string!(Locale::en, u32_range, $ = count);
+ let en = td_string!(Locale::en, u32_range, count);
assert_eq!(en.to_string(), "1..");
- let fr = td_string!(Locale::fr, u32_range, $ = count);
+ let fr = td_string!(Locale::fr, u32_range, count);
assert_eq!(fr.to_string(), "1..");
}
}
@@ -71,36 +71,36 @@ fn or_range() {
// count = 0 | 5
for i in [0, 5] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count);
assert_eq_rendered!(en, "0 or 5");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count);
assert_eq_rendered!(fr, "0 or 5");
}
// count = 1..5 | 6..10
for i in [1, 4, 6, 9] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count);
assert_eq_rendered!(en, "1..5 | 6..10");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count);
assert_eq_rendered!(fr, "1..5 | 6..10");
}
// count = 10..15 | 20
for i in [10, 12, 14, 20] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count);
assert_eq_rendered!(en, "10..15 | 20");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count);
assert_eq_rendered!(fr, "10..15 | 20");
}
// count = _
for i in [15, 17, 21, 56] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count);
assert_eq_rendered!(en, "fallback with no count");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count);
assert_eq_rendered!(fr, "fallback sans count");
}
}
@@ -110,36 +110,36 @@ fn f32_or_range() {
// count = 0 | 5
for i in [0.0, 5.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count);
assert_eq_rendered!(en, "0 or 5");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count);
assert_eq_rendered!(fr, "0 or 5");
}
// count = 1..5 | 6..10
for i in [1.0, 4.0, 6.0, 9.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count);
assert_eq_rendered!(en, "1..5 | 6..10");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count);
assert_eq_rendered!(fr, "1..5 | 6..10");
}
// count = 10..15 | 20
for i in [10.0, 12.0, 14.0, 20.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count);
assert_eq_rendered!(en, "10..15 | 20");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count);
assert_eq_rendered!(fr, "10..15 | 20");
}
// count = _
for i in [15.0, 17.0, 21.0, 56.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count);
assert_eq_rendered!(en, "fallback with no count");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count);
assert_eq_rendered!(fr, "fallback avec tuple vide");
}
}
@@ -148,33 +148,61 @@ fn f32_or_range() {
fn f32_or_range_string() {
// count = 0 | 5
for count in [0.0, 5.0] {
- let en = td_string!(Locale::en, f32_OR_range, $ = count);
+ let en = td_string!(Locale::en, f32_OR_range, count);
assert_eq!(en, "0 or 5");
- let fr = td_string!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td_string!(Locale::fr, f32_OR_range, count);
assert_eq!(fr, "0 or 5");
}
// count = 1..5 | 6..10
for count in [1.0, 4.0, 6.0, 9.0] {
- let en = td_string!(Locale::en, f32_OR_range, $ = count);
+ let en = td_string!(Locale::en, f32_OR_range, count);
assert_eq!(en, "1..5 | 6..10");
- let fr = td_string!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td_string!(Locale::fr, f32_OR_range, count);
assert_eq!(fr, "1..5 | 6..10");
}
// count = 10..15 | 20
for count in [10.0, 12.0, 14.0, 20.0] {
- let en = td_string!(Locale::en, f32_OR_range, $ = count);
+ let en = td_string!(Locale::en, f32_OR_range, count);
assert_eq!(en, "10..15 | 20");
- let fr = td_string!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td_string!(Locale::fr, f32_OR_range, count);
assert_eq!(fr, "10..15 | 20");
}
// count = _
for count in [15.0, 17.0, 21.0, 56.0] {
- let en = td_string!(Locale::en, f32_OR_range, $ = count);
+ let en = td_string!(Locale::en, f32_OR_range, count);
assert_eq!(en, "fallback with no count");
- let fr = td_string!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td_string!(Locale::fr, f32_OR_range, count);
assert_eq!(fr, "fallback avec tuple vide");
}
}
+
+#[test]
+fn args_to_range() {
+ let count = move || 1;
+ let en = td!(Locale::en, args_to_range, count);
+ assert_eq_rendered!(en, "en 1");
+ let fr = td!(Locale::fr, args_to_range, count);
+ assert_eq_rendered!(fr, "fr 1");
+}
+
+#[test]
+fn count_arg_to_range() {
+ let en = td!(Locale::en, count_arg_to_range, arg = "en");
+ assert_eq_rendered!(en, "en zero");
+ let fr = td!(Locale::fr, count_arg_to_range, arg = "fr");
+ assert_eq_rendered!(fr, "fr zero");
+}
+
+#[test]
+fn renamed_ranges_count() {
+ let first_count = move || 0.0;
+ let second_count = move || 1;
+ let en = td!(Locale::en, renamed_ranges_count, first_count, second_count);
+ assert_eq_rendered!(en, "You are broke 1..5 | 6..10");
+ let fr = td!(Locale::fr, renamed_ranges_count, first_count, second_count);
+ assert_eq_rendered!(fr, "Vous êtes pauvre 1..5 | 6..10");
+}
+
diff --git a/tests/json/src/scoped.rs b/tests/json/src/scoped.rs
index d134e332..3387ace1 100644
--- a/tests/json/src/scoped.rs
+++ b/tests/json/src/scoped.rs
@@ -7,18 +7,18 @@ fn subkey_3() {
let fr_scope = scope_locale!(Locale::fr, subkeys);
let count = || 0;
- let en = td!(en_scope, subkey_3, $ = count);
+ let en = td!(en_scope, subkey_3, count);
assert_eq_rendered!(en, "zero");
- let fr = td!(fr_scope, subkey_3, $ = count);
+ let fr = td!(fr_scope, subkey_3, count);
assert_eq_rendered!(fr, "0");
let count = || 1;
- let en = td!(en_scope, subkey_3, $ = count);
+ let en = td!(en_scope, subkey_3, count);
assert_eq_rendered!(en, "one");
- let fr = td!(fr_scope, subkey_3, $ = count);
+ let fr = td!(fr_scope, subkey_3, count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(en_scope, subkey_3, $ = count);
+ let en = td!(en_scope, subkey_3, count);
assert_eq_rendered!(en, "3");
- let fr = td!(fr_scope, subkey_3, $ = count);
+ let fr = td!(fr_scope, subkey_3, count);
assert_eq_rendered!(fr, "3");
}
diff --git a/tests/json/src/subkeys.rs b/tests/json/src/subkeys.rs
index 0f4f9703..0b4e1ffc 100644
--- a/tests/json/src/subkeys.rs
+++ b/tests/json/src/subkeys.rs
@@ -61,18 +61,18 @@ fn subkey_2_string() {
#[test]
fn subkey_3() {
let count = || 0;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count);
assert_eq_rendered!(fr, "0");
let count = || 1;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count);
assert_eq_rendered!(en, "one");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count);
assert_eq_rendered!(en, "3");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count);
assert_eq_rendered!(fr, "3");
}
diff --git a/tests/json/src/tests.rs b/tests/json/src/tests.rs
index b1c14ac5..59a8fbcc 100644
--- a/tests/json/src/tests.rs
+++ b/tests/json/src/tests.rs
@@ -49,19 +49,19 @@ fn click_count_string() {
#[test]
fn subkey_3() {
let count = || 0;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count);
assert_eq_rendered!(fr, "0");
let count = || 1;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count);
assert_eq_rendered!(en, "one");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count);
assert_eq_rendered!(en, "3");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count);
assert_eq_rendered!(fr, "3");
}
@@ -88,3 +88,19 @@ fn non_copy_arg() {
check_impl_fn(&fr);
assert_eq_rendered!(fr, "count");
}
+
+#[test]
+fn same_lit_type() {
+ let en = td!(Locale::en, same_lit_type);
+ assert_eq_rendered!(en, "true");
+ let fr = td!(Locale::fr, same_lit_type);
+ assert_eq_rendered!(fr, "false");
+}
+
+#[test]
+fn mixed_lit_type() {
+ let en = td!(Locale::en, mixed_lit_type);
+ assert_eq_rendered!(en, "59.89");
+ let fr = td!(Locale::fr, mixed_lit_type);
+ assert_eq_rendered!(fr, "true");
+}
diff --git a/tests/namespaces/locales/en/second_namespace.json b/tests/namespaces/locales/en/second_namespace.json
index 9c9b9d61..6067e568 100644
--- a/tests/namespaces/locales/en/second_namespace.json
+++ b/tests/namespaces/locales/en/second_namespace.json
@@ -1,16 +1,16 @@
{
- "common_key": "second namespace",
- "click_count": "You clicked {{ count }} times",
- "click_to_inc": "Click to increment the counter",
- "subkeys": {
- "subkey_1": "subkey_1",
- "subkey_2": "subkey_2",
- "subkey_3": [
- ["zero", "0"],
- ["one", 1],
- ["{{ count }}", "_"]
- ]
- },
- "foreign_key_to_same_namespace": "before {{ @second_namespace::common_key }} after",
- "foreign_key_to_another_namespace": "before {{ @first_namespace::common_key }} after"
-}
\ No newline at end of file
+ "common_key": "second namespace",
+ "click_count": "You clicked {{ count }} times",
+ "click_to_inc": "Click to increment the counter",
+ "subkeys": {
+ "subkey_1": "subkey_1",
+ "subkey_2": "subkey_2",
+ "subkey_3": [
+ ["zero", "0"],
+ ["one", 1],
+ ["{{ count }}", "_"]
+ ]
+ },
+ "foreign_key_to_same_namespace": "before $t(second_namespace:common_key) after",
+ "foreign_key_to_another_namespace": "before $t(first_namespace:common_key) after"
+}
diff --git a/tests/namespaces/locales/fr/second_namespace.json b/tests/namespaces/locales/fr/second_namespace.json
index 7bdd0ae3..c9ec332e 100644
--- a/tests/namespaces/locales/fr/second_namespace.json
+++ b/tests/namespaces/locales/fr/second_namespace.json
@@ -1,15 +1,15 @@
{
- "common_key": "deuxième namespace",
- "click_count": "Vous avez cliqué {{ count }} fois",
- "click_to_inc": "Cliquez pour incrémenter le compteur",
- "subkeys": {
- "subkey_1": "subkey_1",
- "subkey_2": "subkey_2",
- "subkey_3": [
- ["zero", 0],
- ["{{ count }}", "_"]
- ]
- },
- "foreign_key_to_same_namespace": "before {{ @second_namespace::common_key }} after",
- "foreign_key_to_another_namespace": "before {{ @first_namespace::common_key }} after"
-}
\ No newline at end of file
+ "common_key": "deuxième namespace",
+ "click_count": "Vous avez cliqué {{ count }} fois",
+ "click_to_inc": "Cliquez pour incrémenter le compteur",
+ "subkeys": {
+ "subkey_1": "subkey_1",
+ "subkey_2": "subkey_2",
+ "subkey_3": [
+ ["zero", 0],
+ ["{{ count }}", "_"]
+ ]
+ },
+ "foreign_key_to_same_namespace": "before $t(second_namespace:common_key) after",
+ "foreign_key_to_another_namespace": "before $t(first_namespace:common_key) after"
+}
diff --git a/tests/namespaces/src/first_ns.rs b/tests/namespaces/src/first_ns.rs
index bb29286a..6eaf6ed1 100644
--- a/tests/namespaces/src/first_ns.rs
+++ b/tests/namespaces/src/first_ns.rs
@@ -20,33 +20,33 @@ fn common_key() {
#[test]
fn range_only_en() {
let count = move || 0;
- let en = td!(Locale::en, first_namespace.range_only_en, $ = count);
+ let en = td!(Locale::en, first_namespace.range_only_en, count = count);
assert_eq_rendered!(en, "exact");
for i in -3..0 {
let count = move || i;
- let en = td!(Locale::en, first_namespace.range_only_en, $ = count);
+ let en = td!(Locale::en, first_namespace.range_only_en, count = count);
assert_eq_rendered!(en, "unbounded start");
}
for i in 99..103 {
let count = move || i;
- let en = td!(Locale::en, first_namespace.range_only_en, $ = count);
+ let en = td!(Locale::en, first_namespace.range_only_en, count = count);
assert_eq_rendered!(en, "unbounded end");
}
for i in 1..3 {
let count = move || i;
- let en = td!(Locale::en, first_namespace.range_only_en, $ = count);
+ let en = td!(Locale::en, first_namespace.range_only_en, count = count);
assert_eq_rendered!(en, "excluded end");
}
for i in 3..=8 {
let count = move || i;
- let en = td!(Locale::en, first_namespace.range_only_en, $ = count);
+ let en = td!(Locale::en, first_namespace.range_only_en, count = count);
assert_eq_rendered!(en, "included end");
}
for i in [30, 40, 55, 73] {
let count = move || i;
- let en = td!(Locale::en, first_namespace.range_only_en, $ = count);
+ let en = td!(Locale::en, first_namespace.range_only_en, count = count);
assert_eq_rendered!(en, "fallback");
}
- let fr = td!(Locale::fr, first_namespace.range_only_en, $ = count);
+ let fr = td!(Locale::fr, first_namespace.range_only_en, count = count);
assert_eq_rendered!(fr, "pas de ranges en français");
}
diff --git a/tests/namespaces/src/scoped.rs b/tests/namespaces/src/scoped.rs
index b5d608c3..cae098c9 100644
--- a/tests/namespaces/src/scoped.rs
+++ b/tests/namespaces/src/scoped.rs
@@ -23,35 +23,35 @@ fn scoped_ranges() {
let fr_scope = scope_locale!(Locale::fr, first_namespace);
let count = move || 0;
- let en = td!(en_scope, range_only_en, $ = count);
+ let en = td!(en_scope, range_only_en, count = count);
assert_eq_rendered!(en, "exact");
for i in -3..0 {
let count = move || i;
- let en = td!(en_scope, range_only_en, $ = count);
+ let en = td!(en_scope, range_only_en, count = count);
assert_eq_rendered!(en, "unbounded start");
}
for i in 99..103 {
let count = move || i;
- let en = td!(en_scope, range_only_en, $ = count);
+ let en = td!(en_scope, range_only_en, count = count);
assert_eq_rendered!(en, "unbounded end");
}
for i in 1..3 {
let count = move || i;
- let en = td!(en_scope, range_only_en, $ = count);
+ let en = td!(en_scope, range_only_en, count = count);
assert_eq_rendered!(en, "excluded end");
}
for i in 3..=8 {
let count = move || i;
- let en = td!(en_scope, range_only_en, $ = count);
+ let en = td!(en_scope, range_only_en, count = count);
assert_eq_rendered!(en, "included end");
}
for i in [30, 40, 55, 73] {
let count = move || i;
- let en = td!(en_scope, range_only_en, $ = count);
+ let en = td!(en_scope, range_only_en, count = count);
assert_eq_rendered!(en, "fallback");
}
- let fr = td!(fr_scope, range_only_en, $ = count);
+ let fr = td!(fr_scope, range_only_en, count = count);
assert_eq_rendered!(fr, "pas de ranges en français");
}
@@ -61,18 +61,18 @@ fn scoped_sub_subkeys() {
let fr_scope = scope_locale!(Locale::fr, second_namespace.subkeys);
let count = || 0;
- let en = td!(en_scope, subkey_3, $ = count);
+ let en = td!(en_scope, subkey_3, count = count);
assert_eq_rendered!(en, "zero");
- let fr = td!(fr_scope, subkey_3, $ = count);
+ let fr = td!(fr_scope, subkey_3, count = count);
assert_eq_rendered!(fr, "zero");
let count = || 1;
- let en = td!(en_scope, subkey_3, $ = count);
+ let en = td!(en_scope, subkey_3, count = count);
assert_eq_rendered!(en, "one");
- let fr = td!(fr_scope, subkey_3, $ = count);
+ let fr = td!(fr_scope, subkey_3, count = count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(en_scope, subkey_3, $ = count);
+ let en = td!(en_scope, subkey_3, count = count);
assert_eq_rendered!(en, "3");
- let fr = td!(fr_scope, subkey_3, $ = count);
+ let fr = td!(fr_scope, subkey_3, count = count);
assert_eq_rendered!(fr, "3");
}
diff --git a/tests/namespaces/src/second_ns.rs b/tests/namespaces/src/second_ns.rs
index b9aa5d2d..de569766 100644
--- a/tests/namespaces/src/second_ns.rs
+++ b/tests/namespaces/src/second_ns.rs
@@ -54,19 +54,19 @@ fn subkey_2() {
#[test]
fn subkey_3() {
let count = || 0;
- let en = td!(Locale::en, second_namespace.subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, second_namespace.subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, second_namespace.subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, second_namespace.subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "zero");
let count = || 1;
- let en = td!(Locale::en, second_namespace.subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, second_namespace.subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "one");
- let fr = td!(Locale::fr, second_namespace.subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, second_namespace.subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(Locale::en, second_namespace.subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, second_namespace.subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "3");
- let fr = td!(Locale::fr, second_namespace.subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, second_namespace.subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "3");
}
diff --git a/tests/yaml/src/defaulted.rs b/tests/yaml/src/defaulted.rs
index 025fc522..2e965ad9 100644
--- a/tests/yaml/src/defaulted.rs
+++ b/tests/yaml/src/defaulted.rs
@@ -20,16 +20,16 @@ fn defaulted_interpolation() {
#[test]
fn defaulted_ranges() {
let count = || 0;
- let en = td!(Locale::en, defaulted_ranges, locale = "en", $ = count);
+ let en = td!(Locale::en, defaulted_ranges, locale = "en", count = count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, defaulted_ranges, locale = "en", $ = count);
+ let fr = td!(Locale::fr, defaulted_ranges, locale = "en", count = count);
assert_eq_rendered!(fr, "zero");
for i in [-3, 5, 12] {
let count = move || i;
- let en = td!(Locale::en, defaulted_ranges, locale = "en", $ = count);
+ let en = td!(Locale::en, defaulted_ranges, locale = "en", count = count);
assert_eq_rendered!(en, "this range is declared in locale en");
- let fr = td!(Locale::fr, defaulted_ranges, locale = "en", $ = count);
+ let fr = td!(Locale::fr, defaulted_ranges, locale = "en", count = count);
assert_eq_rendered!(fr, "this range is declared in locale en");
}
}
diff --git a/tests/yaml/src/ranges.rs b/tests/yaml/src/ranges.rs
index 58eed14a..c440865a 100644
--- a/tests/yaml/src/ranges.rs
+++ b/tests/yaml/src/ranges.rs
@@ -5,26 +5,26 @@ use common::*;
fn f32_range() {
// count = 0
let count = move || 0.0;
- let en = td!(Locale::en, f32_range, $ = count);
+ let en = td!(Locale::en, f32_range, count = count);
assert_eq_rendered!(en, "You are broke");
- let fr = td!(Locale::fr, f32_range, $ = count);
+ let fr = td!(Locale::fr, f32_range, count = count);
assert_eq_rendered!(fr, "Vous êtes pauvre");
// count = ..0
for i in [-100.34, -57.69, 0.0 - 0.00001] {
let count = move || i;
- let en = td!(Locale::en, f32_range, $ = count);
+ let en = td!(Locale::en, f32_range, count = count);
assert_eq_rendered!(en, "You owe money");
- let fr = td!(Locale::fr, f32_range, $ = count);
+ let fr = td!(Locale::fr, f32_range, count = count);
assert_eq_rendered!(fr, "Vous devez de l'argent");
}
// count = _
for i in [100.34, 57.69, 0.0 + 0.00001] {
let count = move || i;
- let en = td!(Locale::en, f32_range, $ = count);
+ let en = td!(Locale::en, f32_range, count = count);
assert_eq_rendered!(en, format!("You have {}€", i));
- let fr = td!(Locale::fr, f32_range, $ = count);
+ let fr = td!(Locale::fr, f32_range, count = count);
assert_eq_rendered!(fr, format!("Vous avez {}€", i));
}
}
@@ -33,17 +33,17 @@ fn f32_range() {
fn u32_range() {
// count = 0
let count = move || 0;
- let en = td!(Locale::en, u32_range, $ = count);
+ let en = td!(Locale::en, u32_range, count = count);
assert_eq_rendered!(en, "0");
- let fr = td!(Locale::fr, u32_range, $ = count);
+ let fr = td!(Locale::fr, u32_range, count = count);
assert_eq_rendered!(fr, "0");
// count = 1..
for i in [1, 45, 72] {
let count = move || i;
- let en = td!(Locale::en, u32_range, $ = count);
+ let en = td!(Locale::en, u32_range, count = count);
assert_eq_rendered!(en, "1..");
- let fr = td!(Locale::fr, u32_range, $ = count);
+ let fr = td!(Locale::fr, u32_range, count = count);
assert_eq_rendered!(fr, "1..");
}
}
@@ -53,36 +53,36 @@ fn or_range() {
// count = 0 | 5
for i in [0, 5] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count = count);
assert_eq_rendered!(en, "0 or 5");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count = count);
assert_eq_rendered!(fr, "0 or 5");
}
// count = 1..5 | 6..10
for i in [1, 4, 6, 9] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count = count);
assert_eq_rendered!(en, "1..5 | 6..10");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count = count);
assert_eq_rendered!(fr, "1..5 | 6..10");
}
// count = 10..15 | 20
for i in [10, 12, 14, 20] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count = count);
assert_eq_rendered!(en, "10..15 | 20");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count = count);
assert_eq_rendered!(fr, "10..15 | 20");
}
// count = _
for i in [15, 17, 21, 56] {
let count = move || i;
- let en = td!(Locale::en, OR_range, $ = count);
+ let en = td!(Locale::en, OR_range, count = count);
assert_eq_rendered!(en, "fallback with no count");
- let fr = td!(Locale::fr, OR_range, $ = count);
+ let fr = td!(Locale::fr, OR_range, count = count);
assert_eq_rendered!(fr, "fallback sans count");
}
}
@@ -92,36 +92,36 @@ fn f32_or_range() {
// count = 0 | 5
for i in [0.0, 5.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count = count);
assert_eq_rendered!(en, "0 or 5");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count = count);
assert_eq_rendered!(fr, "0 or 5");
}
// count = 1..5 | 6..10
for i in [1.0, 4.0, 6.0, 9.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count = count);
assert_eq_rendered!(en, "1..5 | 6..10");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count = count);
assert_eq_rendered!(fr, "1..5 | 6..10");
}
// count = 10..15 | 20
for i in [10.0, 12.0, 14.0, 20.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count = count);
assert_eq_rendered!(en, "10..15 | 20");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count = count);
assert_eq_rendered!(fr, "10..15 | 20");
}
// count = _
for i in [15.0, 17.0, 21.0, 56.0] {
let count = move || i;
- let en = td!(Locale::en, f32_OR_range, $ = count);
+ let en = td!(Locale::en, f32_OR_range, count = count);
assert_eq_rendered!(en, "fallback with no count");
- let fr = td!(Locale::fr, f32_OR_range, $ = count);
+ let fr = td!(Locale::fr, f32_OR_range, count = count);
assert_eq_rendered!(fr, "fallback avec tuple vide");
}
}
diff --git a/tests/yaml/src/subkeys.rs b/tests/yaml/src/subkeys.rs
index aebf791f..32a2c2ff 100644
--- a/tests/yaml/src/subkeys.rs
+++ b/tests/yaml/src/subkeys.rs
@@ -27,18 +27,18 @@ fn subkey_2() {
#[test]
fn subkey_3() {
let count = || 0;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "0");
let count = || 1;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "one");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "3");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "3");
}
diff --git a/tests/yaml/src/tests.rs b/tests/yaml/src/tests.rs
index cc9a9bd6..b173afe2 100644
--- a/tests/yaml/src/tests.rs
+++ b/tests/yaml/src/tests.rs
@@ -34,18 +34,18 @@ fn click_count() {
#[test]
fn subkey_3() {
let count = || 0;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "zero");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "0");
let count = || 1;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "one");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "1");
let count = || 3;
- let en = td!(Locale::en, subkeys.subkey_3, $ = count);
+ let en = td!(Locale::en, subkeys.subkey_3, count = count);
assert_eq_rendered!(en, "3");
- let fr = td!(Locale::fr, subkeys.subkey_3, $ = count);
+ let fr = td!(Locale::fr, subkeys.subkey_3, count = count);
assert_eq_rendered!(fr, "3");
}