I18n#434
Conversation
|
Looks like a good start! I wonder if we can simplify a bit, though. Can we make a template more like this? #[derive(Template)]
#[template(path = "i18n.html")]
struct UsesI18n<'a> {
#[locale]
loc: unic_langid::LanguageIdentifier,
name: &'a str,
hours: f64,
}Where the type of the field marked as locale must implement a (Since a language identifier will seemingly always just be parsed from a |
|
Also, thanks for working on this! I'm very excited to get this in! |
How would we know to use Fluent does not allow positional arguments. Allowing a |
|
I guess my question is, what bits of state (other than the locale) does a |
jhoobergs
left a comment
There was a problem hiding this comment.
Basically: We need to initialize a static loader (with fallback language) and somehow have access to that loader in different parts of the code.
| } | ||
| $v struct $n { | ||
| language: unic_langid::LanguageIdentifier, | ||
| loader: &'static fluent_templates::once_cell::sync::Lazy<fluent_templates::StaticLoader> |
There was a problem hiding this comment.
We need to be able to access this loader somehow. That's the reason for this struct.
| // The directory of localisations and fluent resources. | ||
| locales: $locales, | ||
| // The language to falback on if something is not present. | ||
| fallback_language: $fallback_language, |
There was a problem hiding this comment.
The fallback language can be added to the toml file.
| ][..]; | ||
|
|
||
| // create default localizer | ||
| let localizer = super::#loc_ty::default(); |
There was a problem hiding this comment.
Here we need to be able to somehow access the static loader. Currently an object of the generated struct type is used for that.
| self.localized_messages.insert(message.clone()); | ||
|
|
||
| buf.write(&format!( | ||
| "self.{}.translate(\"{}\", &std::iter::FromIterator::from_iter(vec![", |
There was a problem hiding this comment.
Here we need to be able to call the translate method. Currently it uses the Localizer object that has to be added to all Template structs.
|
Huh, sorry I missed your responses on this -- are you still interested in working on this? Having reviewed your code a bit more, how about having an Askama-provided type |
|
@djc I would certainly be interested in working on this. I'm not completely sure if I understand your solution with the Askama-provided |
|
Something like this: #[derive(Template)]
#[template(source = "{{ localize(\"hello\", age: 37) }}")]
struct UsesI18n<'a> {
#[locale]
loc: askama::Locale::new(lang_id, &TEMPLATES),
}with this struct Locale {
...
}
impl Locale {
fn new(lang: unic_langid::LanguageIdentifier, templates: &fluent_templates::StaticLoader) { ... }
} |
5633250 to
704f8f1
Compare
This (draft) PR gives an initial onset for localization (#202) by using fluent-templates to statically load all fluent translations.
It is based on code of @kazimuth
@djc Could you give some quick remarks / questions?
TODO
with-i18nfeaturestext_id's (the test fails, as it should, but we should assert that it fails instead of failing)init_translationsmacro