https://github.com/neverbot/hexo-multilang
Multi-language plugin for Hexo. Helps you manage a web whose contents are written in different languages.
https://github.com/neverbot/hexo-multilang
Last synced: about 1 year ago
JSON representation
Multi-language plugin for Hexo. Helps you manage a web whose contents are written in different languages.
- Host: GitHub
- URL: https://github.com/neverbot/hexo-multilang
- Owner: neverbot
- License: mit
- Created: 2020-03-28T15:45:50.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2022-01-11T17:32:07.000Z (over 4 years ago)
- Last Synced: 2025-04-24T21:09:27.290Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 196 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# hexo-multilang
[](https://www.npmjs.com/package/hexo-multilang)
[](https://www.npmjs.com/package/hexo-multilang)
[](https://github.com/neverbot/hexo-multilang/blob/master/license.md)
[](https://www.npmjs.com/package/hexo-multilang)
| :warning: | *This project has been abandoned*: It was created to manage an Hexo web page with contents written in multiple languages (every page and post were repeated in every language, and you could switch between languages to see the different contents). I was managing a webpage with such needs, but not anymore, so I'm not going to maintain it. You can fork it and continue the work if you want. |
| --- | --- |
Multi-language plugin for [Hexo](https://github.com/hexojs/hexo). Helps you manage a Hexo page whose contents are written in different languages.
Based in [`hexo-generator-basic-set`](https://github.com/zyzyz/hexo-generator-basic-set) and [`hexo-generator-i18n`](https://github.com/Jamling/hexo-generator-i18n).
## Demo
You can see this plugin in use in [maldorne.org](https://maldorne.org), a Hexo blog which uses the `hexo-multilang` plugin with a modified version of the [Chic](https://github.com/Siricee/hexo-theme-Chic) theme. It has a language selector in the upper right corner, so you can see the blog changes **not only** the language of the theme, but the language of the contents, also.
### How to test the plugin in an easy way
This plugin provides functions which can help you build a multilang theme. The fastest way to see what can be achieved would be using an already compatible theme, so you could compare code and include the functionalities you would need in your own page. I've modified a version of the [Chic Theme](https://github.com/Siricee/hexo-theme-Chic) to make it compatible with `hexo-multilang`, which you can found in [hexo-chic-theme-multilang](https://github.com/neverbot/hexo-theme-chic-multilang). Take a look to its installation instructions if you want to test it in a local Hexo Blog, so you can see if this is what you are looking for.
## Installation
``` bash
$ npm install hexo-multilang
```
Remove any of these packages if they are installed:
``` bash
$ npm remove hexo-generator-archive hexo-generator-category hexo-generator-index hexo-generator-tag hexo-generator-basic-set hexo-generator-i18n
```
In Hexo the list of plugins installed will be taken from the `package.json` file, and will be loaded and executed in the order which they are found in. Any change or update to this file, locally or in a continuous integration environment, might be able to set its contents in alphabetical order, potentially changing your expected results. As the generators (`archive`, `index`, `tag`, `category`) are called by the same name in every plugin, the last plugin which uses them will have precedence.
So, until Hexo has a better way of handling the loading and execution of plugins, my recommendation is to uninstall any other plugin which includes the same generators or helpers, like the four default ones (the `npm remove` you can see above these lines), or the plugins `hexo-multilang` is based on, like `hexo-generator-basic-set` and `hexo-generator-i18n`.
## Config
*_config.yml*
``` yaml
plugins:
hexo-multilang:
languages: [en, es]
pagination-dir: page
index-generator:
per-page: 5
order-by: -date
index-dir:
default-lang: en
archive-generator:
per-page: 10
order-by: -date
archives-dir: archives
yearly: true
monthly: true
daily: false
category-generator:
per-page: 10
order-by: -date
categories-dir: categories
enable-index-page: true
tag-generator:
per-page: 5
order-by: -date
tags-dir: tags
enable-index-page: true
```
## Post creator modified
When you create a new blog post, it will be created (based on the corresponding scaffold) in every language set in the `_config.yml` file. i.e: for a config with:
``` yaml
language: [en, es]
permalink: :language/:year/:month/:day/:title/
new_post_name: :language/:year/:month/:day/:title.md
```
the creation of a new post will be like this:
``` bash
$ hexo new 'Something something'
INFO Posts created in: en, es
INFO Created: //source/_posts/es/1900/01/01/something-something.md
INFO Created: //source/_posts/en/1900/01/01/something-something.md
```
## Helpers included
### url_for
This plugin overwrites the original hexo `url_for` helper with a new one. By default it would prepend the needed language in the url path: `https://domain.com/some/thing/` would be `https://domain.com//some/thing/`.
If you need the original helper, it is saved as `__hexo_multilang_url_for`.
``` html
<%= post.title %>
```
It also accepts a second parameter with options:
``` js
url_for(path, { ignore : bool, language : string })
```
If `ignore` is present and is `true`, the `url_for` helper will behave as the original Hexo helper. This is useful to use for assets or other urls which would not be multilanguage. When you use this plugin with an already installed template, you will have to add this parameter to the links in the `` of the web, like css, js, etc.
``` html
<% theme.stylesheets.forEach(url => { %>
<% }); %>
```
If `language` is present and is one of the languages defined as an option in the plugin configuration, the language part of the url will be forced to be this value.
## License
[MIT](https://opensource.org/licenses/MIT)