-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathfluent-grammar.rs
More file actions
233 lines (227 loc) · 8.37 KB
/
Copy pathfluent-grammar.rs
File metadata and controls
233 lines (227 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//! This example demonstrates many of the Fluent grammar constructs, and how they are
//! used in dioxus-i18n.
//! This performs a lookup only, no additional translation files are provided
use dioxus::prelude::*;
use dioxus_i18n::{prelude::*, tid};
use unic_langid::langid;
use std::path::PathBuf;
fn main() {
launch(app);
}
#[allow(non_snake_case)]
#[component]
fn Body() -> Element {
rsx! {
table {
tbody {
tr {
td { "Simple message" }
td { {tid!("simple-message")} }
}
tr {
td { "Non-existing message: id provided by default when using tid! macro" }
td { {tid!("non-existing-message")} }
}
tr {
td { "Message with a variable" }
td { {tid!("message-with-variable", name: "Value 1")} }
}
tr {
td { }
td { {tid!("message-with-variable", name: "Value 2")} }
}
tr {
td { "Reference to a term" }
td { {tid!("message-referencing-a-term")} }
}
tr {
td { "Use of special characters." }
td { {tid!("message-with-special-character")} }
}
tr {
td { "Message with blanks." }
td { "'" {tid!("blank-is-removed")} "'" }
}
tr {
td { }
td { "'" {tid!("blank-is-preserved")} "'" }
}
tr {
td { "Message with attributes: root" }
td { {tid!("message-with-attributes")} }
}
tr {
td { "Message with attributes: attribute" }
td { {tid!("message-with-attributes.placeholder")} }
}
tr {
td { }
td { {tid!("message-with-attributes.aria-label")} }
}
tr {
td { }
td { {tid!("message-with-attributes.title")} }
}
tr {
td { "Message with attributes: not existing" }
td { {tid!("message-with-attributes.not-existing")} }
}
tr {
td { "Message with attributes: invalid" }
td { {tid!("message-with-attributes.placeholder.invalid")} }
}
tr {
td { "Message with quotes: cryptic" }
td { {tid!("literal-quote-cryptic")} }
}
tr {
td { "Message with quotes: preferred" }
td { {tid!("literal-quote-preferred")} }
}
tr {
td { "Message with Unicode characters: cryptic" }
td { {tid!("unicode-cryptic")} }
}
tr {
td { "Message with Unicode characters: preferred" }
td { {tid!("unicode-preferred")} }
}
tr {
td { "Message with a placeable: single-line" }
td { {tid!("line-single")} }
}
tr {
td { "Message with a placeable: single-line" }
td { {tid!("single-line")} }
}
tr {
td { "Message with a placeable: multi-line (1)" }
td { {tid!("multi-line")} }
}
tr {
td { "Message with a placeable: multi-line (2)" }
td { pre { {tid!("multi-line")} } }
}
tr {
td { "Message with a placeable: block-line (1)" }
td { {tid!("block-line")} }
}
tr {
td { "Message with a placeable: block-line (2)" }
td { pre { {tid!("block-line")} } }
}
tr {
td { "Message using functions: no function" }
td { pre { {tid!("time-elapsed-no-function", duration: 23.7114812589)} } }
}
tr {
td { "Message using functions: function" }
td { pre { {tid!("time-elapsed-function", duration: 23.7114812589)} } }
}
tr {
td { "Reference to a message" }
td { {tid!("message-referencing-another-message")} }
}
tr {
td { "Message selection: plurals" }
td { {tid!("message-selection-plurals", value: 1)} }
}
tr {
td { }
td { {tid!("message-selection-plurals", value: 2)} }
}
tr {
td { "Message selection: plurals (default: an 'empty' value must be provided...)" }
td { {tid!("message-selection-plurals", value: "")} }
}
tr {
td { "Message selection: plurals (default: ... otherwise an error is raised)" }
td { {tid!("message-selection-plurals")} }
}
tr {
td { "Message selection: numeric" }
td { {tid!("message-selection-numeric", value: 0.0)} }
}
tr {
td { }
td { {tid!("message-selection-numeric", value: 0.5)} }
}
tr {
td { }
td { {tid!("message-selection-numeric", value: 42.0)} }
}
tr {
td { "Message selection: numeric (default)" }
td { {tid!("message-selection-numeric", value: "")} }
}
tr {
td { "Message selection: number" }
td { {tid!("message-selection-number", pos: 1)} }
}
tr {
td { "" }
td { {tid!("message-selection-number", pos: 2)} }
}
tr {
td { "" }
td { {tid!("message-selection-number", pos: 3)} }
}
tr {
td { "" }
td { {tid!("message-selection-number", pos: 4)} }
}
tr {
td { "Variables in references (1)" }
td { {tid!("message-using-term-with-variable")} }
}
tr {
td { "Variables in references (2)" }
td { {tid!("message-using-term-with-variable-2-1")} }
}
tr {
td { }
td { {tid!("message-using-term-with-variable-2-2")} }
}
tr {
td { }
td { {tid!("message-using-term-with-variable-2-default")} }
}
tr {
td { }
td { {tid!("message-using-term-with-variable-2-not-provided")} }
}
tr {
td { "Literals: string" }
td { {tid!("string-literal")} }
}
tr {
td { }
td { {tid!("number-literal-1")} }
}
tr {
td { }
td { {tid!("number-literal-2")} }
}
tr {
td { }
td { {tid!("number-literal-3")} }
}
tr {
td { }
td { {tid!("inline-expression-placeable-1")} }
}
tr {
td { }
td { {tid!("inline-expression-placeable-2")} }
}
}
}
}
}
fn app() -> Element {
use_init_i18n(|| {
// Only one example in this path, which contains the complete Fluent grammar.
I18nConfig::new(langid!("en")).with_auto_locales(PathBuf::from("./examples/data/fluent/"))
});
rsx!(Body {})
}