P
P
Petr Flaks2015-03-14 20:46:42
PHP
Petr Flaks, 2015-03-14 20:46:42

How to do website localization?

Hello!
So far, I'm just learning and creating a site that I would like to have in two languages: in Russian and English. Since I'm just learning, I would not want to resort to ready-made solutions (like Gettext) yet - personal experience, it seems to me, will be useful, at least in the first project.
This is done through the function below. If there is no English text, then Russian will be displayed; and if Russian is also missing, then an error will be displayed:

function __locale($class) {
    if (isset($locale[$class][$_SESSION['language']]) && strlen($locale[$class][$_SESSION['language']]) > 0) {
      return $locale[$class][$_SESSION['language']];
    }
    elseif (isset($locale[$class][0]) && strlen($locale[$class][0]) > 0) {
      return $locale[$class][0];
    }
    else { return 'locale error '.$class; 		}
  }

Where $locale is a variable that is in the localization file:
$locale = array(
  'index.menu.home'									=> array('Главная', 'Home'),
  'index.menu.regi'									=> array('Регистрация', 'Registration'),
  'index.menu.login'									=> array('Вход', 'Login')
// и так далее
);

At first I thought to do it through the database, but it seemed to me that this could affect the site loading speed. Yes, and on Habré I once read in an article that talked about optimizing the speed of loading a site.
The language is hammered into the session, and it is determined through the browser header.
So. I apologize for the large amount of text and move on to the questions:
  1. How good is my implementation? What should be changed before it's too late? I'm very afraid to do something wrong and in the future to rewrite all this ...
  2. How will this affect search engines? Will English-speaking users see a site in English in the search results , and Russian-speaking users in Russian?

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2015-03-14
@neluzhin

https://support.google.com/webmasters/answer/18219...

O
olamedia., 2015-03-14
@w999d

read
php.net/gettext
php.net/setlocale
// didn't want to resort to ready-made solutions (like Gettext)
uh, didn't notice) but from personal experience I'll tell you - if you write your own, it will take a lot of time, but there will be little sense. Do you know the features of all the languages ​​of the world? it means that the solution will be tailored only to a couple of languages ​​\u200b\u200bknown to you, and you will fill the sea with cones.
regarding the language from the browser - it is better to offer a transition to a version with this language, and make the site available to everyone in both versions. it’s more humane (for example, I have a system in English) and friendlier to bots.
Well, it’s worth separating the interface and content. the content is likely to differ more than it seems, so it may be convenient not to translate each line in the database / start fields, but to use a separate database, or filter records by a separate field with a locale mark.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question