[eluser]gr0uch0mars[/eluser]
Hi! I'm also having headaches with list_fields().
My case is: I'm organising the language strings in a database, then I create a script to write the _lang.php files to use with the language class.
The structure of my table is: one column for string names (column "string"), one column per language (column name is language name: 'english', 'spanish'...). Then, each row is a string, with its translations into all languages.
The problem comes when I try to create a controller to update the language files in my language folders (writing the php file with a script) from the database. I list fields (to retrieve all column names, that is, all languages) and then, foreach language , I write the .php file.
This is my code:
Code:
$fields = $this->db->list_fields('languages'); // Retrieve all languages (table columns, including the first one "string")
foreach ($fields as $field)
{
$data = "<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
"; // The begining of the _lang.php file
$this->db->select("string, $field"); // $field means 'spanish', 'english', etc.
$strings = $this->Languages->get_language_strings();
foreach ($strings->result_array() as $string)
{
$data .= '$lang["'.$string['string'].'"] = "'.$string[$field].'"; // $string[$field], there comes the problem.
';
}
$data .= "?>"; // End of _lang.php file
// I start writing the _lang.php file
if ( ! write_file('./system/application/language/'.$field.'/'.$field.'_lang.php', $data))
{
echo '<p>Unable to write the file</p>';
}
else
{
echo '<p>File written!</p>';
}
}
PROBLEM 1: When I write the line
Code:
$lang['logout'] = 'Log Out';
I don't know how to tell the script that 'Log Out' belongs to column $field.
When I write this code
Code:
$data .= '$lang["'.$string['string'].'"] = "'.$string[$field].'";
(and I'm using arrays exceptionally because I don't know what more to do) you see
That means that $field corresponds to 'english, spanish, etc.', one per column (that's why I use a list_field foreach at the beginning). Using objects ($string->$field) doesn't work neither, so what can I do???
PROBLEM 2 (minor problem): How to do a foreach ignoring the first column "string" (which has only the string names, not any translation).
I know my explanation is awful
, but I think you can help me. If you don't understand something, just ask me.
Thank you!