Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use Locale 'en_US' instead of language 'en' to identify a translation

  • Loading branch information...
commit 0a6a012efb672edf69c7f75ac0a41db37ea402ed 1 parent acffdff
Ryan Tyler tylerryan authored
1  .gitignore
View
@@ -2,4 +2,3 @@
.DS_Store
thumbs.db
__MACOSX
-
2  packages/multilingual/blocks/switch_language/controller.php
View
@@ -48,7 +48,7 @@ public function view() {
$pkg = Package::getByHandle('multilingual');
$mdl = Loader::helper('default_language', 'multilingual');
- $this->set('defaultLanguage', $mdl->getSessionDefaultLanguage());
+ $this->set('defaultLanguage', $mdl->getSessionDefaultLocale());
$this->set('cID', $c->getCollectionID());
}
12 packages/multilingual/blocks/switch_language/templates/flags_set_default/view.php
View
@@ -1,8 +1,6 @@
-<? defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
+<? defined('C5_EXECUTE') or die(_("Access Denied."));
-<?
$ih = Loader::helper("interface/flag", 'multilingual');
-
?>
<div class="ccm-multilingual-language-list-wrapper">
@@ -13,15 +11,11 @@
<input type="hidden" name="ccmMultilingualCurrentPageID" value="<?=Loader::helper('text')->entities($_REQUEST['rcID'])?>" />
<? } ?>
-
-<? foreach($languageSections as $ml) {
- ?>
-
+<? foreach($languageSections as $ml) { ?>
<div class="ccm-multilingual-language-list-item">
- <input type="radio" name="ccmMultilingualSiteDefaultLanguage" value="<?=$ml->getLanguage()?>" <? if ($defaultLanguage == $ml->getLanguage()) { ?> checked="checked" <? } ?> /><?
+ <input type="radio" name="ccmMultilingualSiteDefaultLanguage" value="<?=$ml->getLocale()?>" <? if ($defaultLanguage == $ml->getLocale()) { ?> checked="checked" <? } ?> /><?
print $ih->getSectionFlagIcon($ml);
- ?><?
print $ml->getLanguageText($ml->getLanguage());
?></div>
2  packages/multilingual/blocks/switch_language/tools/switch.php
View
@@ -13,7 +13,7 @@
if (empty($_POST['ccmMultilingualSiteRememberDefault'])) {
setcookie('DEFAULT_LANGUAGE', '', time() - 3600, DIR_REL . '/');
}
- $lang = MultilingualSection::getByLanguage($_REQUEST['ccmMultilingualSiteDefaultLanguage']);
+ $lang = MultilingualSection::getByLocale($_REQUEST['ccmMultilingualSiteDefaultLanguage']);
} else {
$lang = MultilingualSection::getByID($_REQUEST['ccmMultilingualChooseLanguage']);
2  packages/multilingual/controllers/dashboard/multilingual/page_report.php
View
@@ -109,7 +109,7 @@ public function ignore_page() {
public function create_page() {
Loader::model('section', 'multilingual');
if (Loader::helper('validation/token')->validate('create_page', $_POST['token'])) {
- $ms = MultilingualSection::getByLanguage($_POST['language']);
+ $ms = MultilingualSection::getByLocale($_POST['language']);
$page = Page::getByID($_POST['sourceID']);
if (is_object($page) && !$page->isError()) {
// we get the related parent id
4 packages/multilingual/controllers/dashboard/multilingual/setup.php
View
@@ -107,7 +107,7 @@ public function load_icons() {
$checked = "checked=\"checked\"";
}
- $html .= '<li><input type="radio" name="msIcon" ' . $checked . ' id="languageIcon' . $i . '" value="' . $region . '" /><label for="languageIcon' . $i . '">' . $flag . ' ' . $value . '</label></li>';
+ $html .= '<li><input type="radio" name="msIcon" ' . $checked . ' id="languageIcon' . $i . '" value="' . $region . '" onchange="ccm_multilingualUpdateLocale(\''.$region.'\')" /><label for="languageIcon' . $i . '">' . $flag . ' ' . $value . '</label></li>';
$i++;
}
}
@@ -149,7 +149,7 @@ public function default_language_updated() {
public function set_default() {
if (Loader::helper('validation/token')->validate('set_default')) {
- $lc = MultilingualSection::getByLanguage($this->post('defaultLanguage'));
+ $lc = MultilingualSection::getByLocale($this->post('defaultLanguage'));
if (is_object($lc)) {
$pkg = Package::getByHandle('multilingual');
$pkg->saveConfig('DEFAULT_LANGUAGE', $this->post('defaultLanguage'));
4 packages/multilingual/db.xml
View
@@ -11,6 +11,10 @@
<DEFAULT value="''"/>
</field>
<field name="msIcon" type="C" size="6"/>
+ <field name="msLocale" type="C" size="32">
+ <NOTNULL/>
+ <DEFAULT value=""/>
+ </field>
</table>
<table name="MultilingualPageRelations">
<field name="mpRelationID" type="I" size="10">
49 packages/multilingual/helpers/default_language.php
View
@@ -11,7 +11,7 @@ public function checkDefaultLanguage() {
if (!$req->getRequestCollectionPath() && $req->getRequestCollectionID() == 1 && (!$req->isIncludeRequest())) {
$pkg = Package::getByHandle('multilingual');
if ($pkg->config('REDIRECT_HOME_TO_DEFAULT_LANGUAGE')) {
- $ms = MultilingualSection::getByLanguage(DefaultLanguageHelper::getSessionDefaultLanguage());
+ $ms = MultilingualSection::getByLocale(DefaultLanguageHelper::getSessionDefaultLocale());
if (is_object($ms)) {
header('Location: ' . Loader::helper('navigation')->getLinkToCollection($ms, true));
exit;
@@ -34,11 +34,16 @@ public function checkDefaultLanguage() {
// first checks to see if there is a cookie set with this
// otherwise we retrieve it from the sitewide multilingual settings
- public function getSessionDefaultLanguage() {
- if (isset($_SESSION['DEFAULT_LANGUAGE'])) {
- return $_SESSION['DEFAULT_LANGUAGE'];
+ public function getSessionDefaultLocale() {
+ // they have a language in a certain session going already
+ if (isset($_SESSION['DEFAULT_LOCALE'])) {
+ return $_SESSION['DEFAULT_LOCALE'];
}
+ // if they've specified their own default locale to remember
+ if(isset($_COOKIE['DEFAULT_LOCALE'])) {
+ return $_COOKIE['DEFAULT_LOCALE'];
+ }
$pkg = Package::getByHandle('multilingual');
//
@@ -49,10 +54,9 @@ public function getSessionDefaultLanguage() {
Loader::model('section','multilingual');
Loader::library('3rdparty/Zend/Locale');
$locale = new Zend_Locale();
- $guestLanguage = $locale->getLanguage();
- if(is_object(MultilingualSection::getByLanguage($guestLanguage))){
- return $guestLanguage;
+ if(is_object(MultilingualSection::getByLocale((string) $locale))){
+ return $locale;
}
}
@@ -70,32 +74,33 @@ public static function setupSiteInterfaceLocalization() {
if (is_dir(DIR_LANGUAGES_SITE_INTERFACE)) {
$ms = MultilingualSection::getCurrentSection();
if (is_object($ms)) {
- $language = $ms->getLanguage();
- if (file_exists(DIR_LANGUAGES_SITE_INTERFACE . '/' . $language . '.mo')) {
+ $locale = $ms->getLocale();
+ if (file_exists(DIR_LANGUAGES_SITE_INTERFACE . '/' . $locale . '.mo')) {
$loc = Localization::getInstance();
- $loc->addSiteInterfaceLanguage($ms->getLanguage());
+ $loc->addSiteInterfaceLanguage($locale);
}
} else {
- $language = DefaultLanguageHelper::getSessionDefaultLanguage();
- if (file_exists(DIR_LANGUAGES_SITE_INTERFACE . '/' . $language . '.mo')) {
+ $locale = DefaultLanguageHelper::getSessionDefaultLocale();
+ if (file_exists(DIR_LANGUAGES_SITE_INTERFACE . '/' . $locale . '.mo')) {
$loc = Localization::getInstance();
- $loc->addSiteInterfaceLanguage($language);
+ $loc->addSiteInterfaceLanguage($locale);
}
}
}
- // add package translations
- if(strlen($language)) {
- $ms = MultilingualSection::getByLanguage($language);
- $pl = PackageList::get();
- $installed = $pl->getPackages();
- foreach($installed as $pkg) {
- if($pkg instanceof Package) {
- $pkg->setupPackageLocalization($ms->msLanguage."_".$ms->msIcon, $ms->msLanguage);
+ // add package translations, won't happen if the DIR_LANGUAGES_SITE_INTERFACE directory doen't exits...
+ if(strlen($locale)) {
+ $ms = MultilingualSection::getByLocale($locale);
+ if($ms instanceof MultilingualSection) {
+ $pl = PackageList::get();
+ $installed = $pl->getPackages();
+ foreach($installed as $pkg) {
+ if($pkg instanceof Package) {
+ $pkg->setupPackageLocalization($ms->getLocale());
+ }
}
}
}
-
}
}
11 packages/multilingual/helpers/section.php
View
@@ -30,15 +30,20 @@ public function section($s = false) {
/**
* returns the current language
* @return string
+ * @deprecated
*/
public function getLanguage() {
+ return self::getLocale();
+ }
+
+ public function getLocale() {
$ms = MultilingualSection::getCurrentSection();
if (is_object($ms)) {
- $lang = $ms->getLanguage();
+ $lang = $ms->getLocale();
} else {
- $lang = Loader::helper('default_language','multilingual')->getSessionDefaultLanguage();
+ $lang = Loader::helper('default_language','multilingual')->getSessionDefaultLocale();
}
- $_SESSION['DEFAULT_LANGUAGE'] = $lang;
+ $_SESSION['DEFAULT_LOCALE'] = $lang;
return $lang;
}
}
67 packages/multilingual/models/section.php
View
@@ -2,10 +2,28 @@
defined('C5_EXECUTE') or die("Access Denied.");
class MultilingualSection extends Page {
+
+ /**
+ * @var string
+ */
+ public $msLocale;
+
+ /**
+ * @var string
+ */
+ public $msIcon;
+
+ /**
+ * @var string
+ */
+ public $msLanguage;
public static function assign($c, $language, $icon) {
$db = Loader::db();
- $db->Replace('MultilingualSections', array('cID' => $c->getCollectionID(), 'msLanguage' => $language, 'msIcon' => $icon), array('cID'), true);
+
+ $locale = $language . (strlen($icon)?'_'.$icon:'');
+
+ $db->Replace('MultilingualSections', array('cID' => $c->getCollectionID(), 'msLanguage' => $language, 'msIcon' => $icon, 'msLocale' => $locale), array('cID'), true);
}
public function unassign() {
@@ -13,18 +31,30 @@ public function unassign() {
$db->Execute('delete from MultilingualSections where cID = ?', array($this->getCollectionID()));
}
+ /**
+ * returns an instance of MultilingualSection for the given page ID
+ * @param int $cID
+ * @param int $cvID
+ * @return MultilingualSection|false
+ */
public static function getByID($cID, $cvID = 'RECENT') {
$r = self::isMultilingualSection($cID);
if ($r) {
$obj = parent::getByID($cID, $cvID, 'MultilingualSection');
$obj->msLanguage = $r['msLanguage'];
$obj->msIcon = $r['msIcon'];
+ $obj->msLocale = $r['msLocale'];
return $obj;
}
return false;
}
+ /**
+ * @param string $language
+ * @return MultilingualSection|false
+ * @deprecated
+ */
public static function getByLanguage($language) {
$db = Loader::db();
$r = $db->GetRow('select cID, msLanguage, msIcon from MultilingualSections where msLanguage = ?', array($language));
@@ -37,6 +67,28 @@ public static function getByLanguage($language) {
return false;
}
+ /**
+ * @param string $language
+ * @return MultilingualSection|false
+ */
+ public function getByLocale($locale) {
+ $db = Loader::db();
+ $r = $db->GetRow('select cID, msLanguage, msIcon, msLocale from MultilingualSections where msLocale = ?', array($locale));
+ if ($r && is_array($r) && $r['msLocale']) {
+ $obj = parent::getByID($r['cID'], 'RECENT', 'MultilingualSection');
+ $obj->msLanguage = $r['msLanguage'];
+ $obj->msIcon = $r['msIcon'];
+ $obj->msLocale = $r['msLocale'];
+ return $obj;
+ }
+ return false;
+ }
+
+
+ /**
+ * gets the MultilingualSection object for the current section of the site
+ * @return MultilingualSection
+ */
public static function getCurrentSection() {
static $lang;
if (!isset($lang)) {
@@ -48,6 +100,10 @@ public static function getCurrentSection() {
return $lang;
}
+ /**
+ * @param Page $page
+ * @return MultilingualSection
+ */
public static function getBySectionOfSite($page) {
// looks at the page, traverses its parents until it finds the proper language
$nav = Loader::helper('navigation');
@@ -61,13 +117,8 @@ public static function getBySectionOfSite($page) {
}
}
- /*
- public function getSessionDefaultLanguage() {
- return "en";
- }
- */
-
public function getLanguage() {return $this->msLanguage;}
+ public function getLocale() { return $this->msLocale; }
public function getLanguageText($locale = ACTIVE_LOCALE) {
if (!class_exists('Zend_Locale')) {
Loader::library('3rdparty/Zend/Locale');
@@ -211,7 +262,7 @@ public static function isMultilingualSection($cID) {
$cID = $cID->getCollectionID();
}
$db = Loader::db();
- $r = $db->GetRow('select cID, msLanguage, msIcon from MultilingualSections where cID = ?', array($cID));
+ $r = $db->GetRow('select cID, msLanguage, msIcon, msLocale from MultilingualSections where cID = ?', array($cID));
if ($r && is_array($r) && $r['msLanguage']) {
return $r;
} else {
10 packages/multilingual/single_pages/dashboard/multilingual/setup.php
View
@@ -16,12 +16,11 @@
<th>&nbsp;</th>
</tr>
<? foreach($pages as $pc) {
- $pcl = MultilingualSection::getByID($pc->getCollectionID());
- ?>
+ $pcl = MultilingualSection::getByID($pc->getCollectionID()); ?>
<tr>
<td><?=$ch->getSectionFlagIcon($pc)?></td>
<td><a href="<?=$nav->getLinkToCollection($pc)?>"><?=$pc->getCollectionName()?></a></td>
- <td><?=$pcl->getLanguageText()?></td>
+ <td><?=$pcl->getLanguageText()?> (<?php echo $pcl->getLocale();?>)</td>
<td><?=$pc->getCollectionPath()?></td>
<td><a href="<?=$this->action('remove_language_section', $pc->getCollectionID(), Loader::helper('validation/token')->generate())?>"><img src="<?=ASSETS_URL_IMAGES?>/icons/remove_minus.png" /></td>
</tr>
@@ -43,7 +42,6 @@
<div id="ccm-multilingual-language-icon">
<?=t('Choose a Language')?>
</div>
-
<br/>
<h3><?=t('Choose a Parent Page')?></h3>
<?=Loader::helper('form/page_selector')->selectPage('pageID', '')?>
@@ -70,7 +68,7 @@
if (lang && lang != '') {
$("#ccm-multilingual-language-icon").load('<?=$this->action("load_icons")?>', {'msLanguage': lang, 'selectedLanguageIcon': icon});
}
-}
+};
</script>
@@ -112,7 +110,7 @@
$defaultLanguages = array('' => t('** None Set'));
foreach($pages as $pc) {
$pcl = MultilingualSection::getByID($pc->getCollectionID());
- $defaultLanguages[$pcl->getLanguage()] = $pcl->getLanguageText();
+ $defaultLanguages[$pcl->getLocale()] = $pcl->getLanguageText();
}
$defaultLanguagesSelect = $form->select('defaultLanguage', $defaultLanguages, $defaultLanguage);
Please sign in to comment.
Something went wrong with that request. Please try again.