GithubHelp home page GithubHelp logo

Comments (8)

dengcb avatar dengcb commented on June 22, 2024 1

我更新了最新dev的代码,惊喜的发现全站多语言基本上实现了。

首先,可以卸载hexo-multilingual的各种generator了,因为最新代码基本上实现了对应功能。
但是,hexo-multilingual这个核心包还是不能卸载,因为它基于

lang: en
label: hello-world

这两个标签,把混在一起的多语言文章给区分开来,在文章详情页上一篇下一篇就不会出现语言混搭。我尝试卸载后,发现多种语言文章混在一起了,如果解决了这个,就可以卸载hexo-multilingual了。

其他,发现的一些小问题,比如:

  1. about还没有多语言,可以引申为,所有page页是否可以用lang和label两个标签来区分多语言。
  2. 文章详情页的分类和书签链接,默认语言还是带en,无效。其实,我在config里用两个map完美实现双语分类和书签的切换。
category_map:
  无他: nothing
tag_map:
  随笔: anything
  1. Insight search现在貌似只能搜英文了,之前中英混搜,我觉得最好能分开,实在不行混在一起也行。
  2. _config.<lang>.yml 里能对title、subtitle、description、date_format进行多语言定义吗?
  3. disqus.ejs里添加this.language = '<%= theme.lang %>';实现多语言化。
  4. 想添加一个语言跳转链接,我把footer改了,因为我只有2种语言的需求,所以简单暴力写了个死的切换函数,暂时实现了需求。如果你能写一个通用版切换器就完美了!

我想,双语应该是大部分人的需求,en默认,再加一个自己的母语。期待下一次更新。

from hexo-theme-minos.

dengcb avatar dengcb commented on June 22, 2024 1

首先,非常感谢能为我兼容 zh≈zh-cn 这种不严谨的诡异要求,我就是个对称控。

其次,我再也测不出bug了,除了修改了一点点代码,把index.html给匿了(还是强迫症)。

我在blog上也写了一篇 文章,讲述整个过程。

关闭此帖!

from hexo-theme-minos.

ppoffice avatar ppoffice commented on June 22, 2024

感谢建议,我会逐步更新这些功能

from hexo-theme-minos.

ppoffice avatar ppoffice commented on June 22, 2024

@dengcb
首先需要在根目录下_config.yml设置多语言

language:
- en
- zh-cn

可以使用如下目录结构,无需设置lang

_post/
    my_post.md
    zh-cn/
        my_post.md
about/
    index.md
zh-cn/
    about/
        index.md

subtitle, description, date_format未在本主题中使用。
另外,更新之后无需再使用hexo-multilingual和hexo-generator-json-content.

from hexo-theme-minos.

dengcb avatar dengcb commented on June 22, 2024

我在测试的过程中,感觉到约定大于配置,会省很多事,否则会出现各种问题。
我把根配置里稀奇古怪的地方都改成默认的了,然后按照你给的目录结构进行了重新布局。

_post/
  hello-world.md
  zh-cn/
    hello_world.md
about/
  index.md
zh-cn/
  about/
    index.md

另外,把包也精简了

{
  "name": "dengcb.github.io",
  "version": "1.0.0",
  "private": true,
  "hexo": {
    "version": "3.7.1"
  },
  "dependencies": {
    "hexo": "^3.7.1",
    "hexo-deployer-git": "^0.3.1",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.1",
    "hexo-generator-tag": "^0.2.0",
    "hexo-pagination": "^0.1.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-renderer-sass": "^0.3.2",
    "hexo-renderer-stylus": "^0.3.1",
    "hexo-server": "^0.2.0"
  }
}

之前绝大部分问题都消失了,功能也很完美。

当然,还有些bug,如下:

  1. 文章详情里分类和书签,在英文下,会有错链:/en/tags/anything, /en/categories/nothing
  2. 文章发布时间和阅读时间,中文下没有翻译,还是“8 Days Ago”
  3. 菜单Category和Tag点击进去,title漏了,只有站点名称
  4. footer里,切换器会被footer_links配置影响,应该这样
<% } %>
<%- partial('common/languages') %>
  1. 如果根配置这样写permalink: :category/:title/,文章中文链接就会变成这样
    /nothing/zh/hello-world/

其他我觉得很好,准备写一篇文章帮小白入门。

from hexo-theme-minos.

ppoffice avatar ppoffice commented on June 22, 2024
  1. 与时间有关的翻译是由moment.js处理的,它使用的是ll-cc格式的语言代码,所以zh-cn可以翻译成中文,但是zh就不行。各个第三方库使用的语言代码格式不一,目前我在Disqus, Facebook comment pluginmoment.js中把用户配置的语言代码转尽可能地转换成了它们需要的语言格式。关于语言格式的话请查阅ISO639RFC5646

  2. 目前如果在一个站点中使用多语言,并且对于同一个post需要支持多个语言版本的话,必须保证post的path或者permalink以语言名开头,如zh-cn/example.md。这种情况下,设置permalink: :slug/...是最好的。而且因为post放到了zh-cn目录中,所以post的slug和title都是以zh-cn开头的。所以这个是Hexo对于permalink的规定。设置为permalink: :category/:title/的话会导致切换语言的时候文章路径错误。

from hexo-theme-minos.

dengcb avatar dengcb commented on June 22, 2024

最后,想起一点,不算bug,是不是head里少了一些meta,所以没有弹出谷歌翻译网页的东东,也就是没有强迫网页是某种语言属性。其实这样挺好,每次弹谷歌翻译也很烦人。

from hexo-theme-minos.

dengcb avatar dengcb commented on June 22, 2024

发现一些缺陷:
在多语言站点里,应该在head里添加alternate url,如:

<link href="https://dengcb.com/hello-world/" rel="alternate" hreflang="en" />
<link href="https://dengcb.com/zh/hello-world/" rel="alternate" hreflang="zh" />

这样,对搜索引擎更友好,seo更好

from hexo-theme-minos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.