Hexo: How to load main index file using hexo i18n localization?

Created on 24 Jun 2019  路  3Comments  路  Source: hexojs/hexo

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:

  • You create a main index.ejs which is loaded by layout.ejs, which also include the header and the footer
  • You create the configuration files for each language
  • When you switch to another language, Hexo 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.

i18n question stale

All 3 comments

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:

  • ./source

    • ./_data

    • ./it.yml

    • ./en.yml

    • ./languages.yml

    • ./it

    • ./_posts/qualcosa.md

    • ./chi-siamo/index.md

    • ./en

    • ./_posts/anything.md

    • ./about-us/index.md


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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lushijie picture lushijie  路  3Comments

bearpaw picture bearpaw  路  3Comments

demurgos picture demurgos  路  3Comments

testareas picture testareas  路  3Comments

mashirozx picture mashirozx  路  3Comments