Domanda

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 ?

È stato utile?

Soluzione

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top