Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptistemontan committed Aug 30, 2023
2 parents ab0ac07 + c2d5874 commit 71385d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ view! { cx,
}
```

The only restriction on variables/components names is that it must be a valid rust identifier. You can define variables inside components: `You have clicked <b>{{ count }}</b> times`, and you can nest components, even with the same identifier: `<b><b><i>VERY IMPORTANT</i></b></b>`.
The only restriction on variables/components names is that it must be a valid rust identifier (`-` are allowed, but are replaced by `_` for the identifier). You can define variables inside components: `You have clicked <b>{{ count }}</b> times`, and you can nest components, even with the same identifier: `<b><b><i>VERY IMPORTANT</i></b></b>`.

For plain strings, `.get_keys().$key` return a `&'static str`, but for interpolated keys it return a struct that implement a builder pattern where variables are passed to functions called `.var_$name(var)` and components to `.comp_$name(comp)`, so for the counter above but without the `t!` macro it will look like this:

Expand Down Expand Up @@ -413,7 +413,7 @@ Accessing your values with the `t!` macro will be like this:
t!(i18n, $namespace.$key)
```

You can have as many namespaces as you want, but the name should be a valid rust identifier.
You can have as many namespaces as you want, but the name should be a valid rust identifier (same as component/variable names, `-` are replaced by `_`).

### Examples

Expand Down
3 changes: 2 additions & 1 deletion leptos_i18n_macro/src/load_locales/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl Key {

pub fn try_new(name: &str) -> Option<Self> {
let name = name.trim();
let ident = syn::parse_str::<syn::Ident>(name).ok()?;
let ident_repr = name.replace('-', "_");
let ident = syn::parse_str::<syn::Ident>(&ident_repr).ok()?;
Some(Key {
name: name.to_string(),
ident,
Expand Down

0 comments on commit 71385d4

Please sign in to comment.