Welcome Guest, Not a member yet? Register   Sign In
using language & template parser classes combined
#1

[eluser]romero619[/eluser]
Hi,
Im new to codeigniter.

I want to use the language class & the template parsing class together to create a multi-lingual site. I've already implemented the il8n.php base class so that I can distinguish the language based on the first url segment (i.e.,'/en','/fr','/es',etc.).

My goal is to load the correct language file (based on the language key in the url segment), and use the template parser class to completely fill in the view template.

I DONT want to use the method of creating separate views based on language (such as 'myview_en.php' and 'myview_fr.php').

I want to only have a single template for each view, and maintain all text in separate language files (similiar to how phpBB uses 'language packs').

Im having trouble conceptualizing how to combine these two classes.
The language class seems like it can only load variables individually, using '$this->lang->line('language_key');' syntax. I dont see how I can load ALL of the variables in a language file, and use them with the parser class.

Also, I will need to pass additional data to my view, and not just the language keys, so the language keys would need to be part of a multidim. array.

Something like:
Code:
//get my data from model
$data['db_results']=$this->my_model->get_my_db_data();

//expand language name based on 2-char lang code
//$this->lang_code comes from 'il8n.php' base controller class
$my_lang=$this->get_full_lang_name($this->lang_code);

//now, load the correct language file
//based on value of '$my_lang' variable,
//and also all of the variables in the language file
//
//DONT KNOW WHAT TO DO HERE TO LOAD ALL VARIABLES IN LANG FILE
//THE FOLLOWING OBVIOUSLY DOESNT WORK...
$data['lang_text']=$this->lang->load('db_results', $my_lang);


//PROBLEM HERE: parser expects its variables to be
//in 1st dimension of $data array, and not in nested (multi-dim) sub-arrays
//so how could I get it to search the entire multi-dim array?
//
//ALSO, I need parser to parse BOTH the 'lang_text' sub-array for the lang keys
//AND also the data contained in the 'db_results' sub-array, for my db query rows.
//would this be possible?

$this->parser->parse('db_results_template', $data);
...so, an example template could contain something like:
Code:
<html>
<head>
<!--
these variables should come from $data['lang_text'] array
based on the language being used...
-->

<title>{db_results_title}</title>
</head>
<body>
<h3>{db_results_heading}</h3>

&lt;!--
the following variables should come from $data['db_results'] array
and are language-independent
--&gt;

{db_results_rows}
<h5>{db_column1}</h5>
<p>{db_column2}</p>
{/db_results_rows}
&lt;/body&gt;
&lt;/html&gt;

any ideas on what would be the best way to accomplish something like this???

Please help,
Thanks,
P.R.
#2

[eluser]romero619[/eluser]
bump...
anyone???
#3

[eluser]Jondolar[/eluser]
Merge your data array (from your model) and your language array.
array array_merge ( array $array1 [, array $array2 [, array $... ]] )

$data = array_merge ($data,$lang);

Now you can use the template parser to parse all of your language elements.




Theme © iAndrew 2016 - Forum software by © MyBB