Multilanguage site: title and description for two languages

Good day! I try to make a site for two languages: ru and en. But it is impossible to set two values for TITLE in the file “/user/config/site,yaml” . I want to make two versions of the TITLE and DESCRIPTION: for russian and english languages. Is it possible to do this?

A first shot would be to use language specific constants.

You have to create a ‘languages’ folder in ‘user’ (user/languages). Then create a yaml-file for each language you want to support, e.g. en.yaml, ru.yaml (it is always a good idea to have these).

In the language-file add this lines (e.g. in user/languages/en.yaml):

  TITLE: "Some title"
  DESCRIPTION: "Some description"`

And for the ru.yaml do the same (use the same names like TITLE etc. The naming is up to you).

Then in your Twig templates you can do the following:

    <title>{% if page.title %}{{ page.title|e('html') }} | {% endif %}{{ "SITE.TITLE"|t }}</title>

The magic is the part {{ "SITE.TITLE"|t }}. This does the trick. The |t tells Twig to translate the key SITE.TITLE to the value given in the en.yaml if ‘en’ is the active language or ‘ru.yaml’ if ‘ru’ is the active language.

For SITE.DESCRIPTION it is the same trick.

You can do this for all texts which are not part of a content page in your pages folder. You just need to define a key structure (such as ‘SITE’ -> ‘TITLE’) and define the translation for them.

Thanks a lot for your answer! I changed TITLE in the file base.html.twig, it’s working :slight_smile: