The idea of making XML documents in the first place is easy to do. Just to see that XML is inefficient
Another is the different template, but there is also a small problem, some words such as the time hint is uncertain, and may be minute, day. It may also be plural plus s.
Well, make an array, and the array will have to be made into a variable in the PHP file, and it's hard to expand (I know what I think it is).
The final form of txt text file, also for such efficiency concerns, open files, search strings, intercept the string of these, fortunately, the last run a bit, the general machine about 0.0004 seconds, which I am surprised to think will be very slow, after all, to call many times.
All right, on the code.
Copy Code code as follows:
Class language
{
Static $lanObject;
Public $type; Unit, Dashboard, menu, and other
Public $lan; Language
Private $special; The common in the file
Private Function __construct ()
{
if (Isset ($_get[' hl ')) | | | isset ($_post[' hl '))
{
Switch (isset ($_get[' hl '))? $_get[' hl ']:$_post[' HL ']
{
Case ' en ':
$this->lan = ' en ';
Case ' en ':
$this->lan = ' en ';
Case ' all ':
$this->lan = ' all ';
Default
$this->error ();
}
}
Else
$this->lan = isset ($_cookie[' hl '])? $_cookie[' HL ']: ' en ';
}
public static function GetObject ()
{
if (!) ( Self:: $lanObject instanceof Self))
Self:: $lanObject = new language ();
Return self:: $lanObject;
}
Public Function LTO ($key)//$key is 中文版
{
if ($this->lan!== ' en ')
return $key;
if (Empty ($this->special))//If the $special is null
{
if (Isset ($this->type))
$this->special = file_get_contents ($this->type. TXT ');
Else
return $key;
}
echo $this->search ($key);
}
Private Function Search ($searchTozh)//PHP String
{
$key _start = Strpos ($this->special, $searchTozh);
$key _end = Strpos ($this->special, ", $key _start);
$len _str = strlen ($searchTozh);
$for _sub = $key _start + $len _str + 1;
Return substr ($this->special, $for _sub, $key _end-$for _sub);
}
}
Strpos (); is to find the first occurrence of the string, such as ' Wo ' in ' Hello World ', the return value is 6
SUBSTR (); is part of the Intercept string
Next is the code that was added when debugging
Copy Code code as follows:
$la = Language::getobject ();
$la->type = ' unit ';
$la->lto (' min ');
Echo ' <br/> ';
$la->lto (' hello ');
LTO (English to be translated in this area);
The content format of the Unit.txt file is
hello-Hello min-small minute-minutes minutes-minutes
$special designed to be global is also the thought of more than one call to LTO (), if the repeated loading of the file is too wasteful performance.
$type Design for the public is to take into account the loading of the file efficiency problems, and sometimes do not need to show these days ago, so it is better to use these types of separation, such as the special responsibility for menu translation Menu.txt, there are specialized for the operation, such as delete, the text of the translation of TXT. This allows you to freely set the text to load
Language can also be set freely.
Well, the program can also be improved, I did not set the $lan according to the client language in the HTTP request.