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 should easily connect to any site written in php, without interfering with the source code of the system.
- No “wrappers”. The system itself must understand what links need to be localized, what text is required to be translated into the desired language version.
- The installation and configuration process should take a minimum of effort.
- The localized version should be indexed by search engines.
- There should be a comfortable admin panel with the search for the page address, the original and the translated texts.
- The system should not have restrictions on the number of languages.
- The system should work as fast as possible.
- Text that differs only in characters must be translated 1 time. For example: “bought 10 times” and “bought> 20 times” should be translated 1 time.
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:
- 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.
- We hang the handler for the return of content: ob_start ('SLITranslate :: autoInit');
- Content received by the handler is parsed (taking into account the system settings), pulling the text and attributes that need to be translated.
- We translate the array into indexes for database search (all symbols that are not needed for translation are removed from the text).
- In one request, we pull out all the data in the required language from the database.
- We replace the original text with the translated one.
- 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.
- We give the user a localized page.
I will answer in advance frequently asked questions:- “How to translate inscriptions in a picture?” - create pictures in different languages, and then create a replacement in the “variables” module. Enter the address of the image in the “original” field, enter the address of the image with a localized label for each language used in the translation fields.
- “What should I do if I have a block with comments on the site (any constantly updated content that is not of special importance) that I don’t want to translate?” - wrap this content in comments that will serve as a “pointer” for the translator. Content that is inside the comments, the content will be ignored and will not fall on the translation.
- “ I have many pages on the site that do not need to be translated. "- in the parser settings there is an item" Ignore addresses ". We write down the necessary pages there.
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.zipGitHub:
https://github.com/ganjar/sli