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

I have started using CodeIgniter 3.0, I need localization support with SEO best practices.
Is there any library available for this?
Reply
#2

I'm also interested in Internationalization. I've located the Language Class for CI3 but wonder if this is enough. Some instances where it doesn't really seem like it might help:
* SEO-optmized urls in a different language. For instance, how can my site server http://example.com/products and also serve http://example.com/produits (the French equivalent) without me either a) defining a whole new controller or b) creating a super-elaborate routes.php file to provide mappings for all of the languages I support. If I support 5 languages, I would need (# of controllers) * (# of methods) * (# of languages supported) entries in the routes file to support these other languages.
* Prompts which incorporate some specific value from my Model in the middle of a sentence. E.g., "You must be at least 13 years of age to use this website." Or "You are limited to 3 login attempts before getting banned."
* Instances where a currency, address, time, or other local-specific entity is dealt with.

Can anyone suggest tools to help create a website that supports multiple languages? Any anecdotes or helpful experience is appreciated.
Reply
#3

(This post was last modified: 12-28-2014, 06:40 AM by ivantcholakov. Edit Reason: A typo )

I have written some notes here: http://forum.codeigniter.com/thread-77.html Also, one my application skeletons (CI3-based) supports partly the things you need: https://github.com/ivantcholakov/starter...-edition-4 , here is a demo: http://iridadesign.com/starter-public-edition-4/www/

To be honest about internationalization, with CodeIgniter you are on your own, you need to implement everything alone. Consider using a ready CodeIniter-based CMS, or have a look at Yii2 framework.

Not important:
http://example.com/en/products and http://example.com/fr/produits - this seems a better choice for me. Otherwise if a word (the slug) is the same in two languages - a collision happens, what content is to be shown then.
Reply
#4

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?
Reply
#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
#6

(12-30-2014, 02:39 PM)mwhitney Wrote:
(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

Heart
all thanks to this best answer its helped my to make multiple language codeigniter3
Reply
#7

all thanks to this best answer its helped my to make multiple language codeigniter3
Reply
#8

(12-27-2014, 09:36 PM)ivantcholakov Wrote: I have written some notes here: http://forum.codeigniter.com/thread-77.html Also, one my application skeletons (CI3-based) supports partly the things you need: https://github.com/ivantcholakov/starter...-edition-4 , here is a demo: http://iridadesign.com/starter-public-edition-4/www/

To be honest about internationalization, with CodeIgniter you are on your own, you need to implement everything alone. Consider using a ready CodeIniter-based CMS, or have a look at Yii2 framework.

Not important:
http://example.com/en/products and http://example.com/fr/produits - this seems a better choice for me. Otherwise if a word (the slug) is the same in two languages - a collision happens, what content is to be shown then.

sorry stupid comment here, i have read your comment above and face problem about slug in my project has multi languange, what should i do to make it dynamic when user change languange

so here is my table


kode | id |title | article |lang | slug


how can i change the slug mr, please hope nice respond Thanks Big Grin
Reply
#9

For multilingual URL in CodeIgniter website, I think you can use 


PHP Code:
$autoload['helper'] = array('url'); 


in your autoload.php website. Source: https://www.cloudways.com/blog/multi-lan...deigniter/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB