Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Internationalization #1696

Closed
CedricCoopengo opened this issue Jan 4, 2016 · 22 comments
Closed

How to use Internationalization #1696

CedricCoopengo opened this issue Jan 4, 2016 · 22 comments
Labels

Comments

@CedricCoopengo
Copy link

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?

@rmarku
Copy link

rmarku commented Jan 5, 2016

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

@larfadin
Copy link

larfadin commented Jan 5, 2016

+1

It would be great if i18n from the doc could work !

@KevinAdu
Copy link

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?

@leesei leesei added question Needs help in usage i18n labels Feb 23, 2016
@zyzyz
Copy link

zyzyz commented May 20, 2016

I think this may solve your problem
hexo-generator-index-multi-lang

@automata
Copy link

Basic generator isn't generating indexes for different languages yet. Even when using @zyzyz's hexo-generator-basic-set: zyzyz/hexo-generator-basic-set#1.

@stale stale bot added the wontfix This will not be worked on label Sep 27, 2017
@stale
Copy link

stale bot commented Sep 27, 2017

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.

@HarshaVardhanPVK
Copy link

Did any one got a solution to display posts/pages in multiple languages?

@stewones
Copy link

+1

@iagobruno
Copy link

@hexojs can you help here? I'm having the same problem.

@mohsenkhanpour
Copy link

mohsenkhanpour commented Dec 30, 2018

Any solutions to this issue?
All posts are generated in the index page and archive regardless of the lang.

@stewones
Copy link

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/

@mohsenkhanpour
Copy link

@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.

@stewones
Copy link

Did you try this plugin?

https://github.com/DougBeney/jekyll-pug/blob/master/README.md

@mohsenkhanpour
Copy link

@stewwan Yeah. Didn't work as expected. I guess the problem with Hexo is lack of correct documentation as most docs are confusing.

@mohsenkhanpour
Copy link

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.

@stale stale bot added the stale label Mar 9, 2019
@yoshinorin yoshinorin added help wanted and removed stale wontfix This will not be worked on labels Mar 11, 2019
@hexojs hexojs deleted a comment from stale bot Mar 11, 2019
@microSoftware
Copy link

Sad the i18n doesn't work. This project was awesome.

@mfechner
Copy link

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: #1696 (comment) 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.

@mohsenkhanpour
Copy link

mohsenkhanpour commented Mar 15, 2020

@mfechner You should define the pages for each language.

  1. Create an index layout
  2. Create index posts for your locales "en", "de",... (markdown for example)
  3. Pass the layout to your posts.

Then your "/en" and "/de" routes will be created and show the right messages.

@mfechner
Copy link

@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.

@mohsenkhanpour
Copy link

mohsenkhanpour commented Mar 15, 2020

@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.

oscarcala added a commit to oscarcala/site that referenced this issue Dec 9, 2020
based on this answer hexojs/hexo#1696 (comment) I propose to update the documentation as this is a FAQ. 

Thanks
@github-actions
Copy link

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.

@Tay0108
Copy link

Tay0108 commented Mar 16, 2024

@mohsenkhanpour thank you for your post, managed to make it work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests