Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Basic skeleton for a multilinual actix-askama site#599

Closed
gpmake wants to merge 1 commit into
askama-rs:mainfrom
gpmake:main
Closed

Basic skeleton for a multilinual actix-askama site#599
gpmake wants to merge 1 commit into
askama-rs:mainfrom
gpmake:main

Conversation

@gpmake
Copy link
Copy Markdown

@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
Copy Markdown
Member

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
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants