Skip to content

Commit 9d66bfa

Browse files
author
Zibi Braniecki
committed
Migrate resolver to use copy-free parser
This is a massive rewrite of the whole crate. It separates out three crates: fluent-syntax becomes a zero-copy AST+parser(+serialized in the future) compabile with Fluent 0.8 fluent-bundle becomes aligned with fluent-bundle in JS fluent becomes a top-level crate with added simple ResourceManager. All of the code is compatible with current stable Rust 2018.
1 parent 60b7f9a commit 9d66bfa

File tree

104 files changed

+3860
-1384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+3860
-1384
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target/
2+
*/target/
23
**/*.rs.bk
34
Cargo.lock

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[workspace]
22
members = [
3+
"fluent-syntax",
4+
"fluent-bundle",
5+
"fluent-cli",
36
"fluent",
4-
"fluent-syntax"
57
]
File renamed without changes.

fluent-bundle/Cargo.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "fluent-bundle"
3+
description = """
4+
A localization system designed to unleash the entire expressive power of
5+
natural language translations.
6+
"""
7+
version = "0.4.3"
8+
edition = "2018"
9+
authors = [
10+
"Zibi Braniecki <[email protected]>",
11+
"Staś Małolepszy <[email protected]>"
12+
]
13+
homepage = "http://www.projectfluent.org"
14+
license = "Apache-2.0/MIT"
15+
repository = "https://github.com/projectfluent/fluent-rs"
16+
readme = "README.md"
17+
keywords = ["localization", "l10n", "i18n", "intl", "internationalization"]
18+
categories = ["localization", "internationalization"]
19+
20+
[dependencies]
21+
fluent-locale = "^0.4.1"
22+
fluent-syntax = { path = "../fluent-syntax" }
23+
failure = "0.1"
24+
failure_derive = "0.1"
25+
intl_pluralrules = "1.0"

fluent/README.md renamed to fluent-bundle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Usage
2424
```rust
2525
extern crate fluent;
2626

27-
use fluent::FluentBundle;
27+
use fluent_bundle::FluentBundle;
2828

2929
fn main() {
3030
let mut bundle = FluentBundle::new(&["en-US"]);

fluent/benches/lib.rs renamed to fluent-bundle/benches/lib.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
#![feature(test)]
22

3-
extern crate fluent;
4-
extern crate fluent_syntax;
53
extern crate test;
64

7-
use fluent::bundle::FluentBundle;
5+
use fluent_bundle::bundle::FluentBundle;
86
use fluent_syntax::{ast, parser::parse};
97
use std::fs::File;
108
use std::io;
119
use std::io::Read;
1210
use test::Bencher;
1311

1412
fn read_file(path: &str) -> Result<String, io::Error> {
15-
let mut f = try!(File::open(path));
13+
let mut f = File::open(path)?;
1614
let mut s = String::new();
17-
try!(f.read_to_string(&mut s));
15+
f.read_to_string(&mut s)?;
1816
Ok(s)
1917
}
2018

@@ -27,7 +25,9 @@ fn bench_simple_format(b: &mut Bencher) {
2725

2826
for entry in resource.body {
2927
match entry {
30-
ast::Entry::Message(ast::Message { id, .. }) => ids.push(id.name),
28+
ast::ResourceEntry::Entry(ast::Entry::Message(ast::Message { id, .. })) => {
29+
ids.push(id.name)
30+
}
3131
_ => continue,
3232
};
3333
}
@@ -37,7 +37,7 @@ fn bench_simple_format(b: &mut Bencher) {
3737

3838
b.iter(|| {
3939
for id in &ids {
40-
bundle.format(id.as_str(), None);
40+
bundle.format(id, None);
4141
}
4242
});
4343
}
@@ -51,7 +51,9 @@ fn bench_menubar_format(b: &mut Bencher) {
5151

5252
for entry in resource.body {
5353
match entry {
54-
ast::Entry::Message(ast::Message { id, .. }) => ids.push(id.name),
54+
ast::ResourceEntry::Entry(ast::Entry::Message(ast::Message { id, .. })) => {
55+
ids.push(id.name)
56+
}
5557
_ => continue,
5658
};
5759
}
@@ -66,7 +68,7 @@ fn bench_menubar_format(b: &mut Bencher) {
6668
// widgets may only expect attributes and they shouldn't be forced to display a value.
6769
// Here however it doesn't matter because we know for certain that the message for `id`
6870
// exists.
69-
bundle.format_message(id.as_str(), None);
71+
bundle.format_message(id, None);
7072
}
7173
});
7274
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

fluent/examples/external_arguments.rs renamed to fluent-bundle/examples/external_arguments.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
extern crate fluent;
2-
3-
use fluent::bundle::FluentBundle;
4-
use fluent::types::FluentValue;
1+
use fluent_bundle::bundle::FluentBundle;
2+
use fluent_bundle::types::FluentValue;
53
use std::collections::HashMap;
64

75
fn main() {
@@ -17,7 +15,8 @@ unread-emails =
1715
*[other] You have { $emailCount } unread emails
1816
}
1917
",
20-
).unwrap();
18+
)
19+
.unwrap();
2120

2221
let mut args = HashMap::new();
2322
args.insert("name", FluentValue::from("John"));

fluent/examples/functions.rs renamed to fluent-bundle/examples/functions.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
extern crate fluent;
2-
3-
use fluent::bundle::FluentBundle;
4-
use fluent::types::FluentValue;
1+
use fluent_bundle::bundle::FluentBundle;
2+
use fluent_bundle::types::FluentValue;
53

64
fn main() {
75
let mut bundle = FluentBundle::new(&["en-US"]);
@@ -10,7 +8,8 @@ fn main() {
108
bundle
119
.add_function("HELLO", |_args, _named_args| {
1210
return Some("I'm a function!".into());
13-
}).unwrap();
11+
})
12+
.unwrap();
1413

1514
// Test for a function that accepts unnamed positional arguments
1615
bundle
@@ -22,7 +21,8 @@ fn main() {
2221
}
2322

2423
None
25-
}).unwrap();
24+
})
25+
.unwrap();
2626

2727
// Test for a function that accepts named arguments
2828
bundle
@@ -35,7 +35,8 @@ fn main() {
3535
}
3636
_ => None,
3737
};
38-
}).unwrap();
38+
})
39+
.unwrap();
3940

4041
bundle
4142
.add_messages("hello-world = Hey there! { HELLO() }")

fluent/examples/hello.rs renamed to fluent-bundle/examples/hello.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
extern crate fluent;
2-
3-
use fluent::bundle::FluentBundle;
1+
use fluent_bundle::bundle::FluentBundle;
42

53
fn main() {
64
let mut bundle = FluentBundle::new(&["en-US"]);

fluent/examples/message_reference.rs renamed to fluent-bundle/examples/message_reference.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
extern crate fluent;
2-
3-
use fluent::bundle::FluentBundle;
1+
use fluent_bundle::bundle::FluentBundle;
42

53
fn main() {
64
let mut bundle = FluentBundle::new(&["x-testing"]);
@@ -11,7 +9,8 @@ foo = Foo
119
foobar = { foo } Bar
1210
bazbar = { baz } Bar
1311
",
14-
).unwrap();
12+
)
13+
.unwrap();
1514

1615
match bundle.format("foobar", None) {
1716
Some((value, _)) => println!("{}", value),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
missing-arg-error = Error: Please provide a number as argument.
2+
input-parse-error = Error: Could not parse input `{ $input }`. Reason: { $reason }
3+
response-msg =
4+
{ $value ->
5+
[one] "{ $input }" has one Collatz step.
6+
*[other] "{ $input }" has { $value } Collatz steps.
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
missing-arg-error = Błąd: Proszę wprowadzić liczbę jako argument.
2+
input-parse-error = Błąd: Nie udało się sparsować `{ $input }`. Powód: { $reason }
3+
response-msg =
4+
{ $value ->
5+
[one] "{ $input }" ma jeden krok Collatza.
6+
[few] "{ $input }" ma { $value } kroki Collatza.
7+
*[many] "{ $input }" ma { $value } kroków Collatza.
8+
}

fluent/examples/selector.rs renamed to fluent-bundle/examples/selector.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
extern crate fluent;
2-
3-
use fluent::bundle::FluentBundle;
4-
use fluent::types::FluentValue;
1+
use fluent_bundle::bundle::FluentBundle;
2+
use fluent_bundle::types::FluentValue;
53
use std::collections::HashMap;
64

75
fn main() {
@@ -19,7 +17,8 @@ hello-world2 = Hello { $name ->
1917
[moon] Moon
2018
}
2119
",
22-
).unwrap();
20+
)
21+
.unwrap();
2322

2423
match bundle.format("hello-world", None) {
2524
Some((value, _)) => println!("{}", value),

0 commit comments

Comments
 (0)