-
-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Askama base crate i18n support #845
base: main
Are you sure you want to change the base?
Conversation
…ama into askama_base_crate_i18n_support
@@ -33,6 +33,7 @@ with-mendes = ["askama_derive/with-mendes"] | |||
with-rocket = ["askama_derive/with-rocket"] | |||
with-tide = ["askama_derive/with-tide"] | |||
with-warp = ["askama_derive/with-warp"] | |||
i18n = ["askama_derive/i18n", "fluent-templates"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this is a fluid
backed i18n, would it be appropriate to self-document that in the feature name? e.g. i18n_fluent
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm by no means a heavy-hitter. I'm just passing through in my search of "the good way" to add i18n to my askama project, and thought I'd try to do my little part.
nothing in this review should be considered blocking. I didn't see any issues, but that by no means implies I didn't miss any. I hope this helps. I really look forward to askama + fluent being able to Just Work^tm
for (k, v) in args { | ||
buf.write(&format!("({:?}, ::askama::i18n::FluentValue::from(", k)); | ||
self.visit_expr(buf, v)?; | ||
buf.writeln(")),")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personal preference for key
and val
#[cfg(feature = "i18n")] | ||
match i18n::load(_input) { | ||
Ok(ts) => ts, | ||
Err(err) => err.into_compile_error(), | ||
} | ||
|
||
#[cfg(not(feature = "i18n"))] | ||
CompileError::from(r#"Activate the "i18n" feature to use i18n_load!()."#).into_compile_error() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using cfg-if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean the crate, I'd prefer not to add more dependencies unless we really need them.
@@ -33,6 +33,8 @@ pub(crate) enum Expr<'a> { | |||
Call(Box<Expr<'a>>, Vec<Expr<'a>>), | |||
RustMacro(Vec<&'a str>, &'a str), | |||
Try(Box<Expr<'a>>), | |||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it feasible to feature gate this instead?
#[cfg(not(feature = "i18n"))] | ||
fn expr_localize(i: &str) -> IResult<&str, Expr<'_>> { | ||
let (i, _) = pair(tag("localize"), ws(tag("(")))(i)?; | ||
eprintln!(r#"Activate the "i18n" feature to use {{ localize() }}."#); | ||
Err(nom::Err::Failure(error_position!(i, ErrorKind::Tag))) | ||
} | ||
|
||
#[cfg(feature = "i18n")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using cfg-if crate
pub fn new(language: LanguageIdentifier, loader: &'static StaticLoader) -> Self { | ||
Self { loader, language } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc-comment here would be handy.
Depends on #844 :
Locale
struct behind feature flag,parking_lot
, since it was used as part of the unsafe code