codeigniter gettext poedit php |
[eluser]wormhit[/eluser]
Hi! Simple tutorial how to use gettext in your codeigniter application. 1) To translate something use function _('my text') in your controllers and views. 2) Create language files structure as follows: Code: /application/language/locales/lv_LV/LC_MESSAGES/ 3) Configure poedit (http://goo.gl/zSyfz) (use codeigniter paths) and generate *.mo and *.po files using poedit and name them as "lang": Code: result: /application/language/locales/lv_LV/LC_MESSAGES/lang.mo and lang.po 4) Create new codeigniter helper /application/helpers/my_language_helper.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 5) set helper in autoloader: /application/config/autoload.php Code: $autoload['helper'] = array(..., 'my_language'); 6) Initialize translation with function. (You can also set language in cookie and set language in helper) Code: set_translation_language('lv_LV'); That's all! =] I tried to find something like this all over the web, but found nothing. So, I looked at default php gettext functions (http://www.php.net/manual/en/function.gettext.php) and it was so easy to make it work with them. Hopefully that will be useful to someone..
[eluser]toopay[/eluser]
First post, and try to share something valuables. Great.
[eluser]T-productions[/eluser]
HI everyone, I've tried your solution on Code Igniter 2.0.2 but it doesn't work at all. In fact when I echo a string with "_" like : Code: echo _("My string"); I work in a local environment with Wamp Server and my firefox says : Quote:The connection was reset However I've put an autoload for this helper and copy your function in a helper like this : Code: <?php Any ideas ? Thanks in advance for your help. Cyril
[eluser]T-productions[/eluser]
Thanks for your answer but it's the same result... It's kind of weird cause gettext extension is activated. Anyone knows what's wrong ?
[eluser]wormhit[/eluser]
I don`t understand. You followed instructions and when you started application it`s sad: Code: The connection was reset Do you created *.po and *.mo files? Check if language file structure is correct and file domain name is ok.
[eluser]T-productions[/eluser]
It's not like that I'm getting this message once I display variables with _(''); I used to use GetText but not in Code Igniter. Here is the process : Structure with : Quote:application/language/locale/en_US/LC_MESSAGES/messages.moThen I try what I put above I get this error only when I put an echo even with GetText I'm working on WampServer with gettext activated. I'm gonna try to upload on my hosting to test it also
[eluser]wormhit[/eluser]
I think it is not the gettext problem. You tryed to google error message? http://www.wampserver.com/phorum/read.php?2,57192
[eluser]Truong Chuong DUong[/eluser]
I just make a library which can auto translate all text between {t} and {/t} in the view, I posted here in case some one want to use it instead calling the gettext function in the view: http://www.chuongduong.net/page/15/codei...-view.html The view code might be: Code: <html>
[eluser]Syed Abidur Rahman[/eluser]
I think, you have misspelled the 'locales' directory. The statement should be like the following: Code: $lang_path = FCPATH.APPPATH.'language/locales'; |
Welcome Guest, Not a member yet? Register Sign In |