Nacho Muñoz Fernandez Posted March 21, 2010 Report Share Posted March 21, 2010 Hello everyone, I have a question about Codon Framework ... Is this considered or is developing a i18n class? greetings (sorry for english google translator dont help me too much ) Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 21, 2010 Administrators Report Share Posted March 21, 2010 What do you mean? Do you mean language strings? Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 21, 2010 Author Report Share Posted March 21, 2010 What do you mean? Do you mean language strings? For example, in the templates files all strings get from other file using this class, using a constant or string. Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 21, 2010 Administrators Report Share Posted March 21, 2010 For example, in the templates files all strings get from other file using this class, using a constant or string. There are some - in the core/lang/en.lang.php file I think it's called. All the other language is directly in the templates, since you can modify the templates you can change the language as well Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 21, 2010 Author Report Share Posted March 21, 2010 There are some - in the core/lang/en.lang.php file I think it's called. All the other language is directly in the templates, since you can modify the templates you can change the language as well Yes this its right, but if you needs 2 o more language at same time for a multilanguage airline, i think this its not posible right now. for make that all language strings from template files needs to be ubicated in other files and use the lang.class.php to load all strings for the user selected language. or the lang.class.php can be used for that? Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 21, 2010 Administrators Report Share Posted March 21, 2010 Yes this its right, but if you needs 2 o more language at same time for a multilanguage airline, i think this its not posible right now. for make that all language strings from template files needs to be ubicated in other files and use the lang.class.php to load all strings for the user selected language. or the lang.class.php can be used for that? Yes you can use that for multi-lang strings Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 21, 2010 Author Report Share Posted March 21, 2010 yes i see, i am working on move al string from templates to a separate language files and making multifile system. This is the modificated Lang.class.php for load all separated files in lang/$lang_iso/ class Lang { public static $language; public static $trans_table; public static function load_language() { $language_selected = $_COOKIE['phpvms_lang']; if(!$_COOKIE['phpvms_lang']) { self::set_language(Config::Get('SITE_DEFAULT_LANGUAGE')); } else { if(in_array($language_selected,Config::Get('SITE_AVALIBLE_LANGUAGE'))) { self::set_language($language_selected); } else { self::set_language(Config::Get('SITE_DEFAULT_LANGUAGE')); } } } public static function set_language($lang='en') { self::$language = $lang; $path = CORE_PATH.DS.'lang'.DS.$lang.DS; $lang_options = CORE_PATH.DS.'lang'.DS.$lang.DS.'.language.xml'; // TODO: language information if(!file_exists($lang_options)) { return false; } $lang_files = glob($path.'{*.php}',GLOB_BRACE);// Loads al language files from the selected lang $trans_temp = array(); foreach($lang_files as $file) { include $file; $trans_temp = array_merge($trans_temp,$trans); unset($trans); } $trans_temp = $trans; /* Load up the translation table from the /lang/[lang]/lang.php file */ self::$trans_table = $trans; unset($trans); } public static function gs($string) { return self::$trans_table[$string]; } /* Alias */ public static function get($string) { return self::gs($string); } } i have also others files for using this. When everything is finished can i send if you like for the next version of PHPVMS or Codon Framework EDIT: i am using the last version of phpvms of Git repository. (revision 906). Greetings Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 22, 2010 Administrators Report Share Posted March 22, 2010 Ah I see. Available is spelled wrong in the config string. Just wondering - why are you doing glob, why not just include 'lang/LANG/lang.php'; which could then include the other files included: $base = dirname(__FILE__); include $base.'/file1.php'; But glob might be ok. But, there might be a faster implementation, rather than using glob (which is pretty slow), like this function http://github.com/ns....class.php#L276 Or the FileIterator, but that might be PHP 5.3 only. And what's in the language file? For the config file, inside the en.lang.php file there is: $trans = array( Perhaps instead of an extra XML file, just add another array: $lang_info = array( 'name' => 'English', ); $trans = array( Just a suggestion And the loading language from the cookie looks interesting. Let me know where you make out with this, perhaps I can roll this back in upstream Thanks! Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 22, 2010 Author Report Share Posted March 22, 2010 Just wondering - why are you doing glob, why not just include 'lang/LANG/lang.php'; which could then include the other files included: Glob its more easier for the user to add new translation files o new modules, make language unnattended. but you are right the fn: GetAvailableSkins() its more faster than glob. About the cookie yes, using the cookie for the no authenticated user and for registered pilots when they loads settings from their profile db and the next reload use the cookie for use less db querys. Using the XML, yes, best using other php file like: config.lang.php for admin panel see the autor, license etc etc... Let me know where you make out with this, perhaps I can roll this back in upstream I am testing this, and i will try to integrate the function that you have said instead of Glob(). Tomorrow i send you... if you need a help with other questions i can help you, or colaborate with the project. Greetings Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 22, 2010 Author Report Share Posted March 22, 2010 Ok, try this: class Lang { public static $language; public static $trans_table; public static function load_language() { $language_selected = $_COOKIE['phpvms_lang']; if(!$language_selected) { self::set_language(Config::Get('SITE_DEFAULT_LANGUAGE')); } else { if(in_array($language_selected,Config::Get('SITE_AVAILABLE_LANGUAGE'))) // This prevents cookie hack { self::set_language($language_selected); } else { self::set_language(Config::Get('SITE_DEFAULT_LANGUAGE')); } } } public static function set_language($lang='en') { self::$language = $lang; $path = CORE_PATH.DS.'lang'.DS.$lang; $trans_temp = array(); if (is_dir($path)) { $fh = opendir($path); while (($file = readdir($fh)) !== false) { if ($file == '.' || $file == '..' || $file == '.svn') continue; $filepath = $path . DS . $file; $file_parts = explode('.',$file); if(!is_dir($filepath) && $file_parts[1] == 'lang' && $file_parts[2] == 'php') // for loading only *.lang.php files { include $filepath; $trans_temp = array_merge($trans_temp,$trans); unset($trans); } } closedir($fh); } $trans = $trans_temp; /* Load up the translation table from the /lang/[lang]/lang.php file */ self::$trans_table = $trans; unset($trans); } public static function gs($string) { return self::$trans_table[$string]; } /* Alias */ public static function get($string) { return self::gs($string); } } this its a helper, in bootstrap.inc.php function lang($string) { echo Lang::gs($string); } function langstr($string) { return Lang::gs($string); } check it if its right. Nabeel can you give me your SkypeID? for talk more faster about that S! Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 22, 2010 Administrators Report Share Posted March 22, 2010 Looks good. I don't have skype atm. But maybe you can implement this into an add-on. I can't integrate just yet, a little too much going on. Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 22, 2010 Author Report Share Posted March 22, 2010 Looks good. I don't have skype atm. But maybe you can implement this into an add-on. I can't integrate just yet, a little too much going on. Ok no problem about that, Will there be changes in revision 906 to the stable version on the .tpl files? I say this because i am working on moving all template strings to lang.php files. If you tell me an approximate date of release of the stable version(2.1), could have finished ready for use this addon and merge all files for that date. What you think? Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted March 22, 2010 Administrators Report Share Posted March 22, 2010 Ok no problem about that, Will there be changes in revision 906 to the stable version on the .tpl files? I say this because i am working on moving all template strings to lang.php files. If you tell me an approximate date of release of the stable version(2.1), could have finished ready for use this addon and merge all files for that date. What you think? There probably will be alot of changes. Here's my suggestion - Create a new Lang class, called class MultiLang { ... } In a new file, and create it into an addon with your custom templates, and release it as an addon. If you place the MultiLang file and just call it, it autoloads. Quote Link to comment Share on other sites More sharing options...
Nacho Muñoz Fernandez Posted March 23, 2010 Author Report Share Posted March 23, 2010 There probably will be alot of changes. Here's my suggestion - Create a new Lang class, called class MultiLang { ... } In a new file, and create it into an addon with your custom templates, and release it as an addon. If you place the MultiLang file and just call it, it autoloads. I'd better save it for the future when you have more time to implement. Greetings and thanks! Quote Link to comment Share on other sites More sharing options...
Mysterious Pilot Posted December 13, 2010 Report Share Posted December 13, 2010 And the loading language from the cookie looks interesting. Let me know where you make out with this, perhaps I can roll this back in upstream Thanks! Actually two things come into the game, there is the browser language negotiation and the cookie thing. Every browser has in its options a prioritized list of langugages the user chooses, for example: 1. Spanish, 2. English, 3. French. When the browser fetches a page from a server it sends this information, if the page requested is not available in the 1st choice, the 2nd is returned and if not the 3rd and so on. There is always a default (what the server has available). Then you can also have a cookie to override that if you like. In my previous life I wrote a couple of multilanguage PHP sites and some code to do it. I used a combination of string constants for the string catalog and language especific files, i.e. Registration.en.php/Registration.de.php. Nevertheless it is a touch matter. So it is Internationalization & Globalization. Another issue that should not be overlooked in multilingual websites (if you really want to go that way, which would be nice) is that the number, date, currency and other formats also change accordingly. If not taken care off, a US centric site would gladly accept numbers in 4.5 format and then an European will enter it as 4,5 meaning the same but in the end being interpreted as two different numeric values because of the culture settings. In other words, it isn't so simple and it takes time but it is better to tackle it earlier in the development process than later (more things to review, more tests to be performed). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.