How to Enable Multilingual and Chinese Search in Just-the-Docs (lunr.js)

🕘
⏱️
👁️ * VIews

When I first started looking into this, it felt a bit overwhelming. But once implemented, it turned out to be remarkably simple. Below is a streamlined guide to enabling multilingual search using lunr.js.

You only need to download the required language files and update two existing files:

Step 1: Update the Theme Script

Open assets/js/just-the-docs.js and locate the following line:

1
var index = lunr(function(){

Right below it, add the following snippet:

1
2
// Enable multilingual search for English and Chinese by 1px.run
this.use(lunr.multiLanguage('en', 'zh'));

Step 2: Download Language Libraries

Download lunr.multi.min.js, lunr.stemmer.support.min.js, and lunr.zh.min.js, then place them into your site’s /assets/js/vendor/ directory.

Download Link: You can fetch the pre-built language files directly from the lunr-languages GitHub repository.

Step 3: Load Scripts in HTML Head

Include the downloaded scripts inside your _includes/head_custom.html file:

1
2
3
4
5
{%- if site.search_enabled != false -%}
<script src="{{ '/assets/js/vendor/lunr.multi.min.js' | relative_url }}"></script>
<script src="{{ '/assets/js/vendor/lunr.stemmer.support.min.js' | relative_url }}"></script>
<script src="{{ '/assets/js/vendor/lunr.zh.min.js' | relative_url }}"></script>
{%- endif -%}

演示: https://1px.run

Note: lunr.multi.min.js and lunr.stemmer.support.min.js are strictly required dependencies.


Expanding or Customizing Language Support

  • To add more languages: Repeat the steps above—add the corresponding language code to lunr.multiLanguage(), download its JS file, and include it in head_custom.html.
  • To support a single non-English language (e.g., Chinese only): Replace this.use(lunr.multiLanguage('en', 'zh')); with this.use(lunr.zh);.
  • Finding language codes: Standard two-letter codes follow the ISO 639-1 Standard, which you can also verify by checking the filenames in the official lunr-languages repository.

转载请注明转自:Yijile.comhttps://yijile.com/en/make-just-the-docs-search-lunr-js-multilingual-chinese/

CC BY-NC-SA 4.0 声明
本文采用 CC BY-NC-SA 4.0方式授权。
转载请注明出处和本文链接,说明是否进行修改,不得用于商业用途,使用相同方式共享。

Last updated on |
一极乐 赏荷