Author: Stasyuk Eugene 118 Tags: , 18.12.2022

While working on creating a WordPress theme, we often come across such inscriptions as “upload more, author, tags”, etc. For example, as in my blog:

Пример записей

It’s good when the site is in one language. Then you don’t really need to do anything with them. But what to do when the site is multilingual.

If the customer does not need to change their names in the future, then there is no point in displaying them for editing in the admin panel either.

There is a lot of information on the Internet in which the use of the Poedit program appears. But there is a much more elegant way. To do this, we need the Loco Translate plugin. This add-on is extremely useful to use – thanks to it you can translate not only theme entries, but also plugins. But specifically today we will talk about the translation of the topic.

Here I will not go into much theory. Let’s focus on the process.

Stages:

  1. In the files with the theme, we place the entries we need in one of these functions _e(), __(); The only difference between these functions is that _e() immediately displays the text on the page, while __() only receives it (therefore, you need to use echo to display the translation text).
    _e('Author', 'my-site');
    echo __('Author', 'my-site');

    The functions have two arguments: The first one is the text to be translated (mandatory). Second: Transfer ID. The scope of the translation, denoted by the name, which then becomes an identifier in PHP (optional).
    Функции

  2. Uploading the Loco Translate plugin to our site
  3. In the admin panel in the left menu we find the Loco Translate item, hover over it with the mouse and click on the Themes item.В меню
  4. We ended up on a page where all the downloaded themes that are available to us for use on the site are displayed. We choose our current theme. In this case, it’s a topic called “My”Темы
  5. Before proceeding to the next step, I recommend creating a directory called languages in the theme folder. Here we will store all the files that are related to the translation of our theme.languages
  6. After point 4, if you create a topic from scratch, then most likely you will be greeted with the following message on the page that opens – No translations found for “name”. Therefore, the next step is to click on the inscription above “Create a template”.
    Нет-шаблона Thus, the plugin scans our theme and all the inscriptions that we declared in the theme using the functions in paragraph 1 will be output to a file in .pot format – this will be a template for translations without the translation itself.
  7. Next, we create the actual translation of the records. Click on the inscription “New language”.Новый язык
  8. In this window, we set the language to which we will translate and the place where we will save the translation file (In my case, we translate the topic into Ukrainian and save the file to the languages folder).Настройки языкаHaving finished with this, click on the “Start translation” button below. As a result of this step, we will have two translation files in .po and .mo format.
  9. Next we find the inscriptions that we will translate. In the area with a list of inscriptions, find the one you need and click on it. We will have two fields below available: the first is how the inscription is displayed in the topic, the second is how this inscription should be displayed in translation. Actually, in the second field, we enter the translation we need and save the changes. We translate all other inscriptions in the same way.
    перевод
  10. The final touch is to download the theme translation (.mo) file. We do this with the load_theme_textdomain() function which will be used in the after_setup_theme hook. This code is placed in the theme’s functions.php file:
    function my_theme_setup()
    {
    load_theme_textdomain('my-site', get_template_directory() . '/languages');
    }
    add_action('after_setup_theme', 'my_theme_setup');

Other articles

Position sticky doesn’t work position: sticky

Position sticky doesn’t work

Position sticky doesn’t work

Position sticky doesn’t work – to my surprise this is a fairly common request that I myself have encountered in my time. Sticky is a pretty simple and versatile solution for placing sticky blocks on a page. At the very least, it doesn’t require you to do a decent amount of javascript code, which did […]

How to import a large MySQL database into OpenServer

How to import a large MySQL database into OpenServer

How to import a large MySQL database into OpenServer

Perhaps everyone is used to importing a database using phpMyAdmin. But this platform has a limit on the weight of the file that can be uploaded. So if the database dump exceeds this quota, you can’t do it through phpMyAdmin. Today I’m going to show an alternative way to load the database – through the […]