This is group project from SLL - idea, Jan - the code, me - adoptation for 4images and finish up*
Finaly u can add multilanguage support not only for the interface (
http://4homepages.de/forum/viewtopic.php?t=4743 ) 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://come.no-ip.com/multilang.phpHere is a little example.
Updated on 08-07-03 2:50PM (EST)
------- Installation ----------
Step 1.
Open /global.php
Find:
Code:
$config['language_dir_default'] = $config['language_dir'];
Add after:
Code:
$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
Add at the end, just before closing ?>
Code:
function multilang($text, $show_first = 0, $remove = 0){
global $config;
preg_match("#\[".$config['language_dir']."\](.*)(\[\/?".$config['language_list']."\]|$)#Uim", $text, $match);
if (!empty($match[1])) {
return $match[1];
}
preg_match("#^(.*)\[".$config['language_list']."\]#Uim", $text, $match);
if (!empty($match[1])) {
return $match[1];
}
preg_match("#\[".$config['language_dir_default']."\](.*)(\[\/?".$config['language_list']."\]|$)#Uim", $text, $match);
if (!empty($match[1])) {
return $match[1];
}
if ($show_first) {
preg_match("#\[".$config['language_list']."\](.*)(\[\/?".$config['language_list']."\]|$)#Uim", $text, $match);
if (!empty($match[2])) {
return $match[2];
}
}
if ($remove) {
return preg_replace("#\[".$config['language_list']."\](.*)#im", "", $text);
}
return $text;
}
function multilang_tag_remove($text){
global $config;
return preg_replace("#\[\/?".$config['language_list']."\]#i", " ", $text);
}
This is it.
Now, let me show u how to use it:
U'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.php find:
Code:
"image_name" => $image_row['image_name'],
"image_description" => $description,
replace with:
Code:
"image_name" => multilang($image_row['image_name']),
"image_description" => multilang($description),
Important! this is MUST do, other wise your keywords will be messed up!
Open /admin/images.php
Find:
Code:
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);
Replace with:
Code:
$search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column]));
Find:
Code:
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]);
Replace with:
Code:
$search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]));
Open /member.php
Find TWO TIMES:
Code:
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);
Replace BOTH with:
Code:
$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 Wink
_________________
Please read before posting:
Using forum guide
FAQ
Last edited by V@no on 12.08.2003, 22:47; edited 8 times in total