Use i18n
This commit is contained in:
parent
e8593b5f5a
commit
076cc98098
6 changed files with 18 additions and 8 deletions
|
@ -1 +1 @@
|
|||
hello-world = Hello, World!
|
||||
fedihub = FediHub
|
||||
|
|
|
@ -1 +1 @@
|
|||
hello-world = Привет, Мир!
|
||||
fedihub = FediHub
|
||||
|
|
|
@ -50,4 +50,12 @@ impl I18n {
|
|||
|
||||
Ok(Self(hash_map))
|
||||
}
|
||||
|
||||
pub fn dummy_translate(&self, locale: &str, key: &str) -> String {
|
||||
let bundle = self.0.get(locale).unwrap();
|
||||
let msg = bundle.get_message(key).unwrap();
|
||||
let val = msg.value.unwrap();
|
||||
let mut errors = vec![];
|
||||
bundle.format_pattern(val, None, &mut errors).to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,17 @@ use rocket_csrf::CsrfToken;
|
|||
|
||||
#[get("/")]
|
||||
pub fn index(
|
||||
_i18n: State<I18n>,
|
||||
i18n: State<I18n>,
|
||||
csrf_token: CsrfToken,
|
||||
current_user: states::MaybeCurrentUser,
|
||||
) -> Result<Template, CommonResponse> {
|
||||
let page_context = views::home::Index {
|
||||
i18n_fedihub: i18n.dummy_translate("en", "fedihub"),
|
||||
};
|
||||
|
||||
let context = views::Site {
|
||||
page: "home/index".to_string(),
|
||||
page_context: (),
|
||||
page_context,
|
||||
authenticity_token: csrf_token.authenticity_token().to_string(),
|
||||
current_user: current_user.0,
|
||||
};
|
||||
|
|
|
@ -16,11 +16,9 @@ pub struct Error {
|
|||
}
|
||||
|
||||
pub mod home {
|
||||
use crate::models;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Index {
|
||||
pub users: Vec<models::User>,
|
||||
pub i18n_fedihub: String,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="jumbotron jumbotron-fluid text-center">
|
||||
<div class="container">
|
||||
<h1>FediHub</h1>
|
||||
<h1>{{ i18n_fedihub }}</h1>
|
||||
<p class="lead">Federated services without censorship.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Reference in a new issue