Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 07:10 am EDT

Geeklog Forums

Language selection


Yvan

Anonymous
Is it possible to set up GL so that a language selection is available to guests as well as to registered users? Ideally, I would like English as the default and French available to whomever. Thanks.
 Quote

Tim

Anonymous
Hello, Has anyone found an answer to this question? I am interested in doing the same thing. Thanks, Tim.
 Quote

Status: offline

maigoofy

Forum User
Junior
Registered: 02/09/03
Posts: 15
Quote by Yvan: Is it possible to set up GL so that a language selection is available to guests as well as to registered users? Ideally, I would like English as the default and French available to whomever. Thanks.
Great idea. I want to do that with English and Japanese.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Just some thoughts: The actual language selector should be trivial - you can get most of the code from function editpreferences() in usersettings.php. The tricky bit is that you would have to set the language cookie for the user. You can\'t do that in the block directly, since cookies can only be sent in the header of a page, i.e. before the actual page contents. So you would have to redirect the user to some other page, set the cookie there and then send them back to where they came from. That\'s a bit like what users.php does when you log in. Hope that helps. bye, Dirk
 Quote

Tym

Anonymous
I tried to post this message last week, but my browser crashed before submitting, and I didnt feel like doing it again. Anyways, I solved the visitor language option. Here is what I found and did:

In the file usersettings.php, there is a comment in the function savepreferences() that reads like so.
// Save theme, when doing so, put in cookie so we can set the user's theme even when they aren't logged in

This lead me to believe that if a user is not logged in, couldn't that also mean a visitor might be accessing the site. Unfortunately, this function is only called from main() if and only if both $_USER['username'] and $mode are not empty, meaning the user has to be logged in and mode is set (preferences, comments, edit, saveuser, savepreferences, or savecomments). If it fails these, else it checks for $mode = preferences, and if not, then the browser is redirected to index.php. The changes I made are to this ELSE, inserting the following code:

Text Formatted Code

} else if ($mode == 'savepreferences') {
     setcookie($_CONF['cookie_language'],$HTTP_POST_VARS['language'],time() + 31536000,$_CONF['cookie_path']);  
     $display .= COM_refresh($_CONF['site_url'] . '/index.php');
 


All this code simply does is if savepreferences is set, then a cookie is stored with the language information, and then the browser is redirected to the homepage. Now the language dropdown can be inserted into any public file, such as the header.thtml. The code for the dropdown is in the function editpreferences() with a comment that reads:
// Get available languages

Now, you won't need every bit of the code, so here is what I used in my header.thtml file:

Text Formatted Code

$retval .= '<form action="' . $_CONF['site_url'] . '/usersettings.php" method="post">';
    if ($_CONF['allow_user_language'] == 1) {
        $retval .= '<select name="language" class="textblacksmall">' . LB;

        if (empty($_USER['language'])) {
            $userlang = $_CONF['language'];
        } else {
            $userlang = $_USER['language'];
        }

        // Get available languages
        $language_options = '';
        $fd = opendir($_CONF['path_language']);
        while (($file = @readdir($fd)) == TRUE) {
            if (is_file($_CONF['path_language'].$file)) {
                clearstatcache();
                $file = str_replace('.php', '', $file);
                                if ($file != ".DS_Store") {  // Inserted 7/23/2003 - TN
                        $language_options .= '<option value="' . $file . '" ';
                        if ($userlang == $file) {
                            $language_options .= 'selected="SELECTED"';
                        }
                        $uscore = strpos ($file, '_');
                        if ($uscore !== false) {
                            $lngname = substr ($file, 0, $uscore);
                            $lngadd = substr ($file, $uscore + 1);
                            $lngname = strtoupper ($lngname{0}) . substr ($lngname, 1);
                            $lngadd = strtoupper ($lngadd{0}) . substr ($lngadd, 1);
                            $file = $lngname . ' (' . $lngadd . ')';
                        } else {
                            $file = strtoupper ($file{0}) . substr ($file, 1);
                        }
                        $language_options .= '>' . $file . '</option>' . LB;
                                }
            }
        }
        $retval .= $language_options;
        $retval .= '</select>';
        $retval .= '<input type="hidden" name="mode" value="savepreferences"> '
            . '<input type="image" src="{layout_url}/theme-images/but_go.gif" value="Go" align="middle" alt="Go"></form>';
                echo($retval);
    }
 


And that should be it.

Now, I have geeklog running on an OS X server, and I noticed that in my language dropdown there as a listing of .DS (Store). I didn't find anything on the site regarding this, so I am posting what this is. On the Mac OS, every folder has an invisible file that stores desktop information for that folder. You might have encountered something similar it when using a disk on a pc after using it on a mac. Anyways, this invisible file cannot be deleted for 2 reasons. 1) If you try to erase it, the system will replace it with a new one, and 2) The trash bin has it's own copy of the file, and only the system has permissions to overwrite. In order to remove the file listing from the dropdown, you will need to edit the code with an if condition to check for the file, and not use it. You will notice this in the code snippet above where today's date and my initials are located. Thats what that is. Hope this helps. Happy GL'ing.

Tim.
 Quote

Status: offline

1000ideen

Forum User
Full Member
Registered: 08/04/03
Posts: 1298
You may also find this here as Hack:
http://summitpages.ca/filemgmt/singlefile.php?lid=22

Perhaps it should become a standard block of GL like the theme tester?
 Quote

Status: offline

Euan

Forum User
Full Member
Registered: 04/22/02
Posts: 292
The block on this page does what you want.

Cheers

Euan.
-- Heather Engineering
-- No job too small
 Quote

All times are EDT. The time is now 07:10 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content