diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index f5152f6da3a..1dbde6e371e 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -754,9 +754,13 @@ def copy_translation_js(self) -> None:
def copy_stemmer_js(self) -> None:
"""Copy a JavaScript file for stemmer."""
if self.indexer is not None:
- jsfile = self.indexer.get_js_stemmer_rawcode()
- if jsfile:
- copyfile(jsfile, path.join(self.outdir, '_static', '_stemmer.js'))
+ if hasattr(self.indexer, 'get_js_stemmer_rawcodes'):
+ for jsfile in self.indexer.get_js_stemmer_rawcodes():
+ copyfile(jsfile, path.join(self.outdir, '_static', path.basename(jsfile)))
+ else:
+ jsfile = self.indexer.get_js_stemmer_rawcode()
+ if jsfile:
+ copyfile(jsfile, path.join(self.outdir, '_static', '_stemmer.js'))
def copy_theme_static_files(self, context: Dict) -> None:
def onerror(filename: str, error: Exception) -> None:
diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py
index 6c748aed19f..cd099a6b5c1 100644
--- a/sphinx/search/__init__.py
+++ b/sphinx/search/__init__.py
@@ -439,15 +439,34 @@ def context_for_searchtool(self) -> Dict[str, Any]:
js_splitter_code = self.js_splitter_code
return {
- 'search_language_stemming_code': self.lang.js_stemmer_code,
+ 'search_language_stemming_code': self.get_js_stemmer_code(),
'search_language_stop_words': jsdump.dumps(sorted(self.lang.stopwords)),
'search_scorer_tool': self.js_scorer_code,
'search_word_splitter_code': js_splitter_code,
}
+ def get_js_stemmer_rawcodes(self) -> List[str]:
+ """Returns a list of non-minified stemmer JS files to copy."""
+ if self.lang.js_stemmer_rawcode:
+ return [
+ path.join(package_dir, 'search', 'non-minified-js', fname)
+ for fname in ('base-stemmer.js', self.lang.js_stemmer_rawcode)
+ ]
+ else:
+ return []
+
def get_js_stemmer_rawcode(self) -> str:
+ return None
+
+ def get_js_stemmer_code(self) -> str:
+ """Returns JS code that will be inserted into language_data.js."""
if self.lang.js_stemmer_rawcode:
- return path.join(package_dir, 'search', 'non-minified-js',
- self.lang.js_stemmer_rawcode)
+ js_dir = path.join(package_dir, 'search', 'minified-js')
+ with open(path.join(js_dir, 'base-stemmer.js')) as js_file:
+ base_js = js_file.read()
+ with open(path.join(js_dir, self.lang.js_stemmer_rawcode)) as js_file:
+ language_js = js_file.read()
+ return ('%s\n%s\nStemmer = %sStemmer;' %
+ (base_js, language_js, self.lang.language_name))
else:
- return None
+ return self.lang.js_stemmer_code