Welcome Guest, Not a member yet? Register   Sign In
Internationalization and localization (i18n) for CodeIgniter 3.0?
#5

(12-28-2014, 12:34 AM)karthik_code Wrote: Here is a workout for CI 2.1 https://github.com/bcit-ci/CodeIgniter/w...ation-i18n
Is there anything similar to CI 3.0?

Though the code could use some cleanup and modernization, it would probably work with 3.0 with the following modifications:


Change the site_url() method in MY_Config to accept a second argument and pass that argument to the parent's site_url() method:

PHP Code:
class MY_Config extends CI_Config
{
 
   public function site_url($uri ''$protocol NULL)
 
      
        if 
(is_array($uri))
 
       {
 
           $uri implode('/'$uri);
 
       }

 
       if (function_exists('get_instance'))
 
       {
 
           $uri get_instance()->lang->localized($uri);            
        
}

 
       return parent::site_url($uri$protocol);
 
   }


Don't use the provided language helper (or update it to work properly with the arguments expected by the CI 3.0 language helper). You would probably be better off using printf()/sprintf() to handle placeholders in your localized strings anyway.

Most of the functions in the MY_Lang file don't override existing functions, so you may be able to use that unmodified, but I would recommend:
- rename the MY_Lang() function to __construct()
- add the public visibility keyword to the load() method
- remove the default value from the load() method's $langfile argument
Reply


Messages In This Thread
RE: Internationalization and localization (i18n) for CodeIgniter 3.0? - by mwhitney - 12-30-2014, 02:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB