1

Although I find the built-in language management in Opencart close to perfect, I need a language switcher extension for any text anywhere on the site, which would work something like following :

{en}text shown only on English site{/en}
{de}text shown only on German site{/de}

Similar extension is used widely in Joomla and is quite popular.

Does anybody know such an extension for Opencart ?

Charles
  • 50,943
  • 13
  • 104
  • 142
bogatyrjov
  • 5,317
  • 9
  • 37
  • 61
  • Really? It is way far from perfect :-D `gettext` with just one language file (per language) would be much much better... This *language files* and phrases repeating is silly... And I think You are already speaking of it... Anyway - what is the effort of what You are asking for? Can't You do the same with current language system...? I'm not sure I understand Your need correctly... – shadyyx Apr 19 '13 at 08:30
  • Usually, by default, there is a simple way to switch languages in admin, when you edit articles etc. (anywhere where there is a text field in admin). I have a custom module in admin, which has a text field and which doesn't support multiple languages. So, I need this magic plugin, like I described, which would save me a ton of hours. – bogatyrjov Apr 19 '13 at 21:45
  • If it is Your own extension, then edit it to support multilanguage (check other OpenCart admin parts for how to implement this). If it is extension You have bought then contact the developer/company to add the multilingual support... Or if You feel up to editing the 3rd party extension on Your own, go right into it...Check `admin/controller/localisation/order_status.php` for a simple solution or `admin/controller/catalog/information.php` for a solution using WYSIWYG and tabs... – shadyyx Apr 20 '13 at 10:12

1 Answers1

2

Why don't you just use the tags you mentioned:

{en}text shown only on English site{/en}
{de}text shown only on German site{/de}

Then add preg_match on output before rendering.

In system/engine/controller.php find this line:

$this->output = ob_get_contents();

replace with (in my example language IDs are 1 and 2 for English and Russian respectively):

//check for current language and do preg_replace on output

/* get current language ID */
$cur_lang_id = $this->config->get('config_language_id');

/* store buffer output in variable */
$html = ob_get_contents();
$tags = array('/\{en\}/','/\{\/en\}/','/\{ru\}/','/\{\/ru\}/');

/* do replacements */
if ($cur_lang_id == '2') {$html = preg_replace('/\{en\}.+\{\/en\}/','',$html);}
if ($cur_lang_id == '1') {$html = preg_replace('/\{ru\}.+\{\/ru\}/','',$html);}

/* remove tags */
$html = preg_replace($tags,'',$html);

//$this->output = ob_get_contents();
$this->output = $html;
B-and-P
  • 1,693
  • 10
  • 26