📜 ⬆️ ⬇️

SLI - fast creation of multilingual on the site

Good day Khabrachelovek! I publish a post at the request of the programmer ganjar . He helped our online store to quickly make multilingual SLI, which will be discussed. In the comments, he will answer all questions.

SLI (Site Language Injection) - PHP script to quickly create multilingual website.

Probably every web developer at least once had to create multilingual content on the site. And everyone who has done this is well aware of the difficulties, as well as the amount of time that needs to be “killed” for the boring work of accomplishing the task.
')
Before you start creating your solution, I read a lot of articles about how different programmers solved the problem of multilingualism, and in none of them did I find a universal way to solve it. Under each new project, it was necessary to re-use the “wrapper” functions for text and links, create tables with translations, and modernize the admin panel to localize the content. I did not like any of the described options, because even the creation of small sites took a lot of time. Initially, it was necessary to implement the functionality for the work of saving / selecting the translated texts, modify the admin area for localization, and then wrap the entire text and links in the function for localizing content.

The task that was required to solve:


The solution of the tasks:

To connect the system, we use the setting in the .htaccess file “php_value auto_prepend_file”. Thus, we will be able to connect the translation system without interfering with the source of the site.

The system is connected. It now remains to get involved in the work so that “nothing has changed” for the site to function:

  1. We intercept data from the address bar. We check them for the presence of a language alias, where you can see which language is currently selected. If a language is selected, remove the language alias from REQUEST_URI so that “nothing has changed” in the work of the site itself.
  2. We hang the handler for the return of content: ob_start ('SLITranslate :: autoInit');
  3. Content received by the handler is parsed (taking into account the system settings), pulling the text and attributes that need to be translated.
  4. We translate the array into indexes for database search (all symbols that are not needed for translation are removed from the text).
  5. In one request, we pull out all the data in the required language from the database.
  6. We replace the original text with the translated one.
  7. Add to all local links, action in forms and JavaSctipt-nd location.href language alias. This is necessary so that when using the site a person does not return to the version without the selected language.
  8. We give the user a localized page.

I will answer in advance frequently asked questions:



More information about setting up and working with the program in the documentation: http://sli.su/documentation/
You can download the program on the official website: http://sli.su/download/
For those who are too lazy to enter e-mail (to receive updates), direct link: http://sli.su/files/models/Release/2/file/sli_ver1_0.zip

GitHub: https://github.com/ganjar/sli

Source: https://habr.com/ru/post/195468/


All Articles