I'm using Hexo to create a simple blog in NodeJS and I'm facing a problem regarding the localization.
Essentially, Hexo allow you to create multi-lingual blog, for doing so it is necessary edit the main config.yml including :/lang in front of permalink and new_post_name:
languages [it, en] #first language is the default language
permalink: :lang/:year/:month/:day/:title/
new_post_name: :lang/:title.md
so I edited the config.yml including those changes, and then I've created the localization file for italian and english, these files are included in the languages folder of the theme:
theme_name
languages
en.yml
it.yml
the it.yml looks like that:
hello_world: "Ciao Mondo"
and en.yml:
hello_world: "Hello World"
so I have defined the index.ejs (I'm using EJS as view template), and I've included the following content:
<p><%= __('hello_world') %></p>
so essentially when I go to: http://localhost:4000 I'll see the string Ciao Mondo.
Now there is a problem on that, when I switch to the english language, Hexo will look inside the en folder which is created inside source as the documentation suggest.
The problem's that for each language I need to have an index.ejs which cannot include the main index.ejs, so at this point the localization becomes completely useless.
For explain better the problem:
index.ejs which is loaded by layout.ejs, which also include the header and the footerHexo look at that route: http://localhost:4000/en, so the index.ejs is different.How can I use the root index.ejs from all the languages folders?
I tried already using <%= include ... %> but seems that the index.ejs does not support embedded javascript templateing..
Thanks in advance.
Hello @sfarzoso 👋
It looks like you're on the right track with the i18n.
Let me recommend two projects which have good i18n support for examples.
Theme NexT has done it the orthodox way:
https://github.com/theme-next/hexo-theme-next
This is one I have modified to have a different directory structure:
https://www.learnplasma.org/en/
https://www.learnplasma.org/zh/
So theoretically you could have this directory structure:
In any case the ./theme/your-theme/layout/ does not have different languages. Only 1.
Can you see if these examples help or would you like to expand on your need?
-TC
Source for example 2 https://github.com/ethsociety/learn-plasma
This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.