N
N
nepster-web2014-02-28 17:44:02
PHP
nepster-web, 2014-02-28 17:44:02

What is the best way to implement multilingualism on the site?

The following question arose, it is necessary to work out the structure of the site in several languages.
Let's immediately move away from the idea of ​​​​squinting and hooking on all sorts of Google translators and the like.
There are several issues in the implementation of this case:
1) For example, we have a table "news" project news:

news_id
title
news_short
news_full
status

And for example, we work with several languages ​​on the site (Russian, English, French)
How would it be better to create news on the site by the administrator? That is, the administrator must do triple work, namely, write content 3 times for each language.
Option one:
Duplicate fields in the table:
title_ru
title_en
news_short_en
news_full_en
news_short_ru
news_full_ru
...

Option two:
The "news" table contains the default language, Russian, and there is another table in which there are translations into other languages.
tr_id
lang
title
news_short
news_full
news_id

And for example, if our site is viewed in English, then we take the data from the translation table by the news_id and lang attributes.
Which option is better? Can someone recommend theirs?
Question number 2
What about the content? For example, we have template files: news_full.tpl, news_short.tpl, etc...
Would it be optimal to create folders with languages ​​in each module in views and duplicate view files only with different translations:
views
    - ru
      - news_full.tpl
      - news_short.tpl
    - en
      - news_full.tpl
      - news_short.tpl
...

And the last question number 3
For example, our site works entirely on ajax and the server gives answers, well, for example, with an error:
Wrong password
So here, in any case, we have a translation table, but how best to arrange it? Each error has its own code (for example, ERROR_WRONG_PASSWORD) and using this code, based on the desired language, we get the translation?
Or you can use language files and store, for example, packages like this: starting from the default language:
array(
  'Неверный пароль' => 'Wrong Password'
 )

Please share your tips.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Aleksei Podgaev, 2014-02-28
@nepster-web

1) of course the second option. every time you add a new language to remake the table - not comme il faut.
2) Do your templates for different languages ​​differ visually? I usually make one template, and put all the standard texts (button labels, etc.) into language files/classes. Those. I actually have one template, it's just that in addition to the actual content of the article, it also goes through the stage of inserting all the standard texts from the current language file.
3) The same as in question number 2. I make my own file for each language, which I load before I start working with the view. From it I take all the text constants, whether they are labels on buttons or error messages. From base at an error only the code comes. According to this code, I take the text from a text file and send it to the client.

V
victimofbrainlessness, 2014-02-28
@victimofbrainlessness

#2-3
gettext po, i18n
stackoverflow.com/questions/2319060/using-php-gett...
blog.lingohub.com/developers/2013/07/php-internati...

A
antimind, 2014-03-01
@antimind

See how multilanguage is implemented in prestashop. In my opinion, a very good solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question