Skip to content
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

Basic skeleton for a multilinual actix-askama site #599

Closed
wants to merge 1 commit into from

Conversation

gpmake
Copy link

@gpmake gpmake commented Jan 11, 2022

I created a basic multi-language site with two pages (Home and About). For each page, I used two template structs with the same content. A possible next step is to create a newtype wrapped around an inner type with a Deref impl to share the same type definitions for the template structs. Here is the repository create on my GitHub account: git@github.com:gpmake/basic-actix-askama-multilingual-site.git

@Kijewski
Copy link
Contributor

Please have a look at #600 if that kind of localization would work for you. It has the added feature that you don't need to copy the structure multiple times, which I guess works better if you want to support a lot of languages.

@djc
Copy link
Owner

djc commented Jan 12, 2022

So I don't think we actually want an example of this, but here's the pattern I was trying to explain:

#[derive(Template)]
#[template(path = "home/home-en.html")]
struct HomeEn<'a>(Home<'a>);

impl<'a> std::ops::Deref for HomeEn<'a> {
    type Target = Home<'a>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

struct Home<'a> {
    lang: &'a str,
    title: &'a str,
    page: &'a str,
}

This way you can have multiple templates defined that all use the same underlying context type. You could potentially also have an impl<'a> From<Home<'a>> for HomeEn<'a> if that makes life easier for you.

@djc
Copy link
Owner

djc commented Jan 23, 2022

Going to close this for now; let's discuss in #600.

@djc djc closed this Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants