Skip to content

Instantly share code, notes, and snippets.

@kepek
Created November 29, 2011 11:56
Show Gist options
  • Save kepek/1404560 to your computer and use it in GitHub Desktop.
Save kepek/1404560 to your computer and use it in GitHub Desktop.
Magento Multilanguage Category Description (Fast Workaround)
<?php
/* Vritual Helper Function */
public function translate($text = false, $lang = false) {
$lang = $lang ? $lang : Mage::app()->getLocale()->getLocaleCode();
if($text) {
preg_match('#\[translate lang="'.$lang.'"\](.*?)\[/translate\]#si', $text, $match);
if($match) {
$output = trim($match[1]);
}
else {
$output = $text;
}
}
else {
$output = false;
}
return $output;
}
?>
<?php
/* Sample Category Description */
$text = '[translate lang="en_GB"]Lorem Ipsum EN[/translate][translate lang="de_DE"]Lorem Ipsum DE[/translate]';
?>
<?php
/* How to Use it? */
echo Mage::helper('virtual')->translate($text, 'en_US');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment