Releases: Baptistemontan/leptos_i18n
v0.5.0-rc1
v0.5.0-rc1
Other than the update to Leptos v0.7.0-rc1, this release is mostly bug fixes and internal refactors.
The new things are:
t_plural!
, see book- The addition of the
direction
method toLocale
, which gives you the script direction of the variant. - The html "dir" attribute is being set alongside the "lang" attribute, thanks @sabify
What's Changed
t_plural!
by @Baptistemontan in #149- update t_string by @Baptistemontan in #154
- Simplify internal cfgs by @Baptistemontan in #155
- fix: change html direction based on selected language by @sabify in #156
- Allow use of ssr and hydrate cfg together without compile error by @Baptistemontan in #157
- fix: update deps and unpin was-bindgen over leptos and leptos-use by @sabify in #159
- Macro hygiene by @Baptistemontan in #160
- Fix locale resolution of the router not reflecting on the client by @Baptistemontan in #162
- Macros doctests by @Baptistemontan in #158
New Contributors
Full Changelog: v0.5.0-gamma2...v0.5.0-rc1
v0.4.2
What's Changed
- fixed t_string and updated docs by @Baptistemontan in #153
Full Changelog: v0.4.1...v0.4.2
v0.5.0-gamma2
v0.5.0-gamma2
This new pre-release updates to leptos v0.5.0-rc0
and brings utilities for icu datagen with the new leptos_i18n_build
crate. See the datagen section
of the book.
What's Changed
- split macro crate into parser and macro by @Baptistemontan in #145
- crate for build.rs utilities by @Baptistemontan in #146
Full Changelog: v0.5.0-gamma...v0.5.0-gamma2
v0.5.0-gamma
Binary size improvement
This release brings two major features axed toward reducing binary sizes: lazy loading of translations and custom providers for ICU4X. You can find more informations about those two in the new Reduce binary size
section of the book.
JSON 5
Now support JSON5 files format with the "json5_files" feature.
Header options
Now take options to pass down to leptos-use
for header setter/getter.
Options builder
Options are now a builder instead of taking params one by one. This is done to later add more options without introducing breaking changes
Leptos -gamma2 release
This release works with the new -gamma2 release from Leptos
What's Changed
- Header options by @Baptistemontan in #138
- Use a builder for context options by @Baptistemontan in #140
- Removed some code dedup by @Baptistemontan in #141
- Reduce ICU footprint by @Baptistemontan in #144
- Dyn load by @Baptistemontan in #139
- Support for JSON5 file format by @Baptistemontan in #143
Full Changelog: v0.5.0-beta...v0.5.0-gamma
v0.4.1
v0.5.0-beta
v0.5.0-beta
This is a port of v0.4.0
to Leptos v0.7.0-beta
, there should'nt be any breaking changes other than the one caused by Leptos.
What's Changed
- Update to Leptos v0.7 by @Baptistemontan in #132
Full Changelog: v0.4.0...v0.5.0-beta
v0.4.0
v0.4.0
This release add a bunch of things, I will briefly cover them here, but you can read about them in the updated book.
I18next JSON v4
This version tries to follow more closely the I18next JSON v4 format, and for this some adjustement have been made:
- Proper plurals
- Changed "Foreign keys" to follow I18next nesting syntax
- Added formatters
Proper Plurals
The old versions of plurals were a weird homemade version that was actually not that great, they still exist and are renommed "Ranges", but you can now create actual plurals:
{
"key_one": "one item",
"key_other": "{{ count }} items"
}
t!(i18n, key, count = move || 0); // -> "0 items"
t!(i18n, key, count = move || 1); // -> "one item"
t!(i18n, key, count = move || 2); // -> "2 items"
And also support ordinal plurals:
{
"key_ordinal_one": "{{ count }}st place",
"key_ordinal_two": "{{ count }}nd place",
"key_ordinal_few": "{{ count }}rd place",
"key_ordinal_other": "{{ count }}th place"
}
t!(i18n, key, count = move || 1); // -> "1st place"
t!(i18n, key, count = move || 2); // -> "2nd place"
t!(i18n, key, count = move || 3); // -> "3rd place"
t!(i18n, key, count = move || 4); // -> "4th place"
t!(i18n, key, count = move || 41); // -> "41st place"
Nesting
Before, the syntax for foreign keys was {{ @key, arg = value, ..}}
, this now follows I18next nesting syntax: $t(key, { "arg": value })
.
The rework is really powerful, as you can do stuff like:
{
"key": "{{ arg }}",
"string_arg": "$t(key, {\"arg\": \"str\"})",
"boolean_arg": "$t(key, {\"arg\": true})",
"number_arg": "$t(key, {\"arg\": 56})",
"interpolated_arg": "$t(key, {\"arg\": \"value: {{ new_arg }}\"})",
"foreign_key_arg": "$t(key, {\"arg\": \"value: $t(interpolated_arg)\"})"
}
t!(i18n, string_arg); // -> "str"
t!(i18n, boolean_arg); // -> "true"
t!(i18n, number_arg); // -> "56"
t!(i18n, interpolated_arg, new_arg = "a value"); // -> "value: a value"
t!(i18n, foreign_key_arg, new_arg = "a value"); // -> "value: value: a value"
Or use them to have plurals with 2 different count:
{
"key": "$t(key_boys, {\"count\": \"{{ boys_count }}\"}) and $t(key_girls, {\"count\": \"{{ girls_count }}\"})",
"key_boys_one": "{{ count }} boy",
"key_boys_other": "{{ count }} boys",
"key_girls_one": "{{ count }} girl",
"key_girls_other": "{{ count }} girls"
}
t!(i18n, key, boys_count = move || 0, girls_count = move || 0); // -> "0 boys and 0 girls"
t!(i18n, key, boys_count = move || 0, girls_count = move || 1); // -> "0 boys and 1 girl"
t!(i18n, key, boys_count = move || 1, girls_count = move || 0); // -> "1 boy and 0 girls"
t!(i18n, key, boys_count = move || 56, girls_count = move || 39); // -> "56 boys and 39 girls"
Routing
You can now use a router to have a "/:locale/..." prefix for the URL !
use crate::i18n::I18nRoute;
use leptos::*;
use leptos_router::*;
view! {
<Router>
<Routes>
<I18nRoute>
<Route path="/" view=Home />
<Route path="/counter" view=Counter />
</I18nRoute>
</Routes>
</Router>
}
Scoping
You can turn this:
let i18n = use_i18n();
t!(i18n, namespace.subkeys.value);
t!(i18n, namespace.subkeys.more_subkeys.subvalue);
t!(i18n, namespace.subkeys.more_subkeys.another_subvalue);
Into this:
let i18n = use_i18n();
let i18n = scope_i18n!(i18n, namespace.subkeys);
t!(i18n, value);
t!(i18n, more_subkeys.subvalue);
t!(i18n, more_subkeys.another_subvalue);
Context provider
provide_i18n_context()
is now deprecated. Now use I18nContextProvider
.
Sub contexts
You can now create subcontext with a subcontext provider:
use crate::i18n::*;
use leptos::*;
#[component]
fn Foo() -> impl IntoView {
view! {
<I18nContextProvider>
<I18nSubContextProvider>
<Sub />
</I18nSubContextProvider>
<Home />
</I18nContextProvider>
}
}
#[component]
fn Sub() -> impl IntoView {
let i18n = use_i18n();
view! {
<p>{t!(i18n, sub)}</p>
}
}
In this snippet the Sub
component will have a context seperated from the "main" context.
Formatters
You can now specify a formatter for a value:
{
"key": "{{ var, formatter }}"
}
Currently supported formatters:
- Number
- Date
- Time
- DateTime
- List
Directives
I18nContext
now implement Directives
, so you can now do <div use:i18n />
and it will set the "lang" attributes on it, reactively: <div lang="en"></div>
.
Bugfixes
There are also some bugfixes and improvement that I won't list here.
What's Changed
- fix CI by @Baptistemontan in #104
- Feature to replace translations by the key during dev by @Baptistemontan in #103
- Fixed an error when using
t_string!
with thedebug_interpolations
feature by @Baptistemontan in #102 - Fix csr locale fetching by @Baptistemontan in #108
- private macro to declare locales in code by @Baptistemontan in #105
- Add end2end testing for examples by @Baptistemontan in #107
- Scoped contexts by @Baptistemontan in #111
- Add a
i18nRoute
component for locale based routing by @Baptistemontan in #113 - Extends context API by @Baptistemontan in #114
- Use
typed-builder
for interpolations by @Baptistemontan in #117 - Refactor to use
leptos_use::use_locales
by @Baptistemontan in #120 - icu4x integration by @Baptistemontan in #121
- Fix redirection bug with routing when changing locale in explicit default locale suffix by @Baptistemontan in #124
- Rework plurals by @Baptistemontan in #125
- Rework Foreign keys to follow i18next nesting syntax and behavior by @Baptistemontan in #128
- Typo fixes by @mrkiffie in #129
- Update doc for the incoming
v0.4
by @Baptistemontan in #131
New Contributors
Full Changelog: v0.3.3...v0.4.0
v0.4.0-beta2
Breaking changes
Provide context
provide_i18n_context()
is now deprecated. Now use I18nContextProvider
.
Crate features
Two features are removed: sync
and serde
.
sync
was added with v0.4.0-beta
but is now removed, as it is always on.
serde
is removed because some new bounds have been added to the Locale
trait, some of those are Serialize
and DeserializeOwned
, so the serde
features is now always active.
New features
Directives
I18nContext
now implement Directives
, so you can now do <div use:i18n />
and it will set the "lang" attributes on it, reactively: <div lang="en"></div>
.
Full Changelog: v0.4.0-beta...v0.4.0-beta2
v0.4.0-beta
v0.4.0-beta
This release add a bunch of things, I will briefly cover them here, but you can read about them in the updated book.
I18next JSON v4
This version tries to follow more closely the I18next JSON v4 format, and for this some adjustement have been made:
- Proper plurals
- Changed "Foreign keys" to follow I18next nesting syntax
- Added formatters
Proper Plurals
The old versions of plurals were a weird homemade version that was actually not that great, they still exist and are renommed "Ranges", but you can now create actual plurals:
{
"key_one": "one item",
"key_other": "{{ count }} items"
}
t!(i18n, key, count = move || 0); // -> "0 items"
t!(i18n, key, count = move || 1); // -> "one item"
t!(i18n, key, count = move || 2); // -> "2 items"
And also support ordinal plurals:
{
"key_ordinal_one": "{{ count }}st place",
"key_ordinal_two": "{{ count }}nd place",
"key_ordinal_few": "{{ count }}rd place",
"key_ordinal_other": "{{ count }}th place"
}
t!(i18n, key, count = move || 1); // -> "1rst place"
t!(i18n, key, count = move || 2); // -> "2nd place"
t!(i18n, key, count = move || 3); // -> "3rd place"
t!(i18n, key, count = move || 4); // -> "4th place"
t!(i18n, key, count = move || 41); // -> "41st place"
Nesting
Before, the syntax for foreign keys was {{ @key, arg = value, ..}}
, this now follows I18next nesting syntax: $t(key, { "arg": value })
.
The rework is really powerful, as you can do stuff like:
{
"key": "{{ arg }}",
"string_arg": "$t(key, {\"arg\": \"str\"})",
"boolean_arg": "$t(key, {\"arg\": true})",
"number_arg": "$t(key, {\"arg\": 56})",
"interpolated_arg": "$t(key, {\"arg\": \"value: {{ new_arg }}\"})",
"foreign_key_arg": "$t(key, {\"arg\": \"value: $t(interpolated_arg)\"})"
}
t!(i18n, string_arg); // -> "str"
t!(i18n, boolean_arg); // -> "true"
t!(i18n, number_arg); // -> "56"
t!(i18n, interpolated_arg, new_arg = "a value"); // -> "value: a value"
t!(i18n, foreign_key_arg, new_arg = "a value"); // -> "value: value: a value"
Or use them to have plurals with 2 different count:
{
"key": "$t(key_boys, {\"count\": \"{{ boys_count }}\"}) and $t(key_girls, {\"count\": \"{{ girls_count }}\"})",
"key_boys_one": "{{ count }} boy",
"key_boys_other": "{{ count }} boys",
"key_girls_one": "{{ count }} girl",
"key_girls_other": "{{ count }} girls"
}
t!(i18n, key, boys_count = move || 0, girls_count = move || 0); // -> "0 boys and 0 girls"
t!(i18n, key, boys_count = move || 0, girls_count = move || 1); // -> "0 boys and 1 girl"
t!(i18n, key, boys_count = move || 1, girls_count = move || 0); // -> "1 boy and 0 girls"
t!(i18n, key, boys_count = move || 56, girls_count = move || 39); // -> "56 boys and 39 girls"
Routing
You can now use a router to have a "/:locale/..." prefix for the URL !
use crate::i18n::I18nRoute;
use leptos::*;
use leptos_router::*;
view! {
<Router>
<Routes>
<I18nRoute>
<Route path="/" view=Home />
<Route path="/counter" view=Counter />
</I18nRoute>
</Routes>
</Router>
}
Scoping
You can turn this:
let i18n = use_i18n();
t!(i18n, namespace.subkeys.value);
t!(i18n, namespace.subkeys.more_subkeys.subvalue);
t!(i18n, namespace.subkeys.more_subkeys.another_subvalue);
Into this:
let i18n = use_i18n();
let i18n = scope_i18n!(i18n, namespace.subkeys);
t!(i18n, value);
t!(i18n, more_subkeys.subvalue);
t!(i18n, more_subkeys.another_subvalue);
Sub contexts
You can now create subcontext with a subcontext provider:
use crate::i18n::*;
use leptos::*;
use leptos_i18n::context::I18nSubContextProvider;
#[component]
fn Foo() -> impl IntoView {
provide_i18n_context();
view! {
<I18nSubContextProvider>
<Sub />
</I18nSubContextProvider>
<Home />
}
}
#[component]
fn Sub() -> impl IntoView {
let i18n = use_i18n();
view! {
<p>{t!(i18n, sub)}</p>
}
}
In this snippet the Sub
component will have a context seperated from the "main" context.
Formatters
You can now specify a formatter for a value:
{
"key": "{{ var, formatter }}"
}
Currently supported formatters:
- Number
- Date
- Time
- DateTime
- List
Bugfixes
There are also some bugfixes and improvement that I won't list here.
What's Changed
- fix CI by @Baptistemontan in #104
- Feature to replace translations by the key during dev by @Baptistemontan in #103
- Fixed an error when using
t_string!
with thedebug_interpolations
feature by @Baptistemontan in #102 - Fix csr locale fetching by @Baptistemontan in #108
- private macro to declare locales in code by @Baptistemontan in #105
- Add end2end testing for examples by @Baptistemontan in #107
- Scoped contexts by @Baptistemontan in #111
- Add a
i18nRoute
component for locale based routing by @Baptistemontan in #113 - Extends context API by @Baptistemontan in #114
- Use
typed-builder
for interpolations by @Baptistemontan in #117 - Refactor to use
leptos_use::use_locales
by @Baptistemontan in #120 - icu4x integration by @Baptistemontan in #121
- Fix redirection bug with routing when changing locale in explicit default locale suffix by @Baptistemontan in #124
- Rework plurals by @Baptistemontan in #125
- Rework Foreign keys to follow i18next nesting syntax and behavior by @Baptistemontan in #128
- Typo fixes by @mrkiffie in #129
- Update doc for the incoming
v0.4
by @Baptistemontan in #131
New Contributors
Full Changelog: v0.3.3...v0.4.0-beta
v0.3.3
Improved some docs and fixed a bug with non-copy args passed as arguments to the t!
macro.
What's Changed
- Clone args for
t!
by @Baptistemontan in #98
Full Changelog: v0.3.2...v0.3.3