Dynamic Localization

Help
timt
2010-09-08
2013-05-28
  • timt
    timt
    2010-09-08

    Hi,

    I'm trying to dynamically switch between two languages in my refbase installation, based on a querystring passed from a page outside of refbase.

    I've tried modifying the start_session() function in include.inc.php. I'm using the value from my $_GET variable to set a new $_SESSION variable for the language, and then assigning that to the $defaultLanguage variable defined in ini.inc.php.

    This seems to work fine for navigation purposes, but when I choose Portuguese (my alternative language), I am not able to use refbase's citation or export features. I get a refbase error message (from error.php) stating "Error 1065 : Query was empty."

    However, when I choose English, both citation and export work fine. You can see this in action by choosing a language and then clicking on the database (or "banco de dados") links from here: http://www.indiana.edu/~liblatam/researching-brazil/

    Any suggestions?

    Thanks in advance for any help.

    Tim

     
  • Very hard to say without seeing your code, but you might not be establishing a new session completely/correctly.  I was able to occasionally download content from the Portuguese version, probably because poking around on the site enough established a complete session.  This was particularly true when I could stumble on the original refbase index page (now at 'admin').

     
  • timt
    timt
    2010-09-09

    Here is all I'm doing to modify the code (my addition begins on line 86 of include.inc.php). Any ideas about why it always works in English, if the code is the same?

    // Start a session:
        function start_session($updateUserFormatsStylesTypesPermissions)
        {
            global $defaultMainFields; // defined in 'ini.inc.php'
            global $loginEmail;
            global $loginUserID;
            global $loginFirstName;
            global $loginLastName;
            global $abbrevInstitution;
            global $lastLogin;
            global $referer; // '$referer' is made globally available from within this function
            
            // Added next two variables to global. --TT
            global $defaultLanguage; 
            global $officialDatabaseName;
            
            global $connection;
            // Initialize the session:
            if (!isset($_SESSION["sessionID"]))
            {
                // Ensure that cookies are enabled:
                if (ini_get('session.use_cookies') == 0) // if 'session.use_cookies' is OFF for the current directory
                    ini_set('session.use_cookies', 1); // enable storage of sessions within cookies
                session_start();
                $sessionID = session_id(); // get the current session ID
                if (!empty($sessionID))
                    saveSessionVariable("sessionID", $sessionID);
                    
                // Set language from db/index.php querystring. --TT            
                if ($_GET['lang'] == "pt") {
                    $_SESSION['s_Lang'] = "pt";                    
                    $defaultLanguage = $_SESSION['s_Lang'];
                    $_SESSION['s_Name'] = "Pesquisa no Brasil: Banco de Dados Bibliográficos";    
                    $officialDatabaseName = $_SESSION['s_Name'];                                                                                    
                }
                elseif ($_GET['lang'] == "en") {
                    $_SESSION['s_Lang'] = "en";                                    
                    $defaultLanguage = $_SESSION['s_Lang'];    
                    $_SESSION['s_Name'] = "Researching Brazil: Bibliographic Database";            
                    $officialDatabaseName = $_SESSION['s_Name'];
                } else {
                    $defaultLanguage = $_SESSION['s_Lang'];
                    $officialDatabaseName = $_SESSION['s_Name'];
                }                                        
            }
            // Set the system's locale information:
    
     
  • I still have little clue what you're doing.  I'd imagine that en works because that is the defaultLanguage you defined in your ini.inc.php.  In any case, this patch works for me:

    --- include.inc.php    (revision 1334)
    +++ include.inc.php    (working copy)
    @@ -60,6 +60,7 @@
             global $abbrevInstitution;
             global $lastLogin;
             global $referer; // '$referer' is made globally available from within this function
    +        global $defaultLanguage;
    
             global $connection;
    
    @@ -158,6 +159,12 @@
                     saveSessionVariable("userMainFields", $defaultMainFields);
             }
    
    +        // Set the language: 
    +        if (isset($_GET['lang'])) { 
    +            $defaultLanguage = $_GET['lang']; 
    +            saveSessionVariable("language", $defaultLanguage); 
    +        }
    +
             // Set the referrer:
             if (isset($_REQUEST['referer']) AND !empty($_REQUEST['referer']))
                 $referer = $_REQUEST['referer']; // get the referring URL from the superglobal '$_REQUEST' variable (if any)
    @@ -4166,7 +4173,10 @@
    
             global $defaultLanguage; // defined in 'ini.inc.php'
    
    -        if (isset($_SESSION['loginEmail'])) // if a user is logged in
    +        if (isset($_SESSION['language'])) { 
    +            $userLanguage = $_SESSION['language']; 
    +        }
    +        else if (isset($_SESSION['loginEmail'])) // if a user is logged in
             {
                 // get the preferred language for the current user:
                 $userLanguagesArray = getLanguages($loginUserID);
    
     
  • timt
    timt
    2010-09-09

    Thanks very much for your reply. I appreciate the help. I applied the patch, but am unfortunately still getting the same results-i.e., when I select a record and click "Cite" or "Export," I get a 1065 error ("Query was empty"). The session seems to be working fine . . . but for some reason no query seems to be going through to the database when the language is changed from "en."

    Maybe I did something wrong when I modified the locales? I just tried setting the default language to French and got the same error. I don't get this error, of course, when I change the default language to French in a "normal" refbase installation.

    Why would the database query be affected by the language setting?

    Thanks again for any suggestions.

    Tim

     
  • I don't know what changes you made to the code.  Were you able to revert the bulk of them before applying the patch?  You can test to confirm my solution works on a relatively clean install of refbase:

    http://arc.nucapt.northwestern.edu/refbase-svn2/?lang=de