Website localization

0 like 0 dislike
6 views
The task was to translate the site into many languages of the world. First comes to mind is this: create a static class in which a recorded language identifier and which contains a function that returns text based on the passed argument (the path to this text). Yourself localization files contain an array of texts. Let's say you want to localize the settings page, the field "username", pass to the function the way of Settings/UserName and it returns the value $localize["Settings"]["UserName"];

This approach raises several questions:
1. How to effectively store these locale arrays: in php files and connect (include_once) a specific file depending on the language or json using the memcache and choose the right one?
2. How to determine the system user language (regardless of OS)?
3. Perhaps there is a more effective approach?

PS As the variant looks modification date of the php script, and if it is newer than the one in memcache, the array is serialized and placed in memcache. Or better to serialize localization files before uploading them to the server?
by | 6 views

7 Answers

0 like 0 dislike
by
0 like 0 dislike
1. How to effectively store these locale arrays: in php files and connect (include_once) a specific file depending on the language or json using the memcache and choose the right one?
\r
In my MySQL database, it is most convenient in this case.
\r
2. How to determine the system user language (regardless of OS)?
\r
As far as I know — no way. Usually on sites full of the language is standard, but you can switch to the other.
\r
3. Perhaps there is a more effective approach?
\r
If to write from zero, then effectively I do not know if the Zend Framework, there are special classes has been developed.
by
0 like 0 dislike
I recommend to look at the implementation of the framework Kohana.
\rgithub.com/kohana/core/blob/3.0/develop/classes/kohana/i18n.php
\rgithub.com/kohana/core/blob/3.0/develop/base.php
\r
In principle, not difficult to understand, I think.
In the application, for example, write:
\r
//setting the language I18n::$lang = 'EN-us' //for example //need to translate and write for example __('hello :username', array(':username' => $username)); 

And create, for example, file ru-ru.php (class Kohana_I18n written to look for this file in accordance with its architecture — this moment, and You have to edit, if you want to use) with the contents:
\r
<?php\r\rreturn array(\r'hello :username' => 'Hi, :username!', ); 
by
0 like 0 dislike
1. Recently habré was an article about optimizing PHP. Faster save the file connected. Because the toe can be generated from the admin panel. So it's convenient.
2. Either in IPS (in the Internet a lot of location-based databases), or by the browser headers (Accept-Language).
3. From scratch so westree just to fit in, I guess. You can certainly recycle page to replace the line. words. But It will be. probably, slowly. Although caching and so on...
by
0 like 0 dislike
In the headers of the browser which language? Browser or OS?
\r
I have the Ukrainian language in Ubuntu and piratee, Facebook, Vkontakte automatically set the Ukrainian language. And in the Russian Vendian — appropriately, everywhere Russian. How do they do it?
by
0 like 0 dislike
It's true not yet implemented, but there is an idea to make a lang-file on the fly, i.e., connects the script that checks for all occurrences of Russian words (originally the interface is written in Russian) and as bypass creates a linguistic map, by analogy
$localize["Settings"]["UserName"]; in the file, for example eng.php, then you will only need to fill out as you work. Of course all this needs to be done on the UTF.
\r
Pros
— no need to give up with the lang file and set variables in php files
— you can connect an unlimited number of languages
\r
Cons
— decrease speed
\r
Thoughts on the course
\r
With speed you can play and create even a serialized array with reference to a specific php (all of the editing window, etc.), the set of language variables in these files is restricted to the standard set.
\r
Language phrase will need to take in tag span id="lang" to increase speed.
\r
PS While writing, I have read the above comments and realized that it is already in Zend_Translate stole my idea :)
by
0 like 0 dislike
Translation on the fly, it is better of course result in a file write, not to spend resources every time.
\r
\r
function translate($text) { $text = urlencode(win_utf8($text)); $domain = "ajax.googleapis.com"; $result="; $fp = fsockopen($domain, 80, $errno, $errstr); if (!$fp) { return exit("Error connecting to server translator"); } else { fputs($fp, "GET /ajax/services/language/translate?v=1.0&q=".$text."&langpair=EN%7Cen&callback=foo&context=bar HTTP/1.0\\r\"); fputs($fp, "Host: $domain\\r\"); fputs($fp, "Connection: close\\r\\\r\"); while (!feof($fp)) { $result.=fgets($fp, 1000); } fclose($fp); } preg_match('|"translatedText":"(.*?)"|is', $result, $locale); return $locale[1]; } 
by
110,608 questions
257,186 answers
0 comments
28,648 users