⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Grocery CRUD in multilingual pages



Radenko Kosic

Radenko Kosic
  • profile picture
  • Member

Posted 01 February 2015 - 08:53 AM

Hi,
I'm using Grocery CRUD in multilingual CodeIgniter (HMVC) pages here: http://sukulenti.com/ba/porodica/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.


Amit Shah

Amit Shah
  • profile picture
  • Member

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 :)


Radenko Kosic

Radenko Kosic
  • profile picture
  • Member

Posted 02 February 2015 - 07:19 AM

Thanks for the hint, I'll try to make a helper function.
https://ellislab.com/codeigniter/user-guide/general/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?


Radenko Kosic

Radenko Kosic
  • profile picture
  • Member

Posted 02 February 2015 - 10:15 AM

Renaming CRUD language files works fine!