Skip to content

Releases: Baptistemontan/leptos_i18n

v0.5.0-rc1

09 Nov 01:18
Compare
Choose a tag to compare
v0.5.0-rc1 Pre-release
Pre-release

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 to Locale, 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

New Contributors

Full Changelog: v0.5.0-gamma2...v0.5.0-rc1

v0.4.2

28 Oct 18:09
Compare
Choose a tag to compare

What's Changed

Full Changelog: v0.4.1...v0.4.2

v0.5.0-gamma2

24 Oct 18:53
Compare
Choose a tag to compare
v0.5.0-gamma2 Pre-release
Pre-release

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

Full Changelog: v0.5.0-gamma...v0.5.0-gamma2

v0.5.0-gamma

13 Oct 23:23
Compare
Choose a tag to compare
v0.5.0-gamma Pre-release
Pre-release

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

Full Changelog: v0.5.0-beta...v0.5.0-gamma

v0.4.1

21 Sep 11:25
Compare
Choose a tag to compare

What's Changed

Full Changelog: v0.4.0...v0.4.1

v0.5.0-beta

17 Sep 18:20
Compare
Choose a tag to compare
v0.5.0-beta Pre-release
Pre-release

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

Full Changelog: v0.4.0...v0.5.0-beta

v0.4.0

17 Sep 17:42
Compare
Choose a tag to compare

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"

Read more

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"

Read more

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>
}

Read more

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);

Read more

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.

Read more

Formatters

You can now specify a formatter for a value:

{
  "key": "{{ var, formatter }}"
}

Currently supported formatters:

  • Number
  • Date
  • Time
  • DateTime
  • List

Read more

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

New Contributors

Full Changelog: v0.3.3...v0.4.0

v0.4.0-beta2

17 Sep 13:35
Compare
Choose a tag to compare
v0.4.0-beta2 Pre-release
Pre-release

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

20 Aug 18:57
Compare
Choose a tag to compare
v0.4.0-beta Pre-release
Pre-release

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"

Read more

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"

Read more

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>
}

Read more

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);

Read more

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.

Read more

Formatters

You can now specify a formatter for a value:

{
  "key": "{{ var, formatter }}"
}

Currently supported formatters:

  • Number
  • Date
  • Time
  • DateTime
  • List

Read more

Bugfixes

There are also some bugfixes and improvement that I won't list here.

What's Changed

New Contributors

Full Changelog: v0.3.3...v0.4.0-beta

v0.3.3

22 Feb 21:20
Compare
Choose a tag to compare

Improved some docs and fixed a bug with non-copy args passed as arguments to the t! macro.

What's Changed

Full Changelog: v0.3.2...v0.3.3