Multilingual archetypes

Hi everyone!
I am making site with multilingual support. I want to add archetypes for posts in both language. Structure inside the content folder looks like this:

content
├── en
│   └── post.md
└── sr
    └── post.md

I tried to add folders ‘en’ and ‘sr’ in ‘archetypes’ folder but it didn’t work.

How can I solve this problem? Is there a way to add archetypes for two languages?

While there may be other possibilities, you can just have two separate files in archetypes/ and then “call” each separately. For example, let’s say you have archetypes/en.md for English posts and archetypes/sr.md for Serbian posts. Then, if you want to create a new en post called my-new-english-post, you’d use hugo new en/my-new-english-post.md — or, for a new sr post called my-new-serbian-post, use hugo new sr/my-new-serbian-post.md.

(Based on an article I wrote for the CloudCannon Blog.)

Thanks, but still not working. When I use new en/my-new-english-post.md, it makes in ‘sr’ folder.
Path is sr/en/my-new-english-post.md, same thing happens when write 'new sr/my-new-serbian-post.md`. It’s always the same path ‘content/sr/…’.

I use hugo v0.101.0, can that be a problem?

I use hugo v0.101.0, can that be a problem?

No, not related.

Sorry my suggestion didn’t work. Do you have a public repository so we could see your whole structure?

(Also: you might also try the --kind flag I mentioned in that linked article.)

Because my project is private, I made reference implementation of my site.

I worked with this for a while and, as nearly as I can determine, it’s controlled by your config file’s DefaultContentLanguage setting.

With it set at sr, as you had it, hugo new blog/test-post.md --kind sr/blog creates content/sr/blog/test-post.md. But if that setting is either changed to en or commented-out (which invokes the default setting of en), hugo new blog/test-post.md --kind sr/blog creates content/en/blog/test-post.md — in other words, the --kind sets only which archetype it uses but does not change the final language-specific subdirectory within content/; instead, the DefaultContentLanguage setting does. That does make sense, but the documentation doesn’t explain it.

(You’ll definitely want to use the --kind flag because, otherwise, Hugo uses only the default.md archetype from either theme/[YourTheme]/archetypes/sr/ or theme/[YourTheme]/archetypes/en/, depending on how DefaultContentLanguage is set in the config file.)

Anyway, it appears that, while creating your content from archetypes, you’ll need to switch back and forth on that DefaultConfigLanguage setting. Sorry that I can’t offer a more convenient answer.

You may also want to read this old question from years ago:

1 Like

It seems that there is no implementation yet for language-specific archetypes.

However

To use language-specific archetypes for a language you can do hugo new -k en/blog content/en/blog/my-new-post.md or hugo new -k sr/blog content/sr/blog/my-new-post.md and by including content in your path, the archetype will be interpolated and generated in the adequate folder. The archetypes folder should be structured as follows (in your example):

archetypes
├── en
│   ├── blog.md
│   ├── default.md
│   ├── faq.md
│   ├── series.md
│   └── tags.md
└── sr
    ├── blog.md
    ├── default.md
    ├── faq.md
    ├── series.md
    └── tags.md

It’s not elegant, but it works.

1 Like