I am making my site multilingual and the solution that I went with is to leverage CI's language system(that is, I am using language files).
I am using this addon to access language variables from the language files. Here is the code used to retrieve the language strings
$lang_file = ($this->EE->TMPL->fetch_param('file')) ? $this->EE->TMPL->fetch_param('file') : 'custom_label';
$this->EE->lang->loadfile($lang_file);
$param = $this->EE->TMPL->fetch_param('value');
$string = ($this->EE->lang->line($param)) ? $this->EE->lang->line($param) : '';
return $string;
I noticed though that no languages was set here. So I assumed that it is being set somewhere before this code executes.
I tried changing the languages in the Localization Settings for each member and the addon worked, getting only the strings from that language.
That is all well and good but it does have a problem in particular.
The current system only works for members. What if a guest(logged out user) wants to change language?
Solutions I am currently thinking are
Instead of relying on the saved preferred languaged, I would base it on the url segment
Store the language code in session
However, both of this can only work if I can override the currently set language.
Is there a way to do this?
P.S. Please don't suggest using addons like Publisher or Transcribe. I want to do this without using those addons.