📜 ⬆️ ⬇️

My implementation of interface localization in PHP

The current state of affairs is such that it is very often necessary to implement multilingualism in one’s work. It seems that the techniques are well described and there should be no problems, but I decided to go my own way.

I just want to make a mistake - to that option, which is described below, I came by myself and this applies only to captions / static content. Perhaps there is such an implementation, but I am not familiar with it.

At the moment, I know of such implementations:
Now the description of my version.
There is a table of inscriptions (phraze_id, language_id, value) in which all the static content of the site is stored, as well as a table of languages ​​(language_id, title). These are the tables with which we will work. Now consider the template folder. There is a folder, suppose users in which source templates are stored (templates / users) and there is a temporary shalons folder (tmp / users). Now the most interesting moment. In the source templates in place of the inscriptions we write something like [phraze {site_title}]. When changing the inscriptions in the admin or cron (this is already a private implementation), I replicate the templates (replace [phraze {site_title}] with the “Site Header”) and get the modified template in the tmp / users / ru or tmp / users / en folder depending from the tongue. Here you just have to “say” smarty where to get the templates from. This implementation allows you to avoid the cost of the constant function call / get out of the database and do it only on a specific event.

')

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


All Articles