Last active
December 27, 2015 22:09
-
-
Save hissy/7396557 to your computer and use it in GitHub Desktop.
[concrete5] How to switch area name based on the current language. Install: upload multilingual_text.php to /helpers directory. Requires Internationalization add-on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('C5_EXECUTE') or die("Access Denied."); | |
Loader::model('section', 'multilingual'); | |
class MultilingualTextHelper { | |
/** | |
* Takes area name string (like Header) and add language string (like Header Ja JP) | |
* @param string $text | |
* @return string | |
*/ | |
public function getMultilingualAreaName($text) { | |
$th = Loader::helper('text'); | |
$ms = MultilingualSection::getCurrentSection(); | |
if (is_object($ms)) { | |
$locale = $ms->getLocale(); | |
} else { | |
$locale = Localization::activeLocale(); | |
} | |
if ($locale != 'en_US'){ | |
return $text . ' ' . $th->unhandle($locale); | |
} else { | |
return $text; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mt = Loader::helper('multilingual_text'); | |
// 'Global Nav' in English page, 'Global Nav Ja JP' in Japanese page | |
$a = new GlobalArea($mt->getMultilingualAreaName('Global Nav')); | |
$a->display(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment