Comments (8)
我更新了最新dev的代码,惊喜的发现全站多语言基本上实现了。
首先,可以卸载hexo-multilingual的各种generator了,因为最新代码基本上实现了对应功能。
但是,hexo-multilingual这个核心包还是不能卸载,因为它基于
lang: en
label: hello-world
这两个标签,把混在一起的多语言文章给区分开来,在文章详情页上一篇下一篇就不会出现语言混搭。我尝试卸载后,发现多种语言文章混在一起了,如果解决了这个,就可以卸载hexo-multilingual了。
其他,发现的一些小问题,比如:
- about还没有多语言,可以引申为,所有page页是否可以用
lang和label
两个标签来区分多语言。 - 文章详情页的分类和书签链接,默认语言还是带en,无效。其实,我在config里用两个map完美实现双语分类和书签的切换。
category_map:
无他: nothing
tag_map:
随笔: anything
- Insight search现在貌似只能搜英文了,之前中英混搜,我觉得最好能分开,实在不行混在一起也行。
_config.<lang>.yml
里能对title、subtitle、description、date_format
进行多语言定义吗?- disqus.ejs里添加
this.language = '<%= theme.lang %>';
实现多语言化。 - 想添加一个语言跳转链接,我把footer改了,因为我只有2种语言的需求,所以简单暴力写了个死的切换函数,暂时实现了需求。如果你能写一个通用版切换器就完美了!
我想,双语应该是大部分人的需求,en默认,再加一个自己的母语。期待下一次更新。
from hexo-theme-minos.
首先,非常感谢能为我兼容 zh≈zh-cn
这种不严谨的诡异要求,我就是个对称控。
其次,我再也测不出bug了,除了修改了一点点代码,把index.html给匿了(还是强迫症)。
我在blog上也写了一篇 文章,讲述整个过程。
关闭此帖!
from hexo-theme-minos.
感谢建议,我会逐步更新这些功能
from hexo-theme-minos.
@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.
我在测试的过程中,感觉到约定大于配置,会省很多事,否则会出现各种问题。
我把根配置里稀奇古怪的地方都改成默认的了,然后按照你给的目录结构进行了重新布局。
_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,如下:
- 文章详情里分类和书签,在英文下,会有错链:/en/tags/anything, /en/categories/nothing
- 文章发布时间和阅读时间,中文下没有翻译,还是“8 Days Ago”
- 菜单Category和Tag点击进去,title漏了,只有站点名称
- footer里,切换器会被footer_links配置影响,应该这样
<% } %>
<%- partial('common/languages') %>
- 如果根配置这样写
permalink: :category/:title/
,文章中文链接就会变成这样
/nothing/zh/hello-world/
其他我觉得很好,准备写一篇文章帮小白入门。
from hexo-theme-minos.
-
与时间有关的翻译是由moment.js处理的,它使用的是
ll-cc
格式的语言代码,所以zh-cn
可以翻译成中文,但是zh
就不行。各个第三方库使用的语言代码格式不一,目前我在Disqus
,Facebook comment plugin
和moment.js
中把用户配置的语言代码转尽可能地转换成了它们需要的语言格式。关于语言格式的话请查阅ISO639
和RFC5646
。 -
目前如果在一个站点中使用多语言,并且对于同一个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.
最后,想起一点,不算bug,是不是head里少了一些meta,所以没有弹出谷歌翻译网页的东东,也就是没有强迫网页是某种语言属性。其实这样挺好,每次弹谷歌翻译也很烦人。
from hexo-theme-minos.
发现一些缺陷:
在多语言站点里,应该在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)
- Change the font? HOT 2
- '<' and '>' in code blocks will occur an error
- Using Netlify to deploy, Insight Search Chinese garbled. HOT 3
- How to change default renderer HOT 2
- 设置toc为true后,文章导航栏中文显示乱码 HOT 8
- a problem with the table presentation in markdown document HOT 2
- I Can't use Tag Plugin HOT 5
- show info. on every page with google-analytics data HOT 8
- [Feature Request] Make a table sortable HOT 1
- 本地启动后样式失效了 HOT 5
- Comment GitTalk Support
- gallery relate HOT 1
- [Configuration] Multi Language Suppport HOT 8
- Error when generating static files with Hexo 5.4.0 HOT 4
- [Feature Request] Add visit number
- render errors HOT 1
- [feature request] dark mode
- 搜索按钮出现在导航栏,但搜索页面出现在底部 HOT 10
- Is there full source code regarding to the theme example? 有没有主题文档那个例子的源码? HOT 4
- gallery插件问题 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hexo-theme-minos.