From the documentation i18n is easy to use.
I have to add to my _config.yml this:
language:
- fr
- en
and add the languages folder to my theme with the translations.
If I had <%= __('index.title') %> to my index.ejs I have the french translation on http://localhost:4000/ but on http://localhost:4000/en/ I got this error Cannot GET /en/.
In the document website you didn't even setup the _config.yml
There is a "page" folder for every translation + the index.jade.
I've tried to create a "page" folder for my english translation with an index.html file in.
But when I got on http://localhost:4000/en/ it loads my index.html (the one from my "en" folder) in the `page.ejs``layout but this is not what I want.
How do I load my en.yml translation when I'm on http://localhost:4000/en/ instead of the "en" page?
same question, I have added to my _config.yml:
language:
- es
- en
- de
permalink: :lang/:year/:title/
permalink_defaults:
lang: es
new_post_name: :lang/:title.md
when i write:
hexo new 'Hola Mundo' --lang es
hexo new 'Hola Mundo' --lang en
the post is created in the right folder Page Name source/_posts/es/Hola-Mundo.md but there are only one index.html for all post, so I get in my home page two times the same post, but in diferent languages.
I think that the idea of internationalization is to have a mirror of the site, but in other langues
+1
It would be great if i18n from the doc could work !
So in other words there currently isn't a way to display posts according to language?
So for example English posts appearing under the /en/index.html and Japanese posts appearing under the /ja/index.html and etc?
I think this may solve your problem
hexo-generator-index-multi-lang
Basic generator isn't generating indexes for different languages yet. Even when using @zyzyz's hexo-generator-basic-set: https://github.com/zyzyz/hexo-generator-basic-set/issues/1.
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.
Did any one got a solution to display posts/pages in multiple languages?
+1
@hexojs can you help here? I'm having the same problem.
Any solutions to this issue?
All posts are generated in the index page and archive regardless of the lang.
This project looks dead. I ended up by using jekyll, for those who are facing the same
https://forestry.io/blog/creating-a-multilingual-blog-with-jekyll/
@stewwan I am moving from Jekyll because I need to use Pug templates for a project.
The problem I have is that default language is not respected and index layout for English is used for the first page.
Did you try this plugin?
https://github.com/DougBeney/jekyll-pug/blob/master/README.md
@stewwan Yeah. Didn't work as expected. I guess the problem with Hexo is lack of correct documentation as most docs are confusing.
You can easily generate posts for one language in your index with a simple if statement.
Something like:
if (post.lang == __('lang')) {
//do stuff here
}
Moderators please close this issue as the starter is inactive.
Sad the i18n doesn't work. This project was awesome.
I have exactly the same problem.
I followed the manual here: https://hexo.io/docs/internationalization
I defined in _config.yml the following:
language:
- de
- en
timezone: 'Europe/Berlin'
permalink: :lang/
i18n_dir: :lang
new_post_name: :lang/:title.md # File name of new posts
I have some __('test') and used the translation folder with de.yml to add the translation.
This works fine. If I switch now the site using a link to english with: <a href="/en/" ... it does not work.
I get the error Cannot GET /en/ I typed it from memory, so test can be a little bit different.
It seems it cannot handle the language and therefor does not find the index.ejs.
This comment: https://github.com/hexojs/hexo/issues/1696#issuecomment-220610940 recommended to use the plugin hexo-generator-index-multi-lang. The plugin mentioned that it is deprecated and you should use https://github.com/zyzyz/hexo-generator-basic-set.
So I added it and configured it as recommended.
I tried now both, hexo g and hexo server --watch but it does not work.
If I access the / site which delivers the index.ejs I see both languages, but this site is correctly translated to German.
If I switch to /en/ or /de/ it displays a completely different page, translation is not working (__('contact') so it seems something is here really broken.
Have someone an idea how to get this working?
I saw that switching to another tool like jekyll was recommended by a user, but this is not really a solution.
@mfechner You should define the pages for each language.
Then your "/en" and "/de" routes will be created and show the right messages.
@mohsenkhanpour thanks a lot for your answer. As hexo is completely new for me, it really could be, that I do something wrong. I tried now to strip an example that shows my problem, you can find it here:
https://github.com/mfechner/hexo_i18n_problem
To see the problem, just execute:
npm i
hexo server --watch
Now click on the German and English flag. You will see:
Cannot GET /en/
If I generate the site using hexo g and check the generated html files the __() parts are not translated:
<!-- Footer -->
<div id="footer">
<div class="card-group">
<div class="card border-0 text-center">
<div class="card-img-top">
<i class="fa fa-address-card" aria-hidden="true"></i>
</div>
<div class="card-body">
<h5 class="card-title">Contact</h5>
<p class="card-text">
Tel:
Here the text in the h5 should be Kontakt and not Contact.
I hope this makes the problem more reproduceable that I have.
@mfechner As you see in the built HTML, the string is being rendered by Hexo.
I looked at your repo, the problem is you have created posts for you website but not pages.
.
βββ workspace/
βββ source/
βββ _posts/
β βββ en/
β β βββ welcome.md
β β βββ blogpost.md
β β βββ ...
β βββ de/
β βββ willkommen.md
β βββ blogpost.md
β βββ ...
βββ en/
β βββ index.md
βββ de/
βββ index.md
You are missing those index files which are responsible for /en/ and /de/ index pages.
You don't need much content inside those files if your view is handled via your layout.
You only need to define layout in the frontmatter so your index page is rendered using that layout.
You can add the alias to your default language index so / redirects to your default locale e.g. /de/
---
layout: index
alias: index.html
---
It's no wonder you are getting 404 for /en/ as your current setup generates posts but not pages.
I hope this helped you.
Most helpful comment
I think this may solve your problem
hexo-generator-index-multi-lang