Jump to content

Recommended Posts

I have a class which loads language files and adds the content(which is an array) into a phrases array. It's performed perfectly when i included common_lang.php and login_lang.php. However when i include common_lang.php and profiles_lang.php something weird happens.

 

I have a blank space at the top of the profile pages. And firebug reports that the content of <head> is now empty and its shifted all of it to the <body>.

 

Like i say this only happens when including profiles_lang.php but works with other files like login_lang.php.

 

The content of each language file is the same apart from the data in the array.

 

$l = array(
'USERNAME'    => 'Username',
);

 

this is the language class which is being called in profiles.php like Asf_Language::loadFile('profiles'); The same call is used in other pages replacing 'profiles' with the name of the language file to call.

 

<?php
/* ASF A Simple Forum
* (c) ASF A Simple Forum 2010 - 2011
* 
* @licence        http://www.asimpleforum.co.uk/licence
* 
* $page        includes/languageClass.php
* $author         Carl Markham
* $created        14/06/2011
*/

class Asf_Language
{
    public static $lang;
    
    public static $phrases = array();
    
    public static $loaded_langs = array();
    
    public function __construct($default)
    {
        $this->setLang($default);
        self::loadFile('common');
    }
    
    public static function setLang($lang)
    {
        self::$lang = $lang;
    }
    
    public static function getLang()
    {
        return $lang;
    }
    
    public static function loadFile($file)
    {
        $include = dirname(dirname(dirname(__FILE__))).'/languages/'.self::$lang.'/'.$file.'_lang.php';
        
        if(file_exists($include))
        {
            include($include);
            
            self::$loaded_langs[] = $file;
            
            foreach($l as $key => $val)
            {
                self::$phrases[$key] = $val;
            }
        }
        else
        {
            echo 'File '.$include.' does not exist';
        }
        
        return;
    }
    
    public static function getLoadedLanguages()
    {
        return implode(', ',self::$loaded_langs);
    }
}

 

Anyone have any ideas why the head is being emptied when this file is being included?

 

Link to comment
https://forums.phpfreaks.com/topic/245371-including-language-files/
Share on other sites

this is profiles_lang.php

 

<?php
/* ASF A Simple Forum
* (c) ASF A Simple Forum 2010 - 2011
* 
* @licence        http://www.asimpleforum.co.uk/licence
* 
* $page        languages/en/login_lang.php
* $author         Carl Markham
* $created        27/07/2011
*/

$l = array(
    'WALL_FEED_DELETED'    => 'Your wall feed has been deleted',
    'USER_STATISTICS'    => 'User Statistics',
);

 

and this is login_lang.php

 

<?php
/* ASF A Simple Forum
* (c) ASF A Simple Forum 2010 - 2011
* 
* @licence        http://www.asimpleforum.co.uk/licence
* 
* $page        languages/en/login_lang.php
* $author         Carl Markham
* $created        27/07/2011
*/

$l = array(
    'FILL_ALL_DETAILS'        => 'Please fill in all details',
    'NO_USER'                => 'No user was found matching your data',
    'WRONG_SECRET_QUESTION'    => 'You entered an incorrect secret question or secret answer',
    'LOGGED_IN'                => 'You have now been logged in',
    'LOGIN'                    => 'Log me in',
    'FORGOT_PASS'            => 'Forgot password',
    'USERNAME'                => 'Username',
    'PASSWORD'                => 'Password',
    'AUTO_LOGIN'            => 'Auto Login',
    
    'USERNAME_LOGIN_INFO'    => 'Enter the username you logged in with',
    'PASSWORD_LOGIN_INFO'    => 'The password you chose when you registered',
    'AUTO_LOGIN_INFO'        => 'Choose to be logged in automatically each visit',
);

 

As i said there is no difference apart from the content of the array.

 

Thanks for the help anyway then. If it happened with each included language file then i may be able to understand. But the fact it only happens on this one included file. If i change the file to login_lang.php the space disapears and everything works fine.

Best guess is you either have something in the file before the <?php tag or after the ?> tag or you have saved the file as a UTF-8/Unicoded file with BOM (Byte Order Mark) characters.

 

Make sure there are no characters outside of the <?php ?> tags and make sure that file is saved without the BOM characters (there should be an option in your editor's encoding/file-save-as menu.)

ive changed the save type to utf 8 without BOM but still get the same issue. Ive since deleted the language files and resaved them to make sure this new encoding was being saved but no joy there. It still only happens with profiles_lang.php. I thought it may be the encoding of the profiles.php page which calls the file but ive tested it on the index which had no issues calling common_lang.php and I get the same thing when calling profiles_lang.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.