$CI =& get_instance();
yield CI->Language_model->get_phrase($phrase, $language_id);
I’m working within a web program which must support a number of languages (fortunate for me personally, the customer requested English & Spanish but I need to be prepared to add another later on ).
First, I did a little reading on localization (l10n) vs. internationalization (i18n) and while my need isn’t quite “localization,” ” it’s close enough that’s everything I’m calling it.
I already had my languages dining table, so I added a couple more:
My particular requirements:
I pass along the pure English term, rather than a slug. The PHP function is as follows:
<? = l10n('Logo Alt Text', $language_id)?'
That is OK. I will look up the slug ‘logo_alt_text’ at the $language_id specified and return on the “word. ”
“words” comprised a (special ) slug, where the translation was saved in words_translated (I later switched by calling my translations “phrases” rather than “phrases ). My PHP code will look like:
<? = l10n('logo_alt_text', $language_id)?'
- Easily expandable past two languages.
- Able to read the purpose of my PHP code.
Public function get_phrase($phrase, $language_id)
Operate l10n($slug, $language_id)
And now I could only write:
$question = $this->db->get();
if ($String = $query->unbuffered_row(‘range’))
// We didn’t get a match, so go back the English version
reunite l10n($slug, 1);
$this->Language_model->get_phrase(‘Logo Alt Text’, $language_id);