Closed sergiolepore closed 10 years ago
Some ideas:
_config.yml
language: es #main language
secondary_languages:
- en
- fr
- de
scaffolds
title:
date:
tags:
language: en
---
Post content
The public/index.html
file will have the posts with language = main language.
Posts, pages, archives will be rendered on /{language}/{slug/permalink}.
Inside public/{language}/
folder will reside the main index.html with the posts filtered by language.
If someone is interested, I'm already working on it: https://github.com/kassner/hexo
FYI, I never worked with NodeJS before, so probably I'll make a lot of mistakes. When I'll be done, I'll make a pull request.
Awesome! :)
The new i18n module is ready for this feature. When you call get
function, the module will iterate over the language
property and find the available translation or return the original string.
https://github.com/tommy351/hexo/blob/1c2b23725ea983db9949e5a169207c2f0772b0dc/lib/core/i18n.js
@tommy351 this isn't just for translate template strings?
This module is used in the templates. But it can be used in other purposes, too.
@tommy351 Do you have any example how to do multilanguage posts with it? I've been working on a multilanguage hexo on this fork, but this way seems MUCH way easier than the one I've been working on.
Create an i18n instance.
// You can use an array
var locale = new i18n(['zh-TW', 'zh', 'default']);
// => language: zh-TW, zh, default
// or a string as the argument.
var locale = new i18n('zh-TW');
// => language: zh-TW, zh, default
// If the language isn't defined, it'll be `default`.
var locale = new i18n();
// => language: default
Add language resources.
locale.add('default', {hello: 'Hello'});
locale.add('zh-TW', {hello: '你好'});
// ...
Use the get
function.
var _tw = locale.get('zh-TW');
_tw('hello');
// => 你好
_tw('what');
// => what
But your example is for template translation or "isolated" strings... I want this instead:
myblog.com
main index. Template Lang: ES. Posts lang: ES.myblog.com/en/
index for secondary language. Template Lang: EN. Posts lang: EN.myblog.com/es/2014/02/mi-post-en-espanol/
a blog post in spanish. Template Lang: ES. Post Lang: ES.myblog.com/en/2014/02/my-post-in-english/
this is the post above, but translated by me in another markdown file. Template Lang: EN. Post Lang: EN.Files:
source/_posts/2014-02-07-mi-post-en-espanol.md
Contents:
---
layout: post
title: "Mi post en español"
date: 2014-02-07 18:27
comments: true
categories:
tags:
language: es
---
Este es mi post escrito en español.
source/_posts/2014-02-07-my-post-in-english.md
Contents:
---
layout: post
title: "My post in english"
date: 2014-02-07 18:27
comments: true
categories:
tags:
language: en
---
This is my post written in english.
@sergiolepore I'm working on the similar problem for my boss. I'll post the solution when I'm done.
Nice! Thank you soooo much! :smile:
Here's my solution:
home
, post
generators._posts_:lang
folders.There're still many things to do. Categories, tag and archive pages are not supported so far.
I'll take a look as soon as I can. Thank you! :)
@tommy351: Is there any work being done about this or is it this still the way you suggest doing multiple manual translations of the same post?
Hi, I made an alternative to multi language support just doing some changes in the theme layout files, like this: http://www.shadowdr.com/. It's a bit annoying manage but if this is what you looking for, I would be glad to help.
@ShadowDanceRunner: That looks great! What would I need to do in order to replicate something like that?
When I was considering alternatives I thought about doing many posts with separators /LANG/YYYY/MM/DD (e.g.: /en/2014/03/23) but I realized that It would mean duplicate entries in lists of posts like "recent".
I see that you dealt with it nicely but do not show list of posts. Is it due to that problem or is it just a personal preference?
@IsaacRemuant : In fact I turned off the list, after adjusting I had not checked if it is doubling. As it is now, I know it is doubling the statistics of posts, but I did not care about this.
The official theme: https://github.com/ppoffice/hexo-theme-icarus Modified theme: https://github.com/ShadowDanceRunner/icarus-multilanguage-sample
I removed the duplicate listing on the index creating a condition in /layout/_partial/archive.ejs
Added the flags with the links to change the language in .//layout/_partial/article.ejs
Basically we create 2 posts, one as "mynamepost-en" and other "mynamepost-pt-BR", add in the Front matter of each post the "filename" attribute with the value: "mynamepost".
The trick is to create a link in article.ejs like this:
<a href="<%-url_for(post.path) %> ../<%= post.filename%> - en ">
Results in: blog.com/2015-03-31/mynamepost-pt-BR/../mynamepost-en
If you need more details I'll be glad to help. (sorry my bad english)
@ShadowDanceRunner. It worked wonders. Thanks. I had no issue with the translations.
However, I had a problem with both the duplicated posts in the "recents" widget (both appear) and its position (the css somehow positioning somehow got broken in the process?)
see: http://isaacremuant.github.io/ (the sidebar is at the bottom).
My first language is Spanish. I've been writing in Spanish since I remember, but now I want to share some thoughts in English. I remembered that Wordpress have a plugin called
WPML
, so I started to write a Hexo Plugin that mimics its functionality. I didn't get far :cry:Do you have any plans for this feature? I've been looking at some core files and I think that's not so hard to bring multi-language support by rewriting a few lines.
I'll be waiting until v2.5 comes out :smile: