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:
|
|
Right below it, add the following snippet:
|
|
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:
|
|
演示: 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 inhead_custom.html. - To support a single non-English language (e.g., Chinese only): Replace
this.use(lunr.multiLanguage('en', 'zh'));withthis.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-languagesrepository.
转载请注明转自:Yijile.com( https://yijile.com/en/make-just-the-docs-search-lunr-js-multilingual-chinese/ )
本文采用 CC BY-NC-SA 4.0方式授权。
转载请注明出处和本文链接,说明是否进行修改,不得用于商业用途,使用相同方式共享。