Welcome Guest, Not a member yet? Register   Sign In
validation errors multi-lingual
#1

[eluser]sl3dg3hamm3r[/eluser]
Hey there!

I'm just doing my small form, using CI's
validation capabilities.

How can I make this multi-lingual? The returned errors are by default english, but I'd like german and russian too Smile

Sl3dg3
#2

[eluser]everdaniel[/eluser]
You can add additional languages in your system/application/languages folder and then use this language in your config file.

I think there is already some translations out there, you should run a search about that here in the forums.

Good luck!
#3

[eluser]Derek Allard[/eluser]
I do this in BambooInvoice if you want to download the code and poke. I think there's... 7 or 8... lost count, supported langs in there.
#4

[eluser]sl3dg3hamm3r[/eluser]
Thx for the inputs.

I already saw that I can configure the language in the conf-file and download additional languages (not sure about russian yet), but I would like to alter the language on runtime (the user can select between three languages).

I will have a look at Bamboolnvoice and see if the language is changed during runtime?

Sl3dg3
#5

[eluser]xwero[/eluser]
The hardest part about changing languages at runtime is loading the choosen language files. I've made a method for this a while ago
Code:
/**
    * Makes switching between languages easier
    *
    *  example : http://ellislab.com/forums/viewreply/339962/
    */
    function switch_to($idiom)
    {
        $CI =& get_instance();
        if(is_string($idiom) && $idiom != $CI->config->item('language'))
        {
            $CI->config->set_item('language',$idiom);
            $loaded = $this->is_loaded;
            $this->is_loaded = array();
                
            foreach($loaded as $file)
            {
                $this->load(str_replace('_lang.php','',$file));    
            }
        }
    }
How you do the switch that is up to you, there are some solutions floating around the on the forum and wiki.
#6

[eluser]sl3dg3hamm3r[/eluser]
thx! The language-switcher I already have implemented. Now I would only need to call this additional method, nice!
#7

[eluser]sl3dg3hamm3r[/eluser]
here a corrected script which worked for me (based on Xwero's script, which had some errors concerning $this, maybe I tried it in a wrong context):

Code:
$CI =& get_instance();
if($lang != $CI->config->item('language'))
{
    $CI->config->set_item('language',$lang);
    $loaded = $CI->config->is_loaded;
    $CI->config->is_loaded = array();
            
    foreach($loaded as $file)
    {
        $CI->config->load(str_replace('_lang.php','',$file));    
    }
}

I wrote a small helper. A better way might be to inherit the Config-class and add this specialized function, but I was lazy... Smile
#8

[eluser]sl3dg3hamm3r[/eluser]
Gosh, I only realized now that the above snippet (which I use in a helper) doesn't seem to work. The language-files are not loaded when I change the language. It seems that the array is_loaded (from Config-class) is empty, therefore there is nothing to replace.
Why is it empty?
#9

[eluser]sl3dg3hamm3r[/eluser]
Ok, since Config::is_loaded is empty, I tried Config::config. That's how it looks like:

Code:
(
    [...]
    [index_page] => index.php
    [uri_protocol] => AUTO
    [url_suffix] =>
    [language] => de
    [charset] => UTF-8
    [enable_hooks] =>
    [subclass_prefix] => MY_
    [permitted_uri_chars] => a-z 0-9~%.:_\-
    [enable_query_strings] =>
    [directory_trigger] => d
    [controller_trigger] => c
    [function_trigger] => m
    [log_threshold] => 1
    [log_path] =>
    [log_date_format] => Y-m-d H:i:s
    [cache_path] =>
    [encryption_key] =>
    [sess_cookie_name] => ci_session_//[...]
    [sess_expiration] => 7200
    [sess_encrypt_cookie] =>
    [sess_use_database] => 1
    [sess_table_name] => ci_sessions
    [sess_match_ip] =>
    [sess_match_useragent] => 1
    [sess_time_to_update] => 300
    [cookie_prefix] =>
    [cookie_domain] =>
    [cookie_path] => /
    [global_xss_filtering] =>
    [compress_output] =>
    [time_reference] => local
    [rewrite_short_tags] =>
)

There is the language, of course, but there is nothing about what CI language-files are loaded. Where would I find them? Could somebody with some more CI-insights give me a hint where to find (and manipulate) them?
#10

[eluser]benjamincurrie[/eluser]
I created a Multi-Language Hook that I created for a project I have been working on. Multi-Language front-end support seems to be a very desired functionality that doesn't seem to be well supported in any frameworks, heres hoping this helps some people.

https://github.com/benjamincurrie/CodeIg...age-Switch

My main goal was to support multi-lingual search engine friendly URL's, for example:
http://mysite.com/home (home page in English)
http://mysite.com/accueil (home page in French)

This does require a config file to keep track of controller and function translations, for those who don't wish to maintain translations it reverts to URL's like this:
http://mysite.com/fr/home

There is also an option to use a query string:
http://mysite.com/home?lang=fr

I've put the project up on Github and would love some feedback, feel free to fork and improve on the code.
A lot of people seem to want to use cookies for storing user language preference, however I don't believe this is the best practice for search engine crawlers. Will eventually get to supporting this method too (as well as subdomain).

Ben




Theme © iAndrew 2016 - Forum software by © MyBB