Skip to content

Commit 12cc561

Browse files
authored
Refactor of the code, 0.8 compatibility, zero-copy AST/parsing, Rust 2018 goodies (#76)
1 parent efc8813 commit 12cc561

File tree

154 files changed

+10041
-3322
lines changed

Some content is hidden

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

154 files changed

+10041
-3322
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target/
2+
*/target/
23
**/*.rs.bk
34
Cargo.lock

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
3-
"fluent",
4-
"fluent-syntax"
3+
"fluent-syntax",
4+
"fluent-bundle",
5+
"fluent-cli"
56
]
File renamed without changes.
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[package]
2-
name = "fluent"
2+
name = "fluent-bundle"
33
description = """
4-
A localization library designed to unleash the entire expressive power of
4+
A localization system designed to unleash the entire expressive power of
55
natural language translations.
66
"""
77
version = "0.4.3"
8+
edition = "2018"
89
authors = [
910
"Zibi Braniecki <[email protected]>",
1011
"Staś Małolepszy <[email protected]>"
@@ -17,9 +18,9 @@ keywords = ["localization", "l10n", "i18n", "intl", "internationalization"]
1718
categories = ["localization", "internationalization"]
1819

1920
[dependencies]
20-
clap = "2.32"
2121
fluent-locale = "^0.4.1"
22-
fluent-syntax = "0.1.1"
23-
failure = "0.1"
24-
failure_derive = "0.1"
25-
intl_pluralrules = "1.0"
22+
fluent-syntax = { path = "../fluent-syntax" }
23+
failure = "^0.1"
24+
failure_derive = "^0.1"
25+
intl_pluralrules = "^1.0"
26+
rental = "^0.5.2"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Usage
2222
-----
2323

2424
```rust
25-
use fluent::bundle::FluentBundle;
25+
use fluent_bundle::FluentBundle;
2626

2727
fn main() {
2828
let mut bundle = FluentBundle::new(&["en-US"]);
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,70 @@
11
#![feature(test)]
22

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

7-
use fluent::bundle::FluentBundle;
8-
use fluent_syntax::{ast, parser::parse};
5+
use fluent_bundle::bundle::FluentBundle;
6+
use fluent_bundle::resource::FluentResource;
7+
use fluent_syntax::ast;
98
use std::fs::File;
109
use std::io;
1110
use std::io::Read;
1211
use test::Bencher;
1312

1413
fn read_file(path: &str) -> Result<String, io::Error> {
15-
let mut f = try!(File::open(path));
14+
let mut f = File::open(path)?;
1615
let mut s = String::new();
17-
try!(f.read_to_string(&mut s));
16+
f.read_to_string(&mut s)?;
1817
Ok(s)
1918
}
2019

2120
#[bench]
2221
fn bench_simple_format(b: &mut Bencher) {
2322
let source = read_file("./benches/simple.ftl").expect("Couldn't load file");
24-
let resource = parse(&source).unwrap();
23+
let res = FluentResource::try_new(source).expect("Couldn't parse an FTL source");
2524

2625
let mut ids = Vec::new();
2726

28-
for entry in resource.body {
27+
for entry in &res.ast().body {
2928
match entry {
30-
ast::Entry::Message(ast::Message { id, .. }) => ids.push(id.name),
29+
ast::ResourceEntry::Entry(ast::Entry::Message(ast::Message { id, .. })) => {
30+
ids.push(id.name)
31+
}
3132
_ => continue,
3233
};
3334
}
3435

3536
let mut bundle = FluentBundle::new(&["x-testing"]);
36-
bundle.add_messages(&source).unwrap();
37+
bundle
38+
.add_resource(&res)
39+
.expect("Couldn't add FluentResource to the FluentBundle");
3740

3841
b.iter(|| {
3942
for id in &ids {
40-
bundle.format(id.as_str(), None);
43+
bundle.format(id, None);
4144
}
4245
});
4346
}
4447

4548
#[bench]
4649
fn bench_menubar_format(b: &mut Bencher) {
4750
let source = read_file("./benches/menubar.ftl").expect("Couldn't load file");
48-
let resource = parse(&source).unwrap();
51+
let res = FluentResource::try_new(source).expect("Couldn't parse an FTL source");
4952

5053
let mut ids = Vec::new();
5154

52-
for entry in resource.body {
55+
for entry in &res.ast().body {
5356
match entry {
54-
ast::Entry::Message(ast::Message { id, .. }) => ids.push(id.name),
57+
ast::ResourceEntry::Entry(ast::Entry::Message(ast::Message { id, .. })) => {
58+
ids.push(id.name)
59+
}
5560
_ => continue,
5661
};
5762
}
5863

5964
let mut bundle = FluentBundle::new(&["x-testing"]);
60-
bundle.add_messages(&source).unwrap();
65+
bundle
66+
.add_resource(&res)
67+
.expect("Couldn't add FluentResource to the FluentBundle");
6168

6269
b.iter(|| {
6370
for id in &ids {
@@ -66,7 +73,7 @@ fn bench_menubar_format(b: &mut Bencher) {
6673
// widgets may only expect attributes and they shouldn't be forced to display a value.
6774
// Here however it doesn't matter because we know for certain that the message for `id`
6875
// exists.
69-
bundle.format_message(id.as_str(), None);
76+
bundle.compound(id, None);
7077
}
7178
});
7279
}
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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
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::resource::FluentResource;
3+
use fluent_bundle::types::FluentValue;
54
use std::collections::HashMap;
65

76
fn main() {
8-
let mut bundle = FluentBundle::new(&["en"]);
9-
bundle
10-
.add_messages(
11-
"
7+
let res = FluentResource::try_new(
8+
"
129
hello-world = Hello { $name }
1310
ref = The previous message says { hello-world }
1411
unread-emails =
1512
{ $emailCount ->
1613
[one] You have { $emailCount } unread email
1714
*[other] You have { $emailCount } unread emails
1815
}
19-
",
20-
)
21-
.unwrap();
16+
"
17+
.to_owned(),
18+
)
19+
.unwrap();
20+
let mut bundle = FluentBundle::new(&["en"]);
21+
bundle.add_resource(&res).unwrap();
2222

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

0 commit comments

Comments
 (0)