Finaly u can add multilanguage support not only for the interface (
http://www.4homepages.de/forum/index.php?topic=4743.0 ) but also for any text, such as image names, description, anything. Since this is not "real" MOD, I will only show an example how to add this support to image names and description. (basicaly this is more for developers and who know little bit PHP and 4images code structure)
Q: How it works?
A: In the text u'll need add [language] (i.e. [english] or [deutsch]).
Yes, that's it, no [/language] tag requered.
- Everything that is followed after [language] will be used when this language was selected.
- If a text starts with something other then [language] tag and no [language] tag was matched with current language, then the text that can be found before FIRST [language] tag will be showed.
- If a text starts with a [language] tag, and none of the [language] tags are matching with current language, the script will try find [language] tag with 4images default language, if none was found, it will show text as is, with all [] tags.
- If u add [/language] (closing tag) and then add some text after it, that text will be ignored.
Try and see diffirent situations that could be and how this script handle them:
http://gallery.vano.org/multilang.phpHere is a little example.
Updated on 08-07-03 2:50PM (EST) -------- [ Installation ] ----------
Step 1 Open
global.php Find:
$config['language_dir_default'] = $config['language_dir'];
Insert
below:
$handle = opendir(ROOT_PATH."lang");
$config['language_list_array'] = array();
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/$folder") && $folder != "." && $folder != "..") {
$config['language_list_array'][] = $folder;
}
}
closedir($handle);
$config['language_list'] = "(".implode("|", $config['language_list_array']).")";
Step 2 Open
includes/functions.php Insert at the end,
above closing
?>function multilang($text, $show_first = 0, $remove = 0){
global $config;
preg_match("#\[".$config['language_dir']."\](.*)(\[\/?".$config['language_list']."\]|$)#iDUs", $text, $match);
if (!empty($match[1])) {
return $match[1];
}
preg_match("#^(.*)\[".$config['language_list']."\]#iDUs", $text, $match);
if (!empty($match[1])) {
return $match[1];
}
preg_match("#\[".$config['language_dir_default']."\](.*)(\[\/?".$config['language_list']."\]|$)#iDUs", $text, $match);
if (!empty($match[1])) {
return $match[1];
}
if ($show_first) {
preg_match("#\[".$config['language_list']."\](.*)(\[\/?".$config['language_list']."\]|$)#iDUs", $text, $match);
if (!empty($match[2])) {
return $match[2];
}
}
if ($remove) {
return preg_replace("#\[".$config['language_list']."\](.*)#iDs", "", $text);
}
return $text;
}
function multilang_tag_remove($text){
global $config;
return preg_replace("#\[\/?".$config['language_list']."\]#iDUs", " ", $text);
}
Added 05-11-2005Step 3 (optional)
With this step you'll be able add multilanguage support in date format.Open
global.phpFind:
include(ROOT_PATH.'includes/functions.php');
Insert
below:
$config['date_format'] = multilang($config['date_format']);
$config['time_format'] = multilang($config['time_format']);
Step 3.1Open
includes/functions.phpFind:
return date($format, $timestamp + (3600 * $timezone_offset));
Insert
above:
global $lang;
if (isset($lang['date_translate']) && !empty($lang['date_translate']))
return strtr(date($format, $timestamp + (3600 * $timezone_offset)), $lang['date_translate']);
Step 3.1 (optional, needed only if you want use names of month/weekday)Open
lang/<your language>/main.phpAt the end,
above closing
?> insert:
$lang['date_translate'] = array(
"Monday" => "Понедельник",
"Tuesday" => "Вторник",
"Wednesday" => "Среда",
"Thursday" => "Четверг",
"Friday" => "Пятница",
"Saturday" => "Суббота",
"Sunday" => "Воскресенье",
"Mon" => "Пон",
"Tue" => "Втр",
"Wed" => "Срд",
"Thr" => "Чтв",
"Fri" => "Птн",
"Sat" => "Суб",
"Sun" => "Вос",
"January" => "Января",
"February" => "Февраля",
"March" => "Марта",
"April" => "Апреля",
"May" => "Мая",
"June" => "Июня",
"July" => "Июля",
"August" => "Августа",
"September" => "Сентября",
"October" => "Октября",
"November" => "Ноября",
"December" => "Декабря",
"Jan" => "Янв",
"Feb" => "Фев",
"Mar" => "Мар",
"Apr" => "Апр",
"May" => "Май",
"Jun" => "Июн",
"Jul" => "Июл",
"Aug" => "Авг",
"Sep" => "Сен",
"Oct" => "Окт",
"Nov" => "Ноя",
"Dec" => "Дек",
"AM" => "AM",
"PM" => "PM",
"am" => "am",
"pm" => "pm",
);
Translate right side of the array (after
=>) to your langauge. DO NOT TOUCH LEFT PART, WHICH MUST STAY IN ENGLISH
Step 3.3Go to you ACP (Admin Control Panel) -> Settings and add
[<your langauge>] tags to "Date" and "Time" format field.
For example in USA the date format is: month, day, year, (10.25.2005) in Europe is day, month, year (25.10.2005) so, the string in "Date" field should be:
[english]m.d.Y[russian]d.m.Y
For more info about the language tags, read below. And for more info about date format you can find
hereThis is it.
Now, let me show u how to use it:
You'll need send your text through
multilang() function (i.e.
echo multilang($text); this will print result after processing text from
$text variable)
Added two keys:
multilang($text, $show_first, $remove) $show_first = 1 would use first matching [language] as default, instead of showing entire text (case 4 and 5 in the example)
$remove = 1 would remove everything, instead of showing entire text (case 4 and 5 in the example)
Practical example:
-------- Image name and description ------------
Open
includes/functions.phpFind:
"image_name" => $image_row['image_name'],
"image_description" => $description,
Replace with:
"image_name" => multilang($image_row['image_name']),
"image_description" => multilang($description),
Important! this is MUST do, otherwise your keywords will be messed up!
Open
admin/images.php Find:
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);
Replace with:
$search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column]));
Find:
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]);
Replace with:
$search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]));
Open
member.php Find TWO (2) times:
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);
Replace BOTH with:
$search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column]));
P.S. I will updating this post if I think of something else
P.P.S. in the attached file is provided saved google cached page of the original post with a few replys and some extra code.