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

Need help on Internationalization (i18n) (Critical) #3247

Closed
hachi1030-Allen opened this issue Sep 2, 2018 · 13 comments
Closed

Need help on Internationalization (i18n) (Critical) #3247

hachi1030-Allen opened this issue Sep 2, 2018 · 13 comments
Labels
duplicate This issue or pull request already exists feature-request i18n

Comments

@hachi1030-Allen
Copy link

Environment Info

Node version(node -v): v8.9.4

Your site _config.yml (Optional): Need to confirm with you on this.

Your theme _config.yml (Optional): Need to confirm with you on this.

Hexo and Plugin version(npm ls --depth 0):
+-- hexo@3.7.1
+-- hexo-deployer-git@0.3.1
+-- hexo-generator-archive@0.1.5
+-- hexo-generator-category@0.1.3
+-- hexo-generator-feed@1.2.2
+-- hexo-generator-index@0.2.1
+-- hexo-generator-search@2.2.5
+-- hexo-generator-tag@0.2.0
+-- hexo-renderer-ejs@0.3.1
+-- hexo-renderer-marked@0.3.2
+-- hexo-renderer-njucks@1.0.0
+-- hexo-renderer-stylus@0.3.3
`-- hexo-server@0.3.3

For question

I really need some help from you guys on the i18n implementation.

I was trying to follow the blog: https://bluemix.github.io/en/2017/multilingual-blogging-with-Hexo/

After modifying the new_post_name to :lang/:title.md, I was able to create the md files in the seperate folders. However, there will be generate issue that my blogs are not generated correctly. The error message is something like: ENOENT no file or directory: path for some image. .

Please contact me back so that I can demonstrate to you guys on this error.

Also, I need to confirm one thing from you guys. If I enabled the international blogs for both Chinese and English language, do I have to match the articles? Is it possible that only the technical documents that I wrote, I will prepare 2 languages for that, but for others, I just create Chinese ones? The page will render or not?

Please contact back to me via: liu.allen1030@gmail.com as soon as possible. It's really critical for me.

Thanks,

Allen

@hachi1030-Allen
Copy link
Author

No one checked this? So how can we get support on Hexo if the supporting is so bad? The documentation is really really bad, we definitely cannot follow. It's really critical for me!

@tcrowe
Copy link
Contributor

tcrowe commented Sep 25, 2018

Yeah @hachi1030-Allen it can be very difficult. We need more people to help!

i18n is difficult for everyone and it's not clear the best way to use it. Thankfully hexo is so flexible you can roll your own if the default functionality doesn't work for you.

One project with good i18n is theme-next https://github.com/theme-next/hexo-theme-next

Also fork my project here for very advanced i18n support. I did examples with EN, DE, and ZH-HK.

https://github.com/tcrowe/learn-plasma
https://fervent-sammet-4b8cc8.netlify.com/en/

@tomap
Copy link
Contributor

tomap commented Sep 27, 2018

Did you push the source code of your blog on GitHub? That would help us see and understand your full config

@hachi1030-Allen
Copy link
Author

@tcrowe

Hi Tony,

Thanks for the reply. Since it's been a while, I had to use the another blog theme. You can check my needs on the i18n from my current blog: http://liudeyun.net.

I checked on your GitHub link for the theme next, but I did not see any sample blog there is having the i18n feature. Please check mine, I had 2 languages for same blog.

I just want to know, assume that I would like to develop my own theme, what is the best practice to implement i18n?

Thanks,

Allen

@tcrowe
Copy link
Contributor

tcrowe commented Sep 28, 2018

Good to hear back @hachi1030-Allen

Your site looks good. 👍🏼


Assuming unix

To make an i18n theme add to ./theme/my-theme/_config.yml

# main language
language: zh-cn

# all supported languages
languages:
- zh-cn # <---primary at top
- en

Create languages yaml directory:

mkdir -p themes/my-theme/languages

Create yaml for each language i18n texts:

touch themes/my-theme/languages/zh-cn.yml
touch themes/my-theme/languages/en.yml

Edit ./themes/my-theme/languages/zh-cn.yml

你好: 你好

Edit themes/my-theme/languages/en.yml

你好: hello

The key is 你好 so every language must have the same key but different value.


Okay! Languages are ready to go. Now lets implement it inside the template:

Edit ./themes/my-theme/layout/index.ejs

<%= __('你好') %>

That's it!

Can you try and let me know if it worked?

Here, this will generate a new theme very quickly. https://github.com/tcrowe/generator-hexo-theme

@tcrowe
Copy link
Contributor

tcrowe commented Sep 28, 2018

You can also add the language to the layout template:

<html lang="<%=config.language%>">

If not that try lang

@tcrowe
Copy link
Contributor

tcrowe commented Sep 28, 2018

Pages and posts:

---
lang: en
title: ...
date: ...
---

-or-

---
lang: zh-cn
title: ...
date: ...
---

@hachi1030-Allen
Copy link
Author

@tcrowe

Hi Tony,

Thanks for the reply!

Looks like quite easy in your instructs, but as far as I learnt, it's not.

Assume that I would like the same effect as in my blog:

image

I can switch the language both in the root page and also blog post page. How can I implement this using the current i18n?

Also, in my current theme, I have to follow the rules in that theme and there is definitely something bad. For my current folder structure, under my source_posts folder, I will have an additional folder named as zh-cn to put all my Chinese blogs, that's fine. But if I enable post_asset_folder: true, then whenever I created a blog, then I will have a same named folder created. To achieve the internationalization, I have to have a copy of the folders as well in the zh-cn folder for Chinese blogs to use the pictures.

And since that theme do not have the en folder to put English articles, we just use the default folder which is source_posts to put them, so I cannot use the hexo new articlename --lang language to generate blogs into correct folders as well.

That's why I am asking do we have any best practice to achieve this kind of thing?

Thanks,

Allen

@tcrowe
Copy link
Contributor

tcrowe commented Sep 29, 2018

I can switch the language both in the root page and also blog post page. How can I implement this using the current i18n?

It's a good idea to dig through each theme you see which has i18n. It goes something like this.

<% config.theme.languages(lang => { %>
<div>lang: <%=lang%></div>
<% }) %>

If you share the same assets between languages maybe its best to put them in ./source/img/posts/*.png.

source_posts to put them, so I cannot use the hexo new articlename --lang language.. That's why I am asking do we have any best practice to achieve this kind of thing?

It's not clear to me how that should work in hexo or any static site generator. We do need clearer instructions about the i18n capabilities.

One idea I had was to do something like this:

screen shot 2018-09-29 at 12 49 33 pm

You said you could not see it but try to look at these again on how to accomplish the lang/_posts. Fork it and customize for your needs. At the top right switch languages:

screen shot 2018-09-27 at 8 07 15 pm

screen shot 2018-09-27 at 8 07 22 pm

https://github.com/tcrowe/learn-plasma

https://fervent-sammet-4b8cc8.netlify.com/en/

@tcrowe
Copy link
Contributor

tcrowe commented Sep 29, 2018

I like your idea with hexo new articlename --lang language on the CLI. I think we should consider including your idea with mine for hexo i18n. Even if it's just a plugin.

@hachi1030-Allen
Copy link
Author

@tcrowe

Thanks for the reply.

I totally agree with you. I am expecting 3 things actually:

  1. A much detail documentation about i18n implementation.
  2. Some detail sample that can help us to implement these.
  3. Maybe we can have some more interactive communication, for example, live chat, live meeting, etc.

Not sure whether it's possible or not.

Thanks,

Allen

@hachi1030-Allen
Copy link
Author

@tcrowe

Also, yes, please make it as a feature request, I do think if we are going to use internationalization, we should be able to create blogs directly under correct folder using CLI.

Thanks,

Allen

@yoshinorin yoshinorin mentioned this issue Mar 14, 2019
53 tasks
@stevenjoezhang
Copy link
Member

stevenjoezhang commented Feb 29, 2020

See also #1696
I'm closing this issue. Please join the discussion there :)

@stevenjoezhang stevenjoezhang added duplicate This issue or pull request already exists and removed discussion question Needs help in usage labels Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists feature-request i18n
Projects
None yet
Development

No branches or pull requests

4 participants