i18n: first steps

This commit is contained in:
Vincent Breitmoser 2019-08-27 23:56:19 +02:00
parent 6e0ab047ee
commit 77c90fc8fb
No known key found for this signature in database
GPG Key ID: 7BD18320DEADFA11
5 changed files with 71 additions and 1 deletions

View File

@ -10,5 +10,5 @@ build:binary:
- 'echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list.d/testing-nettle.list'
- 'echo "Package: *\nPin: release a=testing\nPin-Priority: 150" > /etc/apt/preferences.d/limit_testing'
- apt update -qy
- apt install -qy libclang-dev build-essential pkg-config clang nettle-dev/testing
- apt install -qy libclang-dev build-essential pkg-config clang nettle-dev/testing gettext
- RUST_BACKTRACE=full cargo test --all

55
Cargo.lock generated
View File

@ -191,6 +191,11 @@ name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.3.2"
@ -602,6 +607,33 @@ dependencies = [
"wasi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gettext"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gettext"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gettext-macros"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gettext 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"runtime-fmt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glob"
version = "0.2.11"
@ -623,6 +655,8 @@ version = "0.1.0"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gettext 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gettext-macros 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hagrid-database 0.1.0",
"handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -636,6 +670,7 @@ dependencies = [
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_contrib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_i18n 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_prometheus 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sequoia-openpgp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1726,6 +1761,15 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rocket_i18n"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gettext 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rocket_prometheus"
version = "0.2.0"
@ -1735,6 +1779,11 @@ dependencies = [
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "runtime-fmt"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rust-argon2"
version = "0.5.1"
@ -2379,6 +2428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum buffered-reader 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "237cf351e1e6666907f4e2b59ee4a00083280445a0c6eb2261640615a3a33317"
"checksum bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708"
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
"checksum byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96c8b41881888cc08af32d47ac4edd52bc7fa27fef774be47a92443756451304"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
"checksum cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff"
@ -2428,6 +2478,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "fc344b02d3868feb131e8b5fe2b9b0a1cc42942679af493061fc13b853243872"
"checksum gettext 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4378b8e09fd51cfdb0d48f40929a5c358efeeb62feb458c7d6eab979fae231f4"
"checksum gettext 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ebb594e753d5997e4be036e5a8cf048ab9414352870fb45c779557bbc9ba971"
"checksum gettext-macros 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fbf88e9e6bba5ff64428ee2a32ea9872d94d4c87c42fb3f219bf87f63e4b9d51"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
"checksum groupable 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32619942b8be646939eaf3db0602b39f5229b74575b67efc897811ded1db4e57"
@ -2542,7 +2595,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rocket_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "79aa1366f9b2eccddc05971e17c5de7bb75a5431eb12c2b5c66545fd348647f4"
"checksum rocket_contrib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e0fa5c1392135adc0f96a02ba150ac4c765e27c58dbfd32aa40678e948f6e56f"
"checksum rocket_http 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1391457ee4e80b40d4b57fa5765c0f2836b20d73bcbee4e3f35d93cf3b80817"
"checksum rocket_i18n 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf9f4c872b824ac0506557be9c66e0315d66d0e378d2ae02ee2e7b0fed2a338"
"checksum rocket_prometheus 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8648f031a8cafb1c8dce50899d2080f475fa58e6643bccd92cf87d0e9993df37"
"checksum runtime-fmt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "196062ca926ca862be9116dee45a5c0b2fce301f6f91baa46c364efd4d0b9349"
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"

View File

@ -35,6 +35,9 @@ base64 = "0.10"
uuid = "0.7"
rocket_prometheus = "0.2"
lazy_static = "1.3.0"
rocket_i18n = "0.4"
gettext-macros = "0.5.1"
gettext = "0.3.0"
[dependencies.lettre]
version = "0.9"

View File

@ -27,6 +27,10 @@ extern crate rocket_prometheus;
extern crate tempfile;
extern crate uuid;
extern crate gettext;
extern crate gettext_macros;
extern crate rocket_i18n;
#[cfg(test)]
extern crate regex;
@ -51,6 +55,7 @@ fn main() {
cause = c;
}
eprintln!();
::std::process::exit(2);
}
}

View File

@ -11,6 +11,8 @@ use rocket::response::status::Custom;
use rocket_prometheus::PrometheusMetrics;
use gettext_macros::{compile_i18n, include_i18n, init_i18n};
use serde::Serialize;
use handlebars::Handlebars;
@ -335,6 +337,8 @@ pub fn serve() -> Result<()> {
Err(rocket_factory(rocket::ignite())?.launch().into())
}
init_i18n!("hagrid", en, de);
fn rocket_factory(mut rocket: rocket::Rocket) -> Result<rocket::Rocket> {
let routes = routes![
// infra
@ -398,6 +402,7 @@ fn rocket_factory(mut rocket: rocket::Rocket) -> Result<rocket::Rocket> {
rocket = rocket
.attach(Template::fairing())
.attach(maintenance_mode)
.manage(include_i18n!())
.manage(hagrid_state)
.manage(stateless_token_service)
.manage(stateful_token_service)
@ -415,6 +420,8 @@ fn rocket_factory(mut rocket: rocket::Rocket) -> Result<rocket::Rocket> {
Ok(rocket)
}
compile_i18n!();
fn configure_prometheus(config: &Config) -> Option<PrometheusMetrics> {
if !config.get_bool("enable_prometheus").unwrap_or(false) {
return None;