Set Up Polyglot
Just install Polyglot like a normal Jekyll plugin. Its gem name is
jekyll-polyglot.
There are several common ways to install a Jekyll plugin:
-
Directly add the plugin’s gem name to the
Gemfilefor your site:gem "jekyll-polyglot"Then, enable the plugin in
_config.yml:plugins: - jekyll-polyglotFinally, run
bundle install.I recommend this method if you plan to work on your site on different machines, e.g. multiple computers, your computer and a server, or your computer and a CI environment.
-
Create a Bundle group called
:jekyll_pluginsin theGemfile, and add the plugin’s gem name to it:group :jekyll_plugins do gem "jekyll-polyglot" endWith this method, you don’t need to modify
_config.yml, so just runbundle installdirectly.Keep in mind, the plugins you install in this way will always load even if you run Jekyll in
--safemode. -
Register the plugin in only
_config.yml:plugins: - jekyll-polyglotThen install it with
gem install jekyll-polyglot.A drawback of this method is your plugins won’t be automatically installed if you set up your site from another machine with
bundle: you should run thegemcommand again for plugins.
After plugin installation, add configuration options for Polyglot to
_config.yml:
languages: ["en", "zh"]
default_lang: "en"
exclude_from_localization: ["assets/css", "assets/img"]
parallel_localization: true
sass:
sourcemap: neverThe first four lines are just normal Polyglot preferences:
-
languagesis an array of ISO 639-1 codes for the languages your site supports. -
default_langis the code for your site’s default language. -
exclude_from_localizationis an array of directories where the files should be commonly shared for all languages. I suggest you at least add the directory for your site’s images here, so the images will not be copied for every localized version of your site during site generation, saving disk spaces. -
parallel_localizationindicates whether localization is run parallel during site generation. According to Polyglot’s documentation, if you are building your site on Windows, you might need to set this tofalse.
The sass.sourcemap option is a
workaround
for Polyglot’s issue with Jekyll 4.0. To be honest, I don’t really understand
what that issue is, but including that option in my configuration has not
caused any problems yet.