Jump to content


Grocery CRUD in multilingual pages

multilingual language

  • Please log in to reply
3 replies to this topic

#1 Radenko Kosic

Radenko Kosic

    Newbie

  • Members
  • Pip
  • 3 posts
  • LocationFrankfurt am Main

Posted 01 February 2015 - 08:53 AM

Hi,
I'm using Grocery CRUD in multilingual CodeIgniter (HMVC) pages here: http://sukulenti.com...odica/agavaceae. Default CRUD language is English and I have this in every function:

        if ($this->lang->lang() == "de") $crud->set_language("german");
        else
        if ($this->lang->lang() == "ba") $crud->set_language("bosnian");
        $output = $crud->render();

I have 9 functions (for 9 succulent families) but I intend to add more languages. Could this be made in a better way (less code)? I tried to add it in __construct() but it does not work.



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 02 February 2015 - 02:32 AM

Well.. u can do it in the constructor..

or better.. make a helper function..

in the function -- get the CI instance .. load the gc library...

create an instance...

and based on the language set / selected - set the cruds language tooo!

and return the crud object... and accet it as the variable

 

$crud = buildCrud()

 

hat should do the trick.

 

Happy GCing :)



#3 Radenko Kosic

Radenko Kosic

    Newbie

  • Members
  • Pip
  • 3 posts
  • LocationFrankfurt am Main

Posted 02 February 2015 - 07:19 AM

Thanks for the hint, I'll try to make a helper function.
https://ellislab.com...al/helpers.html

Do I have to extend language helper?

This is the language_helper.php

if ( ! function_exists('lang'))
{
    function lang($line, $id = '')
    {
        $CI =& get_instance();
        $line = $CI->lang->line($line);

        if ($id != '')
        {
            $line = '<label for="'.$id.'">'.$line."</label>";
        }

        return $line;
    }
}

MY_language_helper.php should be:

if ($this->lang->lang() == "de") $crud->set_language("german");
else
if ($this->lang->lang() == "fr") $crud->set_language("french");
else
if ($this->lang->lang() == "ba") $crud->set_language("bosnian");
else
if ($this->lang->lang() == "hr") $crud->set_language("croatian");

What does this?

$crud = buildCrud();

 

I think it would be better to change core/MY_Lang, I only have to get the current language name to load the same CRUD language.

    // languages
    var $languages = array(
        'en' => 'english',
        'de' => 'german',
        'fr' => 'french',
        'ba' => 'bosnian',
        'hr' => 'croatian'
    );

Maybe I could move CRUD languages from assets to the language folder?
Or it would be the easiest way to rename CRUD language files to "en", "de", "fr" etc?



#4 Radenko Kosic

Radenko Kosic

    Newbie

  • Members
  • Pip
  • 3 posts
  • LocationFrankfurt am Main

Posted 02 February 2015 - 10:15 AM

Renaming CRUD language files works fine!







Also tagged with one or more of these keywords: multilingual, language

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users