Add I18n.lang #16
3 changed files with 9 additions and 5 deletions
|
@ -92,6 +92,8 @@ const ACCEPT_LANG: &'static str = "Accept-Language";
|
|||
pub struct I18n {
|
||||
/// The catalog containing the translated messages, in the correct locale for this request.
|
||||
pub catalog: Catalog,
|
||||
/// The language of the current request.
|
||||
pub lang: &'static str,
|
||||
}
|
||||
|
||||
pub type Translations = Vec<(&'static str, Catalog)>;
|
||||
|
|
|
@ -55,8 +55,9 @@ where
|
|||
.unwrap_or("en");
|
||||
|
||||
match langs.iter().find(|l| l.0 == lang) {
|
||||
Some(catalog) => Ok(I18n {
|
||||
catalog: catalog.1.clone(),
|
||||
Some(translation) => Ok(I18n {
|
||||
catalog: translation.1.clone(),
|
||||
lang: translation.0,
|
||||
}),
|
||||
None => Err(MissingTranslationsError(lang.to_owned()).into()),
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@ impl<'a, 'r> FromRequest<'a, 'r> for I18n {
|
|||
.unwrap_or("en");
|
||||
|
||||
match langs.iter().find(|l| l.0 == lang) {
|
||||
Some(catalog) => Outcome::Success(I18n {
|
||||
catalog: catalog.1.clone(),
|
||||
Some(translation) => Outcome::Success(I18n {
|
||||
catalog: translation.1.clone(),
|
||||
lang: translation.0,
|
||||
}),
|
||||
None => Outcome::Failure((Status::InternalServerError, ())),
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue