Language - How to structure a multilanguage site? |
[eluser]Mauricio de Abreu Antunes[/eluser]
I'm coding a web site. He has 3 language choices: spanish, portuguese and english. In CI user guide, it tells me to put my translations in application/language. Ok, i did it. But i wanna translate form validation errors, like required or is_unique. How do to this? How to avoid system/core/language/english files? Thanks, bye!
[eluser]predat0r[/eluser]
Hi, use this library - https://github.com/daylerees/ci-lang it's for CI 2.1 With multilanguage articles, use an "index" table for an article (id, lang_id, date, status..), and subtables (id, article_id, title, content..) for language variations. With a function you can check what is the current selected language, and get the appropriate language article from the DB. How to implement : http://maestric.com/doc/php/codeigniter_i18n
[eluser]Mauricio de Abreu Antunes[/eluser]
Thanks dude! I have another problem: i told i wanna change my error messages in form_validation and labels (my HTML content is not in DB), titles, headers to another language like portuguese or spanish. When you use set_rules the message is in english. How to change this?
[eluser]predat0r[/eluser]
If I understand you language/english site_lang.php // english language lines, $lang['page_title'] = 'Title'; language/spanish site_lang.php // spanish lang lines, $lang['page_title'] = 'Dirección'; And with form validation, if you have specific files for each language in system/language, then it'll switch to the current language version, but to be hones i didn't try form_validation in my single multilang project
[eluser]Mauricio de Abreu Antunes[/eluser]
When do you have a error message for required field in spanish, what do you display? Do you display it in english?
[eluser]kr1pt[/eluser]
I use this: I place $this->load->lang('default', $this->user->default_language) [application/language/some_lang/default_lang.php] into MY_Controller, and whenever I print something, I use lang('key'). Default_language can be selected by user, default is english. For form_validation, place form_validation_lang.php into application/language/some_lang, because application folder is loaded before system.
[eluser]Mauricio de Abreu Antunes[/eluser]
Ok, but what about error messages? When you miss your username at login, how to translate this message with config file?
[eluser]kr1pt[/eluser]
[quote author="Mauricio de Abreu Antunes" date="1330962370"]Ok, but what about error messages? When you miss your username at login, how to translate this message with config file?[/quote] Just create form_validation_lang.php in application/language/spanish/ folder, with the same variables as those are in form_validation_lang.php in system/language/english folder. If default language is spanish, it will automaticly pick up form_validation_lang from application/language/spanish/ folder. But if those messages are your own, not from validation class, just use: if ($this->user->correct_login() === TRUE) { echo 'logged in'; } else { echo lang('invalid_login'); } and create variable in default_lang.php called $lang['invalid_login'] = 'le derping' Get it?
[eluser]Mauricio de Abreu Antunes[/eluser]
I'll try this, dude! Thank you. Obs.: user guide does not show this alternative.
[eluser]Mauricio de Abreu Antunes[/eluser]
I solved. I did what you mean and i autoloaded all my language files depending on language. Thanks! |
Welcome Guest, Not a member yet? Register Sign In |