Skip to content

Commit e57e7c5

Browse files
authored
Add READMEs for crates (#47)
1 parent 6e211d5 commit e57e7c5

File tree

12 files changed

+333
-26
lines changed

12 files changed

+333
-26
lines changed

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,32 @@ repos:
5959
alias: clippy-hydrate
6060
name: clippy-hydrate
6161
args: [--features=hydrate, --, -A, clippy::comparison-chain, -Dwarnings]
62+
- repo: https://github.com/mondeja/cargo-readme
63+
# TODO: Use upstream after https://github.com/webern/cargo-readme/pull/104 is released
64+
rev: add-pre-commit-hook
65+
hooks:
66+
- id: cargo-readme
67+
alias: cargo-readme-workspace
68+
name: cargo-readme-workspace
69+
args:
70+
[
71+
--project-root=leptos-fluent,
72+
--output=../README.md,
73+
--template=../README.tpl,
74+
]
75+
- id: cargo-readme
76+
alias: cargo-readme-leptos-fluent
77+
name: cargo-readme-leptos-fluent
78+
args:
79+
[
80+
--project-root=leptos-fluent,
81+
--output=README.md,
82+
--template=../README.tpl,
83+
]
84+
- id: cargo-readme
85+
alias: cargo-readme-leptos-fluent-macros
86+
name: cargo-readme-leptos-fluent-macros
87+
args: [--project-root=leptos-fluent-macros, --output=README.md]
6288
- repo: https://github.com/tcort/markdown-link-check
6389
rev: v3.11.2
6490
hooks:

CHANGELOG.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
# CHANGELOG
22

3-
## 2024-03-10 - v0.0.19
3+
## 2024-03-10 - v0.0.20
44

5-
### New features
6-
7-
- Add hydration support with `hydrate` feature.
8-
9-
### Changes
10-
11-
- `I18n` context is now `Copy`able.
5+
### Breaking changes
126

13-
## 2024-03-10 - v0.0.18
7+
- One of the features `csr`, `hydrate` or `ssr` must be enabled.
148

159
### New features
1610

1711
- Add SSR support.
18-
- Added features `csr` and `ssr` for client-side rendering (CSR) and
19-
server-side rendering (SSR).
12+
- Add hydration support.
13+
- Added features `csr`, `hydrate` and `ssr`.
2014

21-
### Breaking changes
15+
### Changes
2216

23-
- One of the features `csr` or `ssr` must be explicitly enabled.
17+
- `I18n` context is now `Copy`able.
18+
- Crates now offers READMEs.
2419

2520
## 2024-03-07 - v0.0.17
2621

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# leptos-fluent
22

3+
<!-- This file has been autogenerated.
4+
To update it, change the content of `leptos-fluent/src/lib.rs`
5+
and run `pre-commit run -a cargo-readme`
6+
-->
7+
38
[![Crates.io](https://img.shields.io/crates/v/leptos-fluent)](https://crates.io/crates/leptos-fluent)
49
[![License](https://img.shields.io/crates/l/leptos-fluent?logo=mit)](https://github.com/mondeja/leptos-fluent/blob/master/LICENSE.md)
510
[![Tests](https://img.shields.io/github/actions/workflow/status/mondeja/leptos-fluent/ci.yml?label=tests&logo=github)](https://github.com/mondeja/leptos-fluent/actions)
@@ -51,7 +56,7 @@ bar = ¡Hola, { $arg1 } y { $arg2 }!
5156

5257
You can use `leptos-fluent` as follows:
5358

54-
```rust,ignore
59+
```rust
5560
use fluent_templates::static_loader;
5661
use leptos::*;
5762
use leptos_fluent::{leptos_fluent, tr, move_tr};

README.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# leptos-fluent
2+
3+
<!-- This file has been autogenerated.
4+
To update it, change the content of `leptos-fluent/src/lib.rs`
5+
and run `pre-commit run -a cargo-readme`
6+
-->
7+
8+
{{readme}}

leptos-fluent-macros/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ version = "0.0.19"
66
license = "MIT"
77
documentation = "https://docs.rs/leptos-fluent"
88
repository = "https://github.com/mondeja/leptos-fluent"
9+
readme = "README.md"
910

1011
[lib]
1112
proc-macro = true
13+
path = "src/lib.rs"
1214

1315
[dependencies]
1416
proc-macro2 = "1"

leptos-fluent-macros/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# leptos-fluent-macros
2+
3+
<!-- This file has been autogenerated.
4+
To update it, change the content of `leptos-fluent-macros/src/lib.rs`
5+
and run `pre-commit run -a cargo-readme`
6+
-->
7+
8+
Macros for the leptos-fluent crate.
9+
10+
See [leptos-fluent] for more information.
11+
12+
[leptos-fluent]: https://crates.io/crates/leptos-fluent

leptos-fluent-macros/README.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# leptos-fluent-macros
2+
3+
<!-- This file has been autogenerated.
4+
To update it, change the content of `leptos-fluent-macros/src/lib.rs`
5+
and run `pre-commit run -a cargo-readme`
6+
-->
7+
8+
{{readme}}

leptos-fluent-macros/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Macros for the leptos-fluent crate.
2+
//!
3+
//! See [leptos-fluent] for more information.
4+
//!
5+
//! [leptos-fluent]: https://crates.io/crates/leptos-fluent
6+
17
extern crate proc_macro;
28

39
mod languages;

leptos-fluent/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
name = "leptos-fluent"
33
description = "Fluent framework for internationalization of Leptos applications"
44
edition = "2021"
5-
version = "0.0.19"
5+
version = "0.0.20"
66
license = "MIT"
77
documentation = "https://docs.rs/leptos-fluent"
88
repository = "https://github.com/mondeja/leptos-fluent"
9+
readme = "README.md"
910

1011
[dependencies]
1112
leptos-fluent-macros = { path = "../leptos-fluent-macros" }

leptos-fluent/README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# leptos-fluent
2+
3+
<!-- This file has been autogenerated.
4+
To update it, change the content of `leptos-fluent/src/lib.rs`
5+
and run `pre-commit run -a cargo-readme`
6+
-->
7+
8+
[![Crates.io](https://img.shields.io/crates/v/leptos-fluent)](https://crates.io/crates/leptos-fluent)
9+
[![License](https://img.shields.io/crates/l/leptos-fluent?logo=mit)](https://github.com/mondeja/leptos-fluent/blob/master/LICENSE.md)
10+
[![Tests](https://img.shields.io/github/actions/workflow/status/mondeja/leptos-fluent/ci.yml?label=tests&logo=github)](https://github.com/mondeja/leptos-fluent/actions)
11+
[![docs.rs](https://img.shields.io/docsrs/leptos-fluent?logo=docs.rs)][documentation]
12+
13+
Internationalization framework for [Leptos] using [fluent-templates].
14+
15+
## Installation
16+
17+
Add the following to your `Cargo.toml` file:
18+
19+
```toml
20+
[dependencies]
21+
leptos-fluent = "0.0.19"
22+
fluent-templates = "0.9"
23+
24+
[features]
25+
csr = ["leptos-fluent/csr"]
26+
hydrate = ["leptos-fluent/hydrate"]
27+
ssr = ["leptos-fluent/ssr"]
28+
```
29+
30+
## Usage
31+
32+
Giving the following directory structure:
33+
34+
```plaintext
35+
.
36+
├── 📄 Cargo.toml
37+
├── 📁 locales
38+
│ ├── 📄 en.ftl
39+
│ └── 📄 es.ftl
40+
└── 📁 src
41+
├── 📄 main.rs
42+
└── 📄 lib.rs
43+
```
44+
45+
With Fluent files _en.ftl_ and _es.ftl_:
46+
47+
```ftl
48+
foo = Hello, world!
49+
bar = Hello, { $arg1 } and { $arg2 }!
50+
```
51+
52+
```ftl
53+
foo = ¡Hola, mundo!
54+
bar = ¡Hola, { $arg1 } y { $arg2 }!
55+
```
56+
57+
You can use `leptos-fluent` as follows:
58+
59+
```rust
60+
use fluent_templates::static_loader;
61+
use leptos::*;
62+
use leptos_fluent::{leptos_fluent, tr, move_tr};
63+
64+
static_loader! {
65+
static TRANSLATIONS = {
66+
locales: "./locales",
67+
fallback_language: "en",
68+
};
69+
}
70+
71+
#[component]
72+
pub fn App() -> impl IntoView {
73+
leptos_fluent! {{
74+
// Path to the locales directory, relative to Cargo.toml file.
75+
locales: "./locales",
76+
// Static translations struct provided by fluent-templates.
77+
translations: TRANSLATIONS,
78+
79+
// Client side options (for `csr` and `hydrate`)
80+
// ---------------------------------------------
81+
// Synchronize `<html lang="...">` attribute with the current
82+
// language using `leptos::create_effect`. By default, it is `false`.
83+
sync_html_tag_lang: true,
84+
// Discover the initial language of the user from the URL.
85+
// By default, it is `false`.
86+
initial_language_from_url: true,
87+
// URL parameter name to use discovering the initial language
88+
// of the user. By default is `"lang"`.
89+
initial_language_from_url_param: "lang",
90+
// Set the discovered initial language of the user from
91+
// the URL in local storage. By default, it is `false`.
92+
initial_language_from_url_to_localstorage: true,
93+
// Get the initial language from local storage if not found
94+
// in an URL param. By default, it is `false`.
95+
initial_language_from_localstorage: true,
96+
// Get the initial language from `navigator.languages` if not
97+
// found in the local storage. By default, it is `false`.
98+
initial_language_from_navigator: true,
99+
// Name of the field in local storage to get and set the
100+
// current language of the user. By default, it is `"lang"`.
101+
localstorage_key: "language",
102+
}};
103+
104+
view! {
105+
<ChildComponent />
106+
}
107+
}
108+
109+
#[component]
110+
fn ChildComponent() -> impl IntoView {
111+
// Use `tr!` and `move_tr!` macros to translate strings.
112+
view! {
113+
<p>
114+
<span>{move || tr!("foo")}</span>
115+
<span>{move_tr!("bar", {
116+
"arg1" => "value1",
117+
"arg2" => "value2",
118+
})}</span>
119+
</p>
120+
}
121+
}
122+
```
123+
124+
## Resources
125+
126+
- [Quickstart]
127+
- [Examples]
128+
- [Documentation]
129+
130+
## Roadmap
131+
132+
Leptos-fluent is currently ready for most use cases. However, it is still in an
133+
early stage of development and the API may contain breaking changes through
134+
v0.0.X releases. I'm trying to release the API at v0.1.0 as stable as possible.
135+
136+
[leptos]: https://leptos.dev/
137+
[fluent-templates]: https://github.com/XAMPPRocky/fluent-templates
138+
[quickstart]: https://docs.rs/leptos-fluent/latest/leptos_fluent/macro.leptos_fluent.html
139+
[examples]: https://github.com/mondeja/leptos-fluent/tree/master/examples
140+
[documentation]: https://docs.rs/leptos-fluent

0 commit comments

Comments
 (0)