Conny Olsson
Conny Olsson

Reputation: 1577

Where should I put translation lists in Codeigniter?

I'm fetching table names and column names from a database and then put them in drop-downs. To be a little nice to my users I'm about to translating the table and column names to something that a normal human can understand.

My problem is that i don't know where I should put the translation lists.

Any other suggestions (with pros and cons)?

Upvotes: 0

Views: 1452

Answers (1)

shaggy
shaggy

Reputation: 1718

Like I wrote in my comment, the best way to achieve this is to use Codeigniter Language class.

Then you create tables_lang.php file in language directory.

Next you load language file:

$this->lang->load('tables', 'english');

or (if you want to use default language):

$this->lang->load('tables');

If you have table users, in that table column name, your language lines should look like this:

$lang['table_users'] = 'Users table';
$lang['table_users_col_name'] = 'User name';

In your controller, model or view you can fetch data this way:

$table = 'users'; //table name from database
$table_name = $this->lang->line('table_'.$table);

$column = 'name';
$column_name = $this->lang->line('table_'.$table.'_col_'.$column);

If you want to use translations in your view, you have to change $this->lang->line() to lang() function from language helper.

Upvotes: 1

Related Questions