Localization / Multi-language Applications with PHP & MySQL

$CI =& get_instance();

$5 CI->load->model(‘Language_model’);
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:

$this->db->select(“wt.word”);
this->db->(“words_translated wt”);
$this->db->join(“phrases w”,”w.word_id=wt.word_identification”,”left”);
$this->db->where(“w.slug”, $slug);
$this->db->where(“wt.language_id”, (int)$language_id);
$this->db->limit(1);
$question = $this->db->get();
if ($String = $query->unbuffered_row(‘range’))
return $row[‘term’];

// 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);

In the event the translation didn’t exist, I could drop back to looking this up in speech ‘1’ (English) and return that.

So I made MY_text_helper.php and put in it:

Finally, I didn’t want to have my PHP code similar to this:

The trouble with this is when I didn’t even specify the English edition of the slug, it will fail. If you want to Be Certain that a term is defined, this can be fine but that I ’d instead have the application continue working so that I scrapped those tables and Created the following concept:
My PHP looks like:
I know I will rewrite those two SQL queries to one question; this was a proof of concept which can get refactored before the app goes to production.


Function l10n($phrase, $language_id)
Return $word;

Finally, I didn’t want to have my PHP code similar to this:
I’m working within an internet program which must support many languages (lucky for me, the customer asked English & Spanish but I want to be ready to easily add another later on ).

<?

  • Easily expandable past two languages.
  • Able to see the purpose of my PHP code.

To begin with I did a little reading on localization (l10n) vs. internationalization (i18n) and while my need isn’t very “localization,” it’s ’s close enough that’s everything I’m calling it.
I know I can rewrite those two SQL queries to a single query; this was a proof of concept which can get refactored until the app goes to creation.

Public function get_phrase($phrase, $language_id)

I had my languages table, so I added a couple more: