Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multilingal search #26

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: scala
jdk: oraclejdk8
jdk: openjdk8
scala: 2.12.6
script: sbt verify

Expand Down
6 changes: 6 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ lazy val optionExamples = Def.settings(
_.withSearch(tokenizer = "[\\s\\-\\.]+")
}
//#search-tokenizer
,
//#search-language
Compile / paradoxMaterialTheme ~= {
_.withSearchLanguage("ru", "jp")
}
//#search-language
)

def project(id: String, base: File): Project = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ case class ParadoxMaterialTheme(properties: Map[String, String]) {
def withoutSearch() =
withoutProperties("search", "search.tokenizer")

def withSearchLanguage(languages: String*) = {
// See(mkdocs-material v3.0.3) https://github.com/squidfunk/mkdocs-material/blob/12a79817f057b09f05c3d7cffe8893dfe9c6bde9/material/base.html#L181-L200
val scripts = "<script src=\"assets/javascripts/lunr/lunr.stemmer.support.js\"></script>" +: languages.flatMap { lang =>
val lunrScript =
if (Set("da", "de", "du", "es", "fi", "fr", "hu", "it", "jp", "no", "pt", "ro", "ru", "sv", "tr").contains(lang)) {
Seq(s"""<script src="assets/javascripts/lunr/lunr.${lang}.js"></script>""")
} else Seq.empty
if (lang == "jp") {
"<script src=\"assets/javascripts/lunr/tinyseg.js\"></script>" +: lunrScript
} else lunrScript
} :+ "<script src=\"assets/javascripts/lunr/lunr.multi.js\"></script>"
withProperties("search.language" -> languages.mkString(","))
.withProperties("search.scripts" -> scripts.mkString("\n"))
}

def withCopyright(copyright: String) =
withProperties("copyright" -> copyright)

Expand Down
20 changes: 2 additions & 18 deletions src/main/paradox/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,35 +252,19 @@ your site. If you want to disable search use:

@@ snip [build.sbt]($root$/build.sbt) { #disable-search }

<!--

### Search language

Site search is implemented using [lunr.js][22], which includes stemmers for the
English language by default, while stemmers for other languages are included
with [lunr-languages][23], both of which are integrated with this theme. Support
for other languages and even multilingual search can be activated by setting
`material.search` to a comma-separated list of supported 2-letter
language codes, e.g.:
The multilingual search can be activated by doing the following.

@@ snip [build.sbt]($root$/build.sbt) { #search-multi }

This will automatically load the stemmers for the specified languages and
set them up with site search, nothing else to be done.

At the time of writing, the following languages are supported: English `en`,
French `fr`, Spanish `es`, Italian `it`, Japanese `jp`, Dutch `du`, Danish `da`,
Portguese `pt`, Finnish `fi`, Romanian `ro`, Hungarian `hu`, Russian `ru`,
Norwegian `no`, Swedish `sv` and Turkish `tr`.
@@ snip [build.sbt]($root$/build.sbt) { #search-language }

@@@ warning { title="Only specify the languages you really need" }
Be aware that including support for other languages increases the general
JavaScript payload by around 20kb (without gzip) and by another 15-30kb per
language.
@@@

-->

### Search tokenization

The separator for tokenization can also be customized, which makes it possible
Expand Down
1 change: 1 addition & 0 deletions theme/src/main/assets/assets/javascripts/lunr/lunr.da.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions theme/src/main/assets/assets/javascripts/lunr/lunr.de.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions theme/src/main/assets/assets/javascripts/lunr/lunr.du.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading