Switch to flake

This commit is contained in:
Savanni D'Gerinel 2022-04-20 09:12:34 -04:00
parent cb917e9a73
commit c91d105d01
7 changed files with 187 additions and 164 deletions

View File

@ -1 +1 @@
use_nix
use flake

2
fluent-ergonomics/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
.direnv

View File

@ -2,35 +2,30 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "fluent"
version = "0.11.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ebe7532e1e5146a909de9e019e31835a84b5dee3eeb234561e525844f3cf3bf"
checksum = "bc4d7142005e2066e4844caf9f271b93fc79836ee96ec85057b8c109687e629a"
dependencies = [
"fluent-bundle",
"unic-langid",
"unic-langid 0.9.0",
]
[[package]]
name = "fluent-bundle"
version = "0.11.0"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27ade33328521266c81cc0924523988f43ccd7359f64689a1b6e818afca3a646"
checksum = "e242c601dec9711505f6d5bbff5bedd4b61b2469f2e8bb8e57ee7c9747a87ffd"
dependencies = [
"fluent-langneg",
"fluent-syntax",
"intl-memoizer",
"intl_pluralrules",
"rental",
"rustc-hash",
"self_cell",
"smallvec",
"unic-langid",
"unic-langid 0.9.0",
]
[[package]]
@ -39,51 +34,45 @@ version = "0.2.0"
dependencies = [
"fluent",
"fluent-syntax",
"unic-langid",
"unic-langid 0.8.0",
]
[[package]]
name = "fluent-langneg"
version = "0.12.1"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe5815efd5542e40841cd34ef9003822352b04c67a70c595c6758597c72e1f56"
checksum = "2c4ad0989667548f06ccd0e306ed56b61bd4d35458d54df5ec7587c0e8ed5e94"
dependencies = [
"unic-langid",
"unic-langid 0.9.0",
]
[[package]]
name = "fluent-syntax"
version = "0.9.3"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac0f7e83d14cccbf26e165d8881dcac5891af0d85a88543c09dd72ebd31d91ba"
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
checksum = "c0abed97648395c902868fee9026de96483933faa54ea3b40d652f7dfe61ca78"
dependencies = [
"byteorder",
"thiserror",
]
[[package]]
name = "intl-memoizer"
version = "0.4.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9867e2d65d82936ef34217ed0f87b639a94384e93a0676158142c861c705391f"
checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f"
dependencies = [
"type-map",
"unic-langid",
"unic-langid 0.9.0",
]
[[package]]
name = "intl_pluralrules"
version = "6.0.0"
version = "7.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82c14d8eece42c03353e0ce86a4d3f97b1f1cef401e4d962dca6c6214a85002"
checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf"
dependencies = [
"tinystr",
"unic-langid",
"unic-langid 0.9.0",
]
[[package]]
@ -105,25 +94,16 @@ dependencies = [
]
[[package]]
name = "rental"
version = "0.5.6"
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc89fe2acac36d212474d138aaf939c04a82df5b61d07011571ebce5aef81f2e"
dependencies = [
"rental-impl",
"stable_deref_trait",
]
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rental-impl"
version = "0.5.5"
name = "self_cell"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
[[package]]
name = "smallvec"
@ -131,12 +111,6 @@ version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "syn"
version = "1.0.82"
@ -148,6 +122,26 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tinystr"
version = "0.3.4"
@ -156,11 +150,11 @@ checksum = "29738eedb4388d9ea620eeab9384884fc3f06f586a2eddb56bedc5885126c7c1"
[[package]]
name = "type-map"
version = "0.3.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d2741b1474c327d95c1f1e3b0a2c3977c8e128409c572a33af2914e7d636717"
checksum = "b6d3364c5e96cb2ad1603037ab253ddd34d7fb72a58bdddf4b7350760fc69a46"
dependencies = [
"fxhash",
"rustc-hash",
]
[[package]]
@ -169,7 +163,16 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d81136159f779c35b10655f45210c71cd5ca5a45aadfe9840a61c7071735ed"
dependencies = [
"unic-langid-impl",
"unic-langid-impl 0.8.0",
]
[[package]]
name = "unic-langid"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73328fcd730a030bdb19ddf23e192187a6b01cd98be6d3140622a89129459ce5"
dependencies = [
"unic-langid-impl 0.9.0",
]
[[package]]
@ -181,6 +184,15 @@ dependencies = [
"tinystr",
]
[[package]]
name = "unic-langid-impl"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a4a8eeaf0494862c1404c95ec2f4c33a2acff5076f64314b465e3ddae1b934d"
dependencies = [
"tinystr",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"

View File

@ -18,6 +18,6 @@ include = [
]
[dependencies]
fluent = "0.11"
fluent = "0.15"
unic-langid = "0.8"
fluent-syntax = "^0.9"
fluent-syntax = "0.11"

View File

@ -0,0 +1,30 @@
{
description = "fluent-ergonomics";
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.11";
oxalica.url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
};
outputs = { self, nixpkgs, oxalica }:
let
version = builtins.string 0 8 self.lastModifiedDate;
supportedSystems = [ "x86_64-linux" ];
in
{
devShell."x86_64-linux" =
let
rust_overlay = import oxalica;
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ rust_overlay ]; };
rust = pkgs.rust-bin.stable."1.59.0".default.override {
extensions = [ "rust-src" ];
};
in
pkgs.mkShell {
name = "fluent-ergonomics";
buildInputs = [
rust
];
};
};
}

