Skip to content

Commit c9bb595

Browse files
committed
Update to new langid
1 parent e201e56 commit c9bb595

File tree

17 files changed

+62
-82
lines changed

17 files changed

+62
-82
lines changed

fluent-bundle/Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ keywords = ["localization", "l10n", "i18n", "intl", "internationalization"]
1818
categories = ["localization", "internationalization"]
1919

2020
[dependencies]
21-
fluent-locale = "^0.6.0"
22-
fluent-syntax = "^0.9"
23-
failure = "^0.1"
24-
failure_derive = "^0.1"
25-
intl_pluralrules = { git = "https://github.com/unclenachoduh/pluralrules", rev = "1c18edd5c5e1e380815f587bf57b3c81e394fee7" }
26-
rental = "^0.5.4"
27-
smallvec = "^0.6.10"
28-
unic-langid = "^0.3.0"
21+
fluent-locale = { path = "../../fluent-locale-rs" }
22+
fluent-syntax = "0.9"
23+
failure = "0.1"
24+
failure_derive = "0.1"
25+
intl_pluralrules = { git = "https://github.com/zbraniecki/pluralrules", branch = "master" }
26+
rental = "0.5.4"
27+
smallvec = "0.6.10"
28+
unic-langid = { git = "https://github.com/zbraniecki/unic-locale", branch = "master" }
2929

3030
[dev-dependencies]
31-
criterion = "^0.2"
32-
serde = { version = "^1.0", features = ["derive"] }
33-
serde_yaml = "^0.8"
34-
rand = "^0.7.0"
31+
criterion = "0.2"
32+
serde = { version = "1.0", features = ["derive"] }
33+
serde_yaml = "0.8"
34+
rand = "0.7.0"
3535

3636
[[bench]]
3737
name = "resolver"

fluent-bundle/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ Usage
2323

