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

Multilingual switch button support #1391

Merged
merged 9 commits into from
Mar 18, 2020
Merged

Multilingual switch button support #1391

merged 9 commits into from
Mar 18, 2020

Conversation

stevenjoezhang
Copy link
Contributor

@stevenjoezhang stevenjoezhang commented Feb 29, 2020

Issue resolved: #1070

+# Show multilingual switcher in footer.
+language_switcher: false

@ZhaoEli
Copy link

ZhaoEli commented Mar 2, 2020

大神,可以开发一个文章底部点赞功能么!

@stevenjoezhang
Copy link
Contributor Author

已经有了,直接用就行。

@stevenjoezhang
Copy link
Contributor Author

Currently hexo-generator-index does not generate separate homepages for posts in different languages. For example,

source/
    _posts/
        zh-cn/
            post-zh.md
        en/
            post-en.md

Both posts will appear in the index page (/index.html , but not one in /index.html and the other in /zh-cn/index.html) - Unless you write your own script, modify configuration (e.g. url and root in _config.yml) and source files, then execute hexo g multiple times; or use 3rd-party plugins like hexo-generator-i18n.

Therefore, this pull requestis only partially done. Full multi-language support needs to wait for the hexo generator implementation.

@suyin-long
Copy link

这个效果怎么看不错来呢?设置后那个切换语言的按钮在哪呢?

@rexwangcc
Copy link

@suyin-long 需要在next/_config.yml中设置 language_switcher: true, 之后会在footer(页面的最下端)显示一个小图标。不满意位置的话可以自行定义sidebar等模板来放置这个选择框。

@zhengfc
Copy link

zhengfc commented May 1, 2020

图标是显示在底部了,一点击的话就是404了;模板要能根据选择语言读语言配置文件的数据就好了;这样至少整体页面结构首先就能切换了

@ext2ed
Copy link

ext2ed commented May 4, 2020

@suyin-long 需要在next/_config.yml中设置 language_switcher: true, 之后会在footer(页面的最下端)显示一个小图标。不满意位置的话可以自行定义sidebar等模板来放置这个选择框。

你好,我设置了 language_switcher: true 以后,好像没有图标在 footer 显示,是需要其他额外的设置吗

@Gabirel
Copy link

Gabirel commented Jul 15, 2020

Currently hexo-generator-index does not generate separate homepages for posts in different languages. For example,

source/
    _posts/
        zh-cn/
            post-zh.md
        en/
            post-en.md

Both posts will appear in the index page (/index.html , but not one in /index.html and the other in /zh-cn/index.html) - Unless you write your own script, modify configuration (e.g. url and root in _config.yml) and source files, then execute hexo g multiple times; or use 3rd-party plugins like hexo-generator-i18n.

Therefore, this pull requestis only partially done. Full multi-language support needs to wait for the hexo generator implementation.

I've made it generate automatically and works very well, except for some several glitches.

Steps to set up

Note for setting up multilingual website:

  1. Combine hexojs/hexo-generator-index and xcatliu/hexo-generator-index-i18n (install them)
  2. Make sure you add ja into your site config (aka, hexo/_config.yml)
  3. Create your posts via hexo new --lang ja "This is a new title"
  4. hexo clean && hexo g && hexo s
  5. Then you should see your post written by Japanese only if you switch your language to Japanese.

PS: This method has a bug that needs to be done in next-theme itself. Please see issue: https://github.com/next-theme/hexo-theme-next/issues/54

Current issues

  1. See issue: https://github.com/next-theme/hexo-theme-next/issues/54

  2. Multiple language pages cannot be generated with the current version of Hexo. (Tell me if I am wrong.)

    For example, /categories/ is showing your default page, such English. You can't have /ja/categories/ at this time, as well as page tag, archives, about.
    This works perfectly for now. Check my website and email me if you have any questions.

  3. Search in next-theme still goes through the whole database based on your posts. Normally, if you only speak Chinese, you don't want to get search results from some posts written by Japanese since you don't understand that language at all. Right? But, it is the case for now. (search plugins need to add multilingual support as well.)

  4. next/previous page in the post view contains multiple language posts. When you switch to Japanese, you should end up those Japanese pages only. (I will create a new issue for this.)

  5. If you do not have the same title for your multiple posts written by different languages, it will lead you to 404 not found.

Demo links

@doutv
Copy link

doutv commented Aug 20, 2023

@suyin-long 需要在next/_config.yml中设置 language_switcher: true, 之后会在footer(页面的最下端)显示一个小图标。不满意位置的话可以自行定义sidebar等模板来放置这个选择框。

你好,我设置了 language_switcher: true 以后,好像没有图标在 footer 显示,是需要其他额外的设置吗

需要在根目录下的 _config.yml 修改 language,只有 language_switcher: true 且 language 数量大于 1,才会显示

language:
- en
- zh-CN

@Happylinzy
Copy link

修改语言后,侧边栏的tag,categories等按钮需要在source目录下设置对应语言文件夹下的index才能替换。但是点击跳转还是回到默认的英文路径下

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

Successfully merging this pull request may close these issues.

Multilingual support
9 participants