E
E
Evgeny Kalibrov2015-02-12 11:49:07
CMS
Evgeny Kalibrov, 2015-02-12 11:49:07

How to implement php and javascript localization?

There is a self-written CMS, all Russian phrases, button names, messages, etc. now hardwired into the code, both php and javascript. At the moment, I set the task of making normal localization packs, so I want to choose some kind of universal method suitable for both php and javascript. Please tell me the implementation mechanism or specific libraries for these purposes.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Aleksei Podgaev, 2015-02-12
@rework

I don't know about libraries.
I do it simply: I put all the texts in an .ini or .json file. This file is then read by the php script.
1. For the .ini file, there is a directly special function that reads the file and makes an associative array out of it. This array with texts (wrapped in a class, of course) is used both by the php script itself and in the frontend - it is inserted as json into a global variable at the very beginning of the page, before all other javascripts are loaded.
2. There should be no problems with the json file either. It's a little harder to read in php, but you don't have to worry about inserting it into the page - you can then load it with an ajax request when the frontend loads and starts working.

V
Vladimir Rodkin, 2015-02-12
@VovanR

As they write above - use Gettext
There is a cross-platform program for working with Poedit localization files . Used in Django, CakePHP, WordPress
For JS, you can generate json from the information received, for example. Django, for example, provides a global function gettextand ngettext, which can be used in scripts themselves.

G
Gluck Virtualen, 2015-02-14
@gluck59

Use a templating engine like Smarty or something similar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question