Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active December 27, 2015 22:09
Show Gist options
  • Save hissy/7396557 to your computer and use it in GitHub Desktop.
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
<?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;
}
}
}
<?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