Author Topic: [MOD] Multi-Language support for any text (updated 05-11-2005)  (Read 214955 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
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.php

Here is a little example.

Updated on 08-07-03 2:50PM (EST)

-------- [ Installation ] ----------
Step 1
Open global.php
Find:
Code: [Select]
$config['language_dir_default'] = $config['language_dir'];

Insert below:
Code: [Select]
$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 ?>
Code: [Select]
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-2005
Step 3 (optional)
With this step you'll be able add multilanguage support in date format.
Open global.php
Find:
Code: [Select]
include(ROOT_PATH.'includes/functions.php');Insert below:
Code: [Select]
$config['date_format'] = multilang($config['date_format']);
$config['time_format'] = multilang($config['time_format']);

Step 3.1
Open includes/functions.php
Find:
Code: [Select]
  return date($format, $timestamp + (3600 * $timezone_offset));Insert above:
Code: [Select]
  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.php
At the end, above closing ?> insert:
Code: [Select]
$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.3
Go 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:
Quote
[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 here

This 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.php
Find:
Code: [Select]
    "image_name" => $image_row['image_name'],
    "image_description" => $description,


Replace with:
Code: [Select]
    "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:
Code: [Select]
          $search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);

Replace with:
Code: [Select]
          $search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column]));


Find:
Code: [Select]
              $search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]);

Replace with:
Code: [Select]
              $search_words[$image_column] = multilang_tag_remove(stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]));



Open member.php
Find TWO (2) times:
Code: [Select]
          $search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);

Replace BOTH with:
Code: [Select]
          $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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline abdoh2010

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Racing 4 Education
Re: [MOD] Multi-Language support for any text
« Reply #1 on: April 04, 2005, 11:30:50 AM »
is this like to write discribtion two time for english languge and the other languge ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Multi-Language support for any text
« Reply #2 on: April 04, 2005, 02:06:54 PM »
yes
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline abdoh2010

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Racing 4 Education
Re: [MOD] Multi-Language support for any text
« Reply #3 on: April 04, 2005, 02:41:09 PM »
that is great and usefal for a website that is just start using 4images but if we are talking about a website witch have more that 1000 item in his gallary than that will need to thing twice before using it
becouse he is ovisly will rewrite all the discribtion for all the items he have and that is had work even if it woth it

for me, i am planing to rewite all the discribtion for my 4images becuse my old discrbtion is not usefal and that is good time for me to use your MOD

thank you for doing what you do for us and for 4images

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Multi-Language support for any text
« Reply #4 on: April 04, 2005, 02:56:39 PM »
that is great and usefal for a website that is just start using 4images but if we are talking about a website witch have more that 1000 item in his gallary than that will need to thing twice before using it
no, u dont have to, unless u want use two or more languages.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline abdoh2010

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Racing 4 Education
Re: [MOD] Multi-Language support for any text
« Reply #5 on: April 04, 2005, 03:06:49 PM »
Yes, I am orady using two languages, Arabic and English

I want to say another thing
Your MOD will increase the SEO for any 4images using your MOD
Double description and double keywords for the search engine
That's cool

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: [MOD] Multi-Language support for any text
« Reply #6 on: April 17, 2005, 05:19:57 AM »
Hi Vano,
I did install your mode Multilang support for any text. Everything works fine, but I would like to use also for Simple News Publishing and that’s why I have changed the code in news.php (see below)

Code: [Select]
$site_template->register_vars(array(
    "news_title" => "<b>".multilang($news_row[$i]['news_title'])."</b>".sprintf($lang['news_posted_by'], $news_row[$i]['user_name'], format_date($config['date_format']." ".$config['time_format'], $news_row[$i]['news_date'])),
"news_text" =>multilang(format_text($news_row[$i]['news_text'], ((isset($config['news_html']))?$config['news_html']:0), 0, ((isset($config['news_bbcode']))?$config['news_bbcode']:1), ((isset($config['news_bbcodeimg']))?$config['news_bbcodeimg']:1))),
"admin_links" => $admin_links,
));

mode multilang works, but bbcode and html code stopped working. It appears as text only. Where did I make the mistake? Could someone please help me out so I can get them both working (bbcode and htmlcode)???
Thanks!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Multi-Language support for any text
« Reply #7 on: April 17, 2005, 05:31:19 AM »
and what if u exchange possitions of miltilang and format_text:
instead of
Quote
multilang(format_text(
do it this way:
Quote
format_text(multilang(
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: [MOD] Multi-Language support for any text
« Reply #8 on: April 17, 2005, 05:45:26 AM »
and what if u exchange possitions of miltilang and format_text:
instead of
Quote
multilang(format_text(
do it this way:
Quote
format_text(multilang(

I am trying now but no change  :cry:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Multi-Language support for any text
« Reply #9 on: April 17, 2005, 05:47:09 AM »
ok, how bbcode doesnt work? do u see the tags or u dont?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: [MOD] Multi-Language support for any text
« Reply #10 on: April 17, 2005, 05:52:30 AM »
ok, how bbcode doesnt work? do u see the tags or u dont?

I have problem with hyperlink and image bbcode.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Multi-Language support for any text
« Reply #11 on: April 17, 2005, 05:57:24 AM »
WHAT PROBLEM? would u describe it please? I'm not a psychic to read you mind.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: [MOD] Multi-Language support for any text
« Reply #12 on: April 17, 2005, 06:14:34 AM »
WHAT PROBLEM? would u describe it please? I'm not a psychic to read you mind.

I want too add picture into text but picture doesn't show in text and the same with hyperlink.

Offline demontech

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: [MOD] Multi-Language support for any text
« Reply #13 on: April 22, 2005, 06:00:34 PM »
Hello Vano,

maybe i'm stupid but i don't understand in witch file and how i shoud write to explain for the gallery that
lattvia=lettland in swedish. And in this case is for my catigories i want to change to the swedish name when someone choose "swedish" on www.demontech.net

Offline Sheon

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: [MOD] Multi-Language support for any text
« Reply #14 on: June 05, 2005, 01:14:07 PM »
How use multi-lang with categories names and description??? I try change categories.php, but it dont work.