In this tutorial, we’ll discuss how to configure fonts that support multiple languages on Linux. First, we’ll begin by having a general overview of how multilingual fonts on Linux work and how we can find fonts that support a specific orthography.
Afterward, we’ll learn how to install and configure these multilingual fonts using fontconfig.
2. Multilingual Fonts on Linux
Major distributions like Ubuntu and Fedora should have support for multiple languages out-of-the-box. If that is not the case, we can install a language pack for our language in the distribution settings.
However, if we have a minimal installation of these distributions or use other distributions like Gentoo, we’ll need to manually configure fonts for other languages. Therefore, it’s good to have a basic understanding of how Linux handles multilingual fonts.
When there are no suitable fonts for the target language, we’ll see placeholder characters as depicted in the image:
As we can see, the Japanese characters don’t make much sense because there is no suitable font available for the language. In the next section, we’ll take a look at a couple of font families that support multiple languages.
2.1. Fonts That Support Multiple Orthographies
We can install a single font package for a single target language. For instance, we can install the IPA fonts for the Japanese language—the default Japanese font on OpenSUSE. However, there might be some characters in the font file that might be missing.
For that reason, it’s usually better to have a one-stop solution for a wide range of languages. This way, we won’t see the strange ligatures on web pages that contain multiple languages.
Currently, there are two reliable multilingual font families that are free to use:
- Google Noto
- Adobe Source Sans
These two font families are available on most package repositories and contain many font files for a plethora of languages. Of course, there are paid solutions as well, but they are not backed up by such companies, and they are expensive.
In the next section, we’ll install and configure the Noto fonts for Ubuntu. However, this method applies to other distributions as well.
2.2. Installing Multilingual Fonts
The most straightforward way to install multilingual fonts is to use a package manager. We can search through our package repository to find the suitable names of the packages, as they might vary for different distributions.
On Ubuntu, we can use apt to install the Noto fonts:
$ sudo apt install -y fonts-noto fonts-noto-cjk
Similarly, we can also download and install the fonts manually:
$ curl -L https://github.com/notofonts/noto-fonts/archive/refs/heads/main.zip -o noto-fonts.zip
Once downloaded, we can unzip the archive and copy the relevant font files to ~/.local/share/fonts:
$ unzip noto-fonts.zip -d ~/.local/share/fonts/noto-fonts
In the same way, we can also download and install the CJK font files for Chinese, Japanese, and Korean languages.
2.3. Updating the Font Cache
Once the fonts are installed, we’ll update the font cache so that it’s available for immediate use:
$ fc-cache -f
Next, let’s test it out:
3. Configuring Multilingual Fonts
Sometimes, the fonts for a target language are overridden by other fonts. Therefore, the glyphs will not be rendered correctly. As an example, let’s take a look at the article below in Pashto:
In this case, another font took precedence over the Noto fonts that support this language. Therefore, we’ll need to configure a Pashto font, which we’ll cover in the next section.
3.1. fontconfig Configuration
fontconfig is a utility we can use to configure fonts on a Linux machine.
The config file for fontconfig is located in ~/.config/fontconfig/fonts.conf. We can create it manually if it’s not there:
$ mkdir -p ~/.config/fontconfig&& touch ~/.config/fontconfig/fonts.conf
The fonts.conf file is a plain XML file that we can modify easily. Let’s add the following properties to the file:
<?xml version='1.0'?> <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> <fontconfig> <!-- Defaults --> <alias> <family>serif</family> <prefer> <family>Noto Serif</family> <family>Noto Sans Arabic</family> <family>Joy Pixels</family> </prefer> </alias> <alias> <family>sans-serif</family> <prefer> <family>Noto Sans</family> <family>Noto Sans Arabic</family> <family>Fira Sans</family> <family>Joy Pixels</family> </prefer> </alias> <alias> <family>sans</family> <prefer> <family>Noto Sans</family> <family>Noto Sans Arabic</family> <family>Fira Sans</family> <family>Joy Pixels</family> </prefer> </alias> <alias> <family>monospace</family> <prefer> <family>Cascadia Code</family> <family>Noto Sans Mono</family> <family>Joy Pixels</family> </prefer> </alias> </fontconfig>
Let’s break this down:
- all the configurations reside inside the root fontconfig tag
- the <alias> tag creates an alias that we can refer to in applications
- the <family> tag specifies a font family — serif in the first instance
- the <prefer> tag specifies the order of preference
Now, we can refer to these fonts as “serif”, “sans-serif”, “sans”, and “monospace” when selecting the font in an application. fontconfig will map these names to our target fonts automatically. We can add as many fonts here as we desire. However, these should cover most languages.
For our example above, we explicitly specified Noto Fonts Arabic for our target language Pashto. Therefore, we should now see the fonts render correctly on the page:
3.2. Adding Aliases for Unavailable Fonts
Oftentimes, web pages choose their own fonts for a specific language. For instance, most front-end developers will choose “Arial” for languages like Arabic and Persian. Of course, it’s their fault for not taking other platforms into account and hardcode the font name in the stylesheets.
Fortunately, we can create aliases for some of these famous font families. As an example, we’ll create an alias, “Arial”, that will be mapped to Noto fonts in our fonts.conf:
<?xml version='1.0'?> <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> <fontconfig> ... <!-- Arial --> <alias> <family>Arial</family> <prefer> <family>Noto Sans</family> <family>Noto Sans Arabic</family> <family>Joy Pixels</family> </prefer> </alias> </fontconfig>
Now, when we visit a page that requires the “Arial” font, the browser will render the text in Noto fonts.
In this article, we discussed how to configure fonts for multiple languages. We looked at the installation of Noto fonts, which is a one-stop solution for most languages.
Afterward, we saw how to configure multilingual fonts using fontconfig.