• [MOD] Language select 4 0 5 1
Currently:  

Author Topic: [MOD] Language select  (Read 256773 times)

0 Members and 2 Guests 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 :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« on: March 21, 2003, 11:14:14 PM »
*Works with all 4images versions*

This MOD was created by Jan, but never "officialy" was published:
http://www.4homepages.de/forum/index.php?topic=3351.0
(and I'm getting PMs very often with questions how did I do that.)

------ Overview -------------------
With this MOD your site visitors will be able chose language for the interface.

There are two versions of this MOD:

A: Using dropdown menu
B: Using images/text as links


----- Installation -------------------
Step 1.

--- Version A ---

Open /includes/page_header.php
Find:
Code: [Select]
$site_template->register_vars(array(
  "media_url" => MEDIA_PATH,
  "thumb_url" => THUMB_PATH,
Add before:
Code: [Select]
$query_string = '';
if (!empty($HTTP_GET_VARS)) {
  foreach ($HTTP_GET_VARS as $key => $val) {
    if ($key != "l") {
      $query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
    }
  }
}
// We add the session id with "&" not "&"
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');

// Now we can better remove the "l" parameter
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);

// We replace "&" with "&" to make it valid XHTML
$lang_url = str_replace("&", "&", $lang_url);

$lang_select  = "<form action=\"".$lang_url."\" method=\"post\">\n";
$lang_select .= "<select class=\"select\" name=\"l\" onChange=\"submit()\">\n";

// Now we open the "lang" folder, read out all available languages
// and add it as options to the dropdown.
$handle = opendir(ROOT_PATH."lang");

while ($folder = @readdir($handle)) {

  if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {

    $lang_select .= "<option value=\"".$folder."\"";

    // If the folder name matches the current language,
    // show the option as selected
    if ($folder == $config['language_dir']) {
      $lang_select .= " selected=\"selected\"";
    }

    $lang_select .= ">".$folder."</option>\n";
  }
}

$lang_select .= "</select>\n</form>";

// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);


--- Version B ---

Open /includes/page_header.php
Find:Find:
Code: [Select]
$site_template->register_vars(array(
  "media_url" => MEDIA_PATH,
  "thumb_url" => THUMB_PATH,
Add before:
Code: [Select]
$query_string = '';
if (!empty($HTTP_GET_VARS)) {
  foreach ($HTTP_GET_VARS as $key => $val) {
    if ($key != "l") {
      $query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
    }
  }
}
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
$lang_url = preg_replace("'&(amp|#38);'i", "&", $lang_url);
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&amp;", $lang_url);
$handle = opendir(ROOT_PATH."lang");
$lang_select = "";
while ($folder = @readdir($handle)) {
  if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
    if ($folder != $config['language_dir']) {
      $lang_select .= "<a class=\"lang\" href=\"".$lang_url.(preg_match("/english/i",$folder) ? "" : ((preg_match("/\?/", $lang_url) ? "&" : "?")."l=".$folder))."\" onMouseOver=\"(window.status='$folder'); return true\" onMouseOut=\"window.status=''; return true\"><img src=\"".TEMPLATE_PATH."/images/".$folder.".gif\" border=\"0\" alt=\"".$folder."\"></a>&nbsp;";
    }else{
    $lang_select .= "<img src=\"".TEMPLATE_PATH."/images/".$folder."2.gif\" border=\"0\" alt=\"".$folder."\">&nbsp;";
    }
  }
}
// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);


Step 2. (for both versions)

Open a temlate where u want your language selector be showed (i.e. /templates/<yourtemplate>/home.html) and add this tag:
{lang_select}



------- Final -----------------------
This script scans /lang/ folder and if it finds any folders inside it, it will add them in the selection.


------- Note ------------------------
Version B is set to use images (I use it on my site)
the filenames of images must be this format:
language_folder_name.gif - for not currently selected languages
and
language_folder_name2.gif - for currently selected language


This version is based on sessions, that means as soon as browser is closed, the language sellection will be lost.
If u wish have cookies based version, so it would "remmember" the last selected language, then u will need apply these changes:
http://www.4homepages.de/forum/index.php?topic=4743.msg31555#msg31555
« Last Edit: March 26, 2006, 07:10:06 PM by V@no »
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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
It didn't work out with English version choice?
« Reply #1 on: May 11, 2003, 05:37:28 AM »
I tried your mod B method, It works fine with my Chinese version, Taiwan version, but didn't work out with the third choice : English version, could tell me how to correct it?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« Reply #2 on: May 11, 2003, 06:09:07 AM »
try again the code in page_header.php
It displayed some smile emoticon inside the code, I just turned smiles off, should be fine now.
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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
[MOD] Language select
« Reply #3 on: May 11, 2003, 07:01:36 AM »
It's not the problem of emotion function.

I just tried again, didn't work out.

when I press the English button, it did nothing, the interface was the same as Chinese version. I think your version B script only takes into account of two choice,

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« Reply #4 on: May 11, 2003, 07:03:57 AM »
hmmm...can I see it in action? I bet u did something wrong...exactly this code I use at my site and it works just perfectly
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 V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« Reply #5 on: May 11, 2003, 07:08:00 AM »
I think I know what's the problem ;)
if u said, that your default language is not english, then u'll also need change:
Code: [Select]
preg_match("/english/i"to whatever is your default language
hope that's what it is
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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
[MOD] Language select
« Reply #6 on: May 11, 2003, 02:28:45 PM »
Quote from: V@no
I think I know what's the problem ;)
if u said, that your default language is not english, then u'll also need change:
Code: [Select]
preg_match("/english/i"to whatever is your default language
hope that's what it is


where to change this code? Or where to put it?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« Reply #7 on: May 11, 2003, 02:41:39 PM »
Quote from: noyou
where to change this code? Or where to put it?

change it in this MOD 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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
[MOD] Language select
« Reply #8 on: May 12, 2003, 01:26:11 AM »
Quote
------- Note ------------------------
Version B is set to use images (I use it on my site)
the filenames of images must be this format:
language_folder_name.gif - for not currently selected languages
and
language_folder_name2.gif - for currently selected language
_________________[

 
what about the third language image link? Which one is for the third language image link?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« Reply #9 on: May 12, 2003, 01:30:46 AM »
Quote from: noyou
what about the third language image link? Which one is for the third language image link?

do u see broken image or something? because as I said, it will show as many emages as many folders it can find in /lang/ dir. I have 5 languages at my site, and it works just perfectly.
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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
[MOD] Language select
« Reply #10 on: May 13, 2003, 03:23:08 AM »
So do I have to create small country flag file *.gif in each /lang/dir?

why *.gif image is broken? didn't show up as an image

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Language select
« Reply #11 on: May 13, 2003, 03:38:15 AM »
no, u need the images be placed into /templates/<yourtemplate>/images/ dir.
the filename format must be as it explained in the mod.
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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
[MOD] Language select
« Reply #12 on: May 13, 2003, 05:12:34 AM »
could you show me how to name *.gif file? Like 1.gif, 2.gif, 3.gif, 4.gif etc?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Language select
« Reply #13 on: May 13, 2003, 11:03:11 AM »
ouh, c'mon :? :wink:
Quote from: V@no
------- Note ------------------------
Version B is set to use images (I use it on my site)
the filenames of images must be this format:
language_folder_name.gif - for not currently selected languages
and
language_folder_name2.gif - for currently selected language

so, for example for english and french languages u must have:
english.gif
english2.gif
french.gif
french2.gif
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 noyou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • http://www.nowife.com/photo/index.php
[MOD] Language select
« Reply #14 on: May 16, 2003, 11:21:14 PM »
sorry to bother you V@no, can you tell me the size for the gif file, 80*60 is good? :)