2424
```rust
2525
use fluent_bundle::{FluentBundle, FluentResource};
26-
use std::convert::TryFrom;
2726
use unic_langid::LanguageIdentifier;
2827

2928
fn main() {
3029
let ftl_string = "hello-world = Hello, world!".to_owned();
3130
let res = FluentResource::try_new(ftl_string)
3231
.expect("Could not parse an FTL string.");
3332

34-
let langid_en = LanguageIdentifier::try_from("en").expect("Parsing failed.");
33+
let langid_en = "en".parse().expect("Parsing failed.");
3534
let mut bundle = FluentBundle::new(&[langid_en]);
3635

3736
bundle.add_resource(&res)

fluent-bundle/examples/external_arguments.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
22
use std::collections::HashMap;
3-
use std::convert::TryFrom;
43
use unic_langid::LanguageIdentifier;
54

65
fn main() {
@@ -16,7 +15,7 @@ unread-emails =
1615
",
1716
);
1817
let res = FluentResource::try_new(ftl_string).expect("Could not parse an FTL string.");
19-
let langid_en = LanguageIdentifier::try_from("en").expect("Parsing failed.");
18+
let langid_en: LanguageIdentifier = "en".parse().expect("Parsing failed.");
2019
let mut bundle = FluentBundle::new(&[langid_en]);
2120
bundle
2221
.add_resource(res)

fluent-bundle/examples/functions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
2-
use std::convert::TryFrom;
32
use unic_langid::LanguageIdentifier;
43

54
fn main() {
@@ -12,7 +11,7 @@ fn main() {
1211
let res2 = FluentResource::try_new(ftl_string2).expect("Could not parse an FTL string.");
1312
let res3 = FluentResource::try_new(ftl_string3).expect("Could not parse an FTL string.");
1413

15-
let langid_en_us = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
14+
let langid_en_us: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
1615
let mut bundle = FluentBundle::new(&[langid_en_us]);
1716

1817
// Test for a simple function that returns a string

fluent-bundle/examples/simple-app.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
2121
use fluent_locale::{negotiate_languages, NegotiationStrategy};
2222
use std::collections::HashMap;
23-
use std::convert::TryFrom;
2423
use std::env;
2524
use std::fs;
2625
use std::fs::File;
@@ -57,7 +56,7 @@ fn get_available_locales() -> Result<Vec<LanguageIdentifier>, io::Error> {
5756
if path.is_dir() {
5857
if let Some(name) = path.file_name() {
5958
if let Some(name) = name.to_str() {
60-
let langid = LanguageIdentifier::try_from(name).expect("Parsing failed.");
59+
let langid: LanguageIdentifier = name.parse().expect("Parsing failed.");
6160
locales.push(langid);
6261
}
6362
}
@@ -78,12 +77,12 @@ fn main() {
7877
// list of requested locales.
7978
let requested = args.get(2).map_or(vec![], |arg| {
8079
arg.split(",")
81-
.map(|s| LanguageIdentifier::try_from(s).expect("Parsing locale failed."))
80+
.map(|s| -> LanguageIdentifier { s.parse().expect("Parsing locale failed.") })
8281
.collect()
8382
});
8483

8584
// 4. Negotiate it against the available ones
86-
let default_locale = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
85+
let default_locale: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
8786
let available = get_available_locales().expect("Retrieving available locales failed.");
8887
let resolved_locales = negotiate_languages(
8988
&requested,

fluent-bundle/src/bundle.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use std::borrow::Borrow;
88
use std::borrow::Cow;
99
use std::collections::hash_map::{Entry as HashEntry, HashMap};
10-
use std::convert::TryFrom;
1110
use std::default::Default;
1211

1312
use fluent_locale::{negotiate_languages, NegotiationStrategy};
@@ -36,14 +35,13 @@ pub struct Message<'m> {
3635
/// ```
3736
/// use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
3837
/// use std::collections::HashMap;
39-
/// use std::convert::TryFrom;
4038
/// use unic_langid::LanguageIdentifier;
4139
///
4240
/// let ftl_string = String::from("intro = Welcome, { $name }.");
4341
/// let resource = FluentResource::try_new(ftl_string)
4442
/// .expect("Could not parse an FTL string.");
4543
///
46-
/// let langid_en = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
44+
/// let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
4745
/// let mut bundle = FluentBundle::new(&[langid_en]);
4846
/// bundle.add_resource(&resource)
4947
/// .expect("Failed to add FTL resources to the bundle.");
@@ -109,10 +107,9 @@ impl<R> FluentBundle<R> {
109107
/// ```
110108
/// use fluent_bundle::FluentBundle;
111109
/// use fluent_bundle::FluentResource;
112-
/// use std::convert::TryFrom;
113110
/// use unic_langid::LanguageIdentifier;
114111
///
115-
/// let langid_en = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
112+
/// let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
116113
/// let mut bundle: FluentBundle<FluentResource> = FluentBundle::new(&[langid_en]);
117114
/// ```
118115
///
@@ -126,7 +123,7 @@ impl<R> FluentBundle<R> {
126123
.into_iter()
127124
.map(|s| s.clone().into())
128125
.collect::<Vec<_>>();
129-
let default_langid = LanguageIdentifier::try_from("en").expect("Parsing failed.");
126+
let default_langid = "en".parse().expect("Parsing failed.");
130127
let pr_locale = negotiate_languages(
131128
&locales,
132129
&IntlPluralRules::get_locales(PluralRuleType::CARDINAL),
@@ -161,7 +158,6 @@ impl<R> FluentBundle<R> {
161158
///
162159
/// ```
163160
/// use fluent_bundle::{FluentBundle, FluentResource};
164-
/// use std::convert::TryFrom;
165161
/// use unic_langid::LanguageIdentifier;
166162
///
167163
/// let ftl_string = String::from("
@@ -170,7 +166,7 @@ impl<R> FluentBundle<R> {
170166
/// ");
171167
/// let resource = FluentResource::try_new(ftl_string)
172168
/// .expect("Could not parse an FTL string.");
173-
/// let langid_en = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
169+
/// let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
174170
/// let mut bundle = FluentBundle::new(&[langid_en]);
175171
/// bundle.add_resource(resource)
176172
/// .expect("Failed to add FTL resources to the bundle.");
@@ -245,13 +241,12 @@ impl<R> FluentBundle<R> {
245241
///
246242
/// ```
247243
/// use fluent_bundle::{FluentBundle, FluentResource};
248-
/// use std::convert::TryFrom;
249244
/// use unic_langid::LanguageIdentifier;
250245
///
251246
/// let ftl_string = String::from("hello = Hi!");
252247
/// let resource = FluentResource::try_new(ftl_string)
253248
/// .expect("Failed to parse an FTL string.");
254-
/// let langid_en = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
249+
/// let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
255250
/// let mut bundle = FluentBundle::new(&[langid_en]);
256251
/// bundle.add_resource(&resource)
257252
/// .expect("Failed to add FTL resources to the bundle.");
@@ -313,13 +308,12 @@ impl<R> FluentBundle<R> {
313308
///
314309
/// ```
315310
/// use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
316-
/// use std::convert::TryFrom;
317311
/// use unic_langid::LanguageIdentifier;
318312
///
319313
/// let ftl_string = String::from("length = { STRLEN(\"12345\") }");
320314
/// let resource = FluentResource::try_new(ftl_string)
321315
/// .expect("Could not parse an FTL string.");
322-
/// let langid_en = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
316+
/// let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
323317
/// let mut bundle = FluentBundle::new(&[langid_en]);
324318
/// bundle.add_resource(&resource)
325319
/// .expect("Failed to add FTL resources to the bundle.");
@@ -359,8 +353,8 @@ impl<R> FluentBundle<R> {
359353

360354
impl<R> Default for FluentBundle<R> {
361355
fn default() -> Self {
362-
let pr_langid = LanguageIdentifier::try_from("en").expect("Parsing failed.");
363-
let langid = LanguageIdentifier::new();
356+
let pr_langid: LanguageIdentifier = "en".parse().expect("Parsing failed.");
357+
let langid = LanguageIdentifier::default();
364358

365359
let pr = IntlPluralRules::create(pr_langid, PluralRuleType::CARDINAL)
366360
.expect("Failed to initialize PluralRules.");

fluent-bundle/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! ```
1414
//! use fluent_bundle::{FluentBundle, FluentValue, FluentResource};
1515
//! use std::collections::HashMap;
16-
//! use std::convert::TryFrom;
1716
//! use unic_langid::LanguageIdentifier;
1817
//!
1918
//! let ftl_string = String::from("
@@ -23,7 +22,7 @@
2322
//! let res = FluentResource::try_new(ftl_string)
2423
//! .expect("Could not parse an FTL string.");
2524
//!
26-
//! let langid_en = LanguageIdentifier::try_from("en-US").expect("Parsing failed.");
25+
//! let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
2726
//! let mut bundle = FluentBundle::new(&[langid_en]);
2827
//!
2928
//! bundle

fluent-bundle/tests/resolver_fixtures.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod helpers;
22

33
use std::collections::HashMap;
4-
use std::convert::TryFrom;
54
use std::fs;
65
use std::iter;
76
use std::path::Path;
@@ -97,7 +96,7 @@ fn create_bundle(
9796
})
9897
.map(|locs| {
9998
locs.into_iter()
100-
.map(|s| LanguageIdentifier::try_from(s).expect("Parsing failed."))
99+
.map(|s| s.parse().expect("Parsing failed."))
101100
.collect()
102101
})
103102
.expect("Failed to calculate locales.");

fluent-bundle/tests/types_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use fluent_bundle::resolve::Scope;
22
use fluent_bundle::types::FluentValue;
33
use fluent_bundle::FluentBundle;
44
use fluent_bundle::FluentResource;
5-
use std::convert::TryFrom;
65
use unic_langid::LanguageIdentifier;
76

87
#[test]
@@ -15,7 +14,7 @@ fn fluent_value_number() {
1514
fn fluent_value_matches() {
1615
// We'll use `ars` locale since it happens to have all
1716
// plural rules categories.
18-
let langid_ars = LanguageIdentifier::try_from("ars").expect("Parsing failed.");
17+
let langid_ars: LanguageIdentifier = "ars".parse().expect("Parsing failed.");
1918
let bundle: FluentBundle<FluentResource> = FluentBundle::new(&[langid_ars]);
2019
let scope = Scope::new(&bundle, None);
2120

fluent-cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ keywords = ["localization", "l10n", "i18n", "intl", "internationalization"]
1818
categories = ["localization", "internationalization"]
1919

2020
[dependencies]
21-
annotate-snippets = {version = "^0.6", features = ["color"]}
22-
clap = "^2.32"
21+
annotate-snippets = {version = "0.6", features = ["color"]}
22+
clap = "2.33"
2323
fluent-syntax = { path = "../fluent-syntax" }

0 commit comments

Comments
 (0)