View File

@ -1,21 +0,0 @@
let
rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
pkgs = import <pkgs-21.05> { overlays = [ rust_overlay ]; };
unstable = import <unstable> {};
rust = pkgs.rust-bin.stable."1.55.0".default.override {
extensions = [ "rust-src" ];
};
in pkgs.mkShell {
name = "luminescent-dreams-core";
buildInputs = [
pkgs.openssl
rust
unstable.rust-analyzer
];
shellHook = ''
if [ -e ~/.nixpkgs/shellhook.sh ]; then . ~/.nixpkgs/shellhook.sh; fi
'';
}

View File

@ -3,7 +3,7 @@
//! The Fluent class makes it easier to load translation bundles with language fallbacks and to go
//! through the most common steps of translating a message.
//!
use fluent::concurrent::FluentBundle;
use fluent::FluentBundle;
use fluent::{FluentArgs, FluentError, FluentResource};
use fluent_syntax::parser::ParserError;
use std::collections::hash_map::Entry;
@ -98,11 +98,11 @@ pub struct FluentErgo {
impl fmt::Debug for FluentErgo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "FluentErgo")
//write!(
//f,
//"FluentErgo {{ language: {:?}, units: {} }}",
//self.language, "whatever, for the moment"
//)
//write!(
//f,
//"FluentErgo {{ language: {:?}, units: {} }}",
//self.language, "whatever, for the moment"
//)
}
}
@ -234,7 +234,7 @@ impl FluentErgo {
let bundle = bundles.get(lang)?;
self.tr_(bundle, msgid, args)
})
.filter(|v| v.is_some())
.filter(|v| v.is_some())
.map(|v| v.unwrap())
.next();
@ -249,7 +249,7 @@ impl FluentErgo {
bundle: &FluentBundle<FluentResource>,
msgid: &str,
args: Option<&FluentArgs>,
) -> Option<String> {
) -> Option<String> {
let mut errors = vec![];
let pattern = bundle.get_message(msgid).and_then(|msg| msg.value);
let res = match pattern {
@ -286,83 +286,83 @@ time_display = {$time} during the day
nested_display = nesting a time display: {time_display}
";
const EO_TRANSLATIONS: &'static str = "
const EO_TRANSLATIONS: &'static str = "
history = Historio
";
#[test]
fn translations() {
let en_id = "en-US".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
assert_eq!(
fluent.tr("preferences", None).unwrap(),
String::from("Preferences")
#[test]
fn translations() {
let en_id = "en-US".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
assert_eq!(
fluent.tr("preferences", None).unwrap(),
String::from("Preferences")
);
}
#[test]
fn translation_fallback() {
let eo_id = "eo".parse::<LanguageIdentifier>().unwrap();
let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![eo_id.clone(), en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
fluent
.add_from_text(eo_id, String::from(EO_TRANSLATIONS))
.expect("text should load");
assert_eq!(
fluent.tr("preferences", None).unwrap(),
String::from("Preferences")
);
assert_eq!(
fluent.tr("history", None).unwrap(),
String::from("Historio")
);
}
#[test]
fn placeholder_insertion_should_strip_placeholder_markers() {
let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
let mut args = FluentArgs::new();
args.insert("time", FluentValue::from(String::from("13:00")));
assert_eq!(
fluent.tr("time_display", Some(&args)).unwrap(),
String::from("13:00 during the day")
);
}
#[test]
fn placeholder_insertion_should_strip_nested_placeholder_markers() {
let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
let mut args = FluentArgs::new();
args.insert("time", FluentValue::from(String::from("13:00")));
assert_eq!(
fluent.tr("nested_display", Some(&args)).unwrap(),
String::from("nesting a time display: 13:00 during the day")
);
}
#[test]
fn test_send() {
fn assert_send<T: Send>() {}
assert_send::<FluentErgo>();
}
#[test]
fn test_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<FluentErgo>();
}
}
#[test]
fn translation_fallback() {
let eo_id = "eo".parse::<LanguageIdentifier>().unwrap();
let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![eo_id.clone(), en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
fluent
.add_from_text(eo_id, String::from(EO_TRANSLATIONS))
.expect("text should load");
assert_eq!(
fluent.tr("preferences", None).unwrap(),
String::from("Preferences")
);
assert_eq!(
fluent.tr("history", None).unwrap(),
String::from("Historio")
);
}
#[test]
fn placeholder_insertion_should_strip_placeholder_markers() {
let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
let mut args = FluentArgs::new();
args.insert("time", FluentValue::from(String::from("13:00")));
assert_eq!(
fluent.tr("time_display", Some(&args)).unwrap(),
String::from("13:00 during the day")
);
}
#[test]
fn placeholder_insertion_should_strip_nested_placeholder_markers() {
let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load");
let mut args = FluentArgs::new();
args.insert("time", FluentValue::from(String::from("13:00")));
assert_eq!(
fluent.tr("nested_display", Some(&args)).unwrap(),
String::from("nesting a time display: 13:00 during the day")
);
}
#[test]
fn test_send() {
fn assert_send<T: Send>() {}
assert_send::<FluentErgo>();
}
#[test]
fn test_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<FluentErgo>();
}
}