Mr.Web
Mr.Web

Reputation: 7144

Codeigniter Language, replace with default where not existing

I'm working on a project with Codeigniter, I have multiple language, I load my default language (Italian) in the config file and this works fine.

I noticed if I switch language (let's say from Italian to English) if there is no variable set in the english_lang.php (or whatever file) I just get a blank instead of using the default language.

So, let's say I have this:

ITALIAN

$lang['main_loading'] = "Caricamento...<br>Attendere.";
$lang['main_titolo'] = "Titolo";
$lang['main_descrizione'] = "Descrizione";

ENGLISH

$lang['main_loading'] = "Loading...<br>Please Wait.";
$lang['main_descrizione'] = "Description";

As you can see main_titolo is missing in the English file, so when I load the page in english I have an empty title instead of using the Italian (default) string for that specific variable.

Is there a way to use default language for non-exsisting languages lines (variables)?

Upvotes: 0

Views: 602

Answers (1)

Egor Sazanovich
Egor Sazanovich

Reputation: 5089

No. You can't define "default" as overridable language. In fact You define language-files-folder in this var. But You can set default language for example "mydefault", create mydefault_lang.php, define there all Your default strings, add this lang-file to autoload.php and after that load Your lang files with language-param in app and override it. For example mydefault

$lang['title'] = "I'm default title";
$lang['header'] = "Hello, world!";

...somewhere at, for example, controllers/user.php

// ....
function login(){
    //                  _desireable lang here_
    $this->load->lang('user','english');
    $this->load->view('user/login');
}

Your language/english/user_lang.php

$lang['title'] = "I'm English title";

And in views/user/login.php

<?php echo $this->lang->line('title'); ?>

Upvotes: 1

Related Questions