Skip to content

Commit

Permalink
Version 0.5.0, Add more functionality for including custom language p…
Browse files Browse the repository at this point in the history
…ackages via locale 'en_ZZ'.
  • Loading branch information
MaWoScha committed Dec 21, 2017
1 parent 04a34d2 commit 2239814
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 77 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ v0.4.4

v0.4.5

Die Datei "var/package/Delete_EmailTemplates_en_US-1.2.0.xml" berücksichtigt zusätzlich dazugekommene englischsprachige E-Mail-Vorlagen
- Die Datei "var/package/Delete_EmailTemplates_en_US-1.2.0.xml" berücksichtigt zusätzlich dazugekommene englischsprachige E-Mail-Vorlagen.
- Italienische Lokalisierung hinzugefügt.

Italienische Lokalisierung hinzugefügt.
v0.5.0

Setting options expanded.
- The idea is to have custom language packs that have only a few entries in addition to the main package (eg de_DE) and are therefore easy to maintain and to include via the locale "de_ZZ", "en_ZZ", "es_ZZ", "fr_ZZ" and so on.

Einstellungsmöglichkeiten erweitert.
- Die Idee ist, kundenspezifische Sprachpakete zu haben, die neben dem Hauptpaket (bsp. de_DE) nur wenige Einträge haben und deshalb leicht zu warten sind und über die locale "de_ZZ", "en_ZZ", "es_ZZ", "fr_ZZ und so weiter einzubinden sind.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package German_LocaleFallback
* @authors MaWoScha <mawoscha@siempro.co, http://www.siempro.co/>
* @developer MaWoScha <mawoscha@siempro.co, http://www.siempro.co/>
* @version 0.4.5
* @version 0.5.0
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class German_LocaleFallback_Block_System_Config_Form_Fieldset_Instructions
Expand All @@ -16,34 +16,43 @@ public function render(Varien_Data_Form_Element_Abstract $element)

$html = $this->_getHeaderHtml($element);
$html .= "<p>";
$html .= $helper->__("Magento has only one variable available for the locale (<a href='%s'>locale</a>). This extension now provides two settings:",
Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit', array('section'=>'general')));
$html .= $helper->__("Magento has only one variable available for the locale (<a href='%s'>locale</a>). This extension now provides two settings:",
Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit', array('section'=>'general')));
$html .= "</p>";

$html .= "<ol style='list-style-position: outside; list-style-type: disc; margin-left:18px;'>";
$html .= "<li>".$helper->__('Locale Preferred')."</li>";
$html .= "<li>".$helper->__('Locale Fallback')."</li>";
$html .= '</ol>';
$html .= "<ol style='list-style-position: outside; list-style-type: disc; margin-left:18px;'>";
$html .= "<li>".$helper->__('Locale Preferred')."</li>";
$html .= "<li>".$helper->__('Locale Fallback')."</li>";
$html .= '</ol>';

$html .= "<p>".$helper->__("Now it is possible to use a preferred language with a fallback language. Thus it can be set as the preferred language a partially available language, the fallback language then takes over the lack of rest.")."</p>";
$html .= "<p>".$helper->__("You want to sell and make use of the language of your target audience. Magento supports it – at least in theory. Practically, it is then but so that for most languages no language packs are available for Magento. Creating your own custom language pack fails again mostly at the expense: The language files of Magento contain several thousand entries.")."</p>";
$html .= "<p>".$helper->__("However, the complexity is significantly lower when only a limited selection of entries had to be translated and for the rest a fallback language could be defined. That would be also safe in case of updating the Magento software.")."</p>";
$html .= "<p>".$helper->__("The fallback language, which complements the missing entries of their own language pack, can be defined here. First, however, one's own language pack must be installed. The process can be reversed.")."</p>";
$html .= "<hr style='margin-top:20px;'>";
$html .= "<p>".$helper->__("Now it is possible to use a preferred language with a fallback language. Thus it can be set as the preferred language a partially available language, the fallback language then takes over the lack of rest.")."</p>";
$html .= "<p>".$helper->__("You want to sell and make use of the language of your target audience. Magento supports it – at least in theory. Practically, it is then but so that for most languages no language packs are available for Magento. Creating your own custom language pack fails again mostly at the expense: The language files of Magento contain several thousand entries.")."</p>";
$html .= "<p>".$helper->__("However, the complexity is significantly lower when only a limited selection of entries had to be translated and for the rest a fallback language could be defined. That would be also safe in case of updating the Magento software.")."</p>";
$html .= "<p>".$helper->__("The fallback language, which complements the missing entries of their own language pack, can be defined here. First, however, one's own language pack must be installed. The process can be reversed.")."</p>";
$html .= "<hr style='margin-top:20px;'>";

$html .= $helper->__("This package is simply adding three Static Blocks to the <a href='%s'>E-Mail-Templates</a>:",
Mage::helper('adminhtml')->getUrl('adminhtml/system_email_template'));
$html .= "<ul style='list-style-position: outside; list-style-type: disc; margin-left:18px;'>";
$html .= "<li>email_template_say_hello &nbsp; (".$helper->__("Salutation").")</li>";
$html .= "<li>email_template_contact &nbsp; (".$helper->__("Contact information").")</li>";
$html .= "<li>email_template_say_bye &nbsp; (".$helper->__("Closing formula").")</li>";
$html .= "</ul>";
$html .= $helper->__("This package is simply adding three Static Blocks to the <a href='%s'>E-Mail-Templates</a>:",
Mage::helper('adminhtml')->getUrl('adminhtml/system_email_template'));
$html .= "<ul style='list-style-position: outside; list-style-type: disc; margin-left:18px;'>";
$html .= "<li>email_template_say_hello &nbsp; (".$helper->__("Salutation").")</li>";
$html .= "<li>email_template_contact &nbsp; (".$helper->__("Contact information").")</li>";
$html .= "<li>email_template_say_bye &nbsp; (".$helper->__("Closing formula").")</li>";
$html .= "</ul>";
$html .= "<p>";
$html .= $helper->__("The static blocks can be managed by the <a href='%s'>CMS system</a> in the admin area.",
Mage::helper('adminhtml')->getUrl('adminhtml/cms_block'));
Mage::helper('adminhtml')->getUrl('adminhtml/cms_block'));
$html .= "</p>";
$html .= "<p style='text-align:right;'>";
$html .= $helper->__("powered by")." <a href='https://github.com/mawoscha/German_LocaleFallback' target='_blank'>MaWoScha</a>";
$html .= "<hr style='margin-top:20px;'><p>";

$html .= $helper->__("For localized packages you can add packages with locals as <a href='%s' target='_blank'>de_ZZ</a>, <a href='%s' target='_blank'>en_ZZ</a>, <a href='%s' target='_blank'>es_ZZ</a>, <a href='%s' target='_blank'>fr_ZZ</a> and so forth.",
'https://github.com/MaWoScha/German_LocalePack_de_ZZ',
'https://github.com/MaWoScha/German_LocalePack_en_ZZ',
'https://github.com/MaWoScha/German_LocalePack_es_ZZ',
'https://github.com/MaWoScha/German_LocalePack_fr_ZZ');
$html .= " " . $helper->__("Also a informal German version <a href='%s' target='_blank'>de_DE_DU</a> is available.",
'https://github.com/MaWoScha/German_LocalePack_de_DE_DU');
$html .= "</p><p style='text-align:right;'>";
$html .= $helper->__("powered by")." <a href='https://github.com/mawoscha/German_LocaleFallback' target='_blank'>MaWoScha</a>";
$html .= "</p>";
$html .= $this->_getFooterHtml($element);

Expand Down
16 changes: 9 additions & 7 deletions app/code/community/German/LocaleFallback/Model/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ protected function _getLocales()
* pt_MZ: Portugiesisch in Mozambique
* ur_IN: Urdu in Indien
* ur_PK: Urdu in Pakistan
$_more_locales = array('ar_YE','de_LU','en_BZ','en_GY','en_HK','en_IN','en_ZA','es_CU','fr_BE','fr_CH','fr_DZ','fr_GY','fr_LU','fr_PF','fr_SN','pt_MZ','ur_IN','ur_PK');
*
* $_more_locales = array('ar_YE','de_LU','en_BZ','en_GY','en_HK','en_IN','en_ZA','es_CU','fr_BE','fr_CH','fr_DZ','fr_GY','fr_LU','fr_PF','fr_SN','pt_MZ','ur_IN','ur_PK');
* Ersetzt durch das Konfigurationsfeld "localefallback/extra_locales/extra_locale_list"
*/
$extra_locales = Mage::getStoreConfig('localefallback/extra_locales/extra_locale_list');

if (!empty ( $extra_locales ) ) {
$extra_locales = str_replace(";", ",", $extra_locales); // only Comma Not Semicolon
$_more_locales = explode( ',', $extra_locales );
$this->_locales = array_merge($_mage_locales,$_more_locales);
} else {
$this->_locales = $_mage_locales;
}
$extra_locales = str_replace(";", ",", $extra_locales); // only Comma Not Semicolon
$_more_locales = explode( ',', $extra_locales );
$this->_locales = array_merge($_mage_locales,$_more_locales);
} else {
$this->_locales = $_mage_locales;
}
}

return $this->_locales;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,45 @@
* @package German_LocaleFallback
* @authors MaWoScha <mawoscha@siempro.co, http://www.siempro.co/>
* @developer MaWoScha <mawoscha@siempro.co, http://www.siempro.co/>
* @version 0.4.0
* @version 0.5.0
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @source http://github.com/magento-hackathon/Hackathon_LocaleFallback
*/
class German_LocaleFallback_Model_System_Config_Source_Locale
{
public function toOptionArray()
{
$_helper = Mage::helper("localefallback");
$_mage_fallbacks = Mage::app()->getLocale()->getOptionLocales();

/**
* Additional fallback languages
* - ar Arabish
* - en English
* - ur Urdu
$_more_Languages = array('ar', 'en', 'ur');
$_more_fallbacks = array(array('value' => 'ar', 'label' => 'Arabic (ar_AR, Fallback)'), array('value' => 'en', 'label' => 'English (en_EN, Fallback)'), array('value' => 'ur', 'label' => 'Urdu (ur_UR, Fallback)'));
* Ersetzt durch das Konfigurationsfeld "localefallback/extra_locales/extra_fallback_list"
* $_more_languages = array('ar', 'en');
* $_more_fallbacks = array(array('value' => 'ar', 'label' => 'Arabic (ar_AR, Fallback)'), array('value' => 'en', 'label' => 'English (en_EN, Fallback)'));
* Ersetzt durch das Konfigurationsfeld "localefallback/extra_locales/extra_fallback_list"
*/
$_more_fallbacks = array();

$_more_Languages = Mage::getStoreConfig('localefallback/extra_locales/extra_fallback_list');
if (!empty ( $_more_Languages ) ) {
$_more_Languages = str_replace(";", ",", $_more_Languages); // only Comma Not Semicolon
$_more_Languages = explode( ',', $_more_Languages );
$_more_languages = Mage::getStoreConfig('localefallback/extra_locales/extra_fallback_list');
if (!empty ( $_more_languages ) ) {
$_more_languages = str_replace(";", ",", $_more_languages); // only Comma Not Semicolon
$_more_languages = explode( ',', $_more_languages );

$languages = Mage::app()->getLocale()->getTranslationList('language', Mage::app()->getLocale()->getLocaleCode());
$countries = Mage::app()->getLocale()->getCountryTranslationList();
$languages = Mage::app()->getLocale()->getTranslationList('language', Mage::app()->getLocale()->getLocaleCode());
$countries = Mage::app()->getLocale()->getCountryTranslationList();

foreach ($_more_Languages as $code_lang) {
$code = $code_lang.'_'.strtoupper($code_lang);
$label = $languages[$code_lang] . ' (' . $code . ', Fallback)';
$_more_fallbacks[] = array(
'value' => $code,
'label' => $label
);
}
}
foreach ($_more_languages as $code_lang) {
$code = $code_lang . '_' . strtoupper($code_lang);
$label = $languages[$code_lang] . ' (' . $code . ', ' . $_helper->__('Fallback') . ')';
$_more_fallbacks[] = array(
'value' => $code,
'label' => $label
);
}
}

return array_merge(
array(array('value' => '', 'label' => 'Disable')),
Expand Down
72 changes: 55 additions & 17 deletions app/code/community/German/LocaleFallback/Model/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package German_LocaleFallback
* @authors MaWoScha <mawoscha@siempro.co, http://www.siempro.co/>, Bastian Ike <b-ike@b-ike.de>
* @developer MaWoScha <mawoscha@siempro.co, http://www.siempro.co/>, Bastian Ike <b-ike@b-ike.de>
* @version 0.4.1
* @version 0.5.0
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @source http://github.com/magento-hackathon/Hackathon_LocaleFallback
* @source http://github.com/access3000/Hackathon_LocaleFallback
Expand Down Expand Up @@ -40,7 +40,7 @@ protected function _getGettextFileData($file)
* @param bool $forceReload
* @return German_LocaleFallback_Model_Translate
*/
protected function _loadGettextModuleTranslation($moduleName, $files, $forceReload=false)
protected function _loadGettextModuleTranslation($moduleName, $files, $forceReload = false)
{
foreach ($files as $file) {
$temp = pathinfo($file, PATHINFO_EXTENSION);
Expand Down Expand Up @@ -85,7 +85,7 @@ public function init($area, $forceReload = false)
$this->setConfig(array(self::CONFIG_KEY_AREA => $area));

$this->_translateInline = Mage::getSingleton('core/translate_inline')
->isAllowed($area=='adminhtml' ? 'admin' : null);
->isAllowed($area == 'adminhtml' ? 'admin' : null);

if (!$forceReload) {
if ($this->_canUseCache()) {
Expand All @@ -99,15 +99,25 @@ public function init($area, $forceReload = false)

$this->_data = array();

/** START - Bastian Ike */
if (!Mage::app()->getStore()->isAdmin() && $localeFallback = Mage::getStoreConfig('general/locale/code_fallback')) {
/** START - MaWoScha */
$localePreferred = Mage::getStoreConfig('general/locale/code');
$localeFallback = Mage::getStoreConfig('general/locale/code_fallback');
$localeCustom = '';
if (strstr($localePreferred, '_')) {
$data = explode('_', $localePreferred);
$localeCustom = $data[0] . '_ZZ';
}
/** END - MaWoScha */

/** START - Bastian Ike */
if (!Mage::app()->getStore()->isAdmin() && !empty($localeFallback)) {
// save original locale
$tmp_locale_original = $this->getLocale();

// set locale fallback
$this->setLocale($localeFallback);
// set global locale to fallback locale
Mage::getSingleton('core/locale')->setLocale($localeFallback); /* by access3000 */
Mage::getSingleton('core/locale')->setLocale($localeFallback); /* by access3000 */

// load translations as usual
foreach ($this->getModulesConfig() as $moduleName => $info) {
Expand All @@ -123,18 +133,46 @@ public function init($area, $forceReload = false)
// restore original locale
$this->setLocale($tmp_locale_original);
// restore global original locale
Mage::getSingleton('core/locale')->setLocale($tmp_locale_original); /* by access3000 */
Mage::getSingleton('core/locale')->setLocale($tmp_locale_original); /* by access3000 */
}
/** END - Bastian Ike */
/** END - Bastian Ike */

foreach ($this->getModulesConfig() as $moduleName => $info) {
$info = $info->asArray();
$this->_loadModuleTranslation($moduleName, $info['files'], $forceReload);
$this->_loadGettextModuleTranslation($moduleName, $info['files'], $forceReload); /* Bastian Ike */
$this->_loadGettextModuleTranslation($moduleName, $info['files'], $forceReload); /* Bastian Ike */
}

/** START - MaWoScha */
if (!empty($localeCustom)) {
// save original locale
$tmp_locale_original = $this->getLocale();

// set locale fallback
$this->setLocale($localeCustom);
// set global locale to fallback locale
Mage::getSingleton('core/locale')->setLocale($localeCustom);

// load translations as usual
foreach ($this->getModulesConfig() as $moduleName => $info) {
$info = $info->asArray();
$this->_loadModuleTranslation($moduleName, $info['files'], $forceReload);
$this->_loadGettextModuleTranslation($moduleName, $info['files'], $forceReload);
}

$this->_loadThemeTranslation($forceReload);
$this->_loadGettextTranslation($forceReload);
$this->_loadDbTranslation($forceReload);

// restore original locale
$this->setLocale($tmp_locale_original);
// restore global original locale
Mage::getSingleton('core/locale')->setLocale($tmp_locale_original);
}
/** END - MaWoScha */

$this->_loadThemeTranslation($forceReload);
$this->_loadGettextTranslation($forceReload); /* Bastian Ike */
$this->_loadGettextTranslation($forceReload); /* Bastian Ike */
$this->_loadDbTranslation($forceReload);

if (!$forceReload && $this->_canUseCache()) {
Expand All @@ -154,22 +192,22 @@ public function init($area, $forceReload = false)
* @param string $localeCode
* @return string
*/
public function getTemplateFile($file, $type, $localeCode=null)
public function getTemplateFile($file, $type, $localeCode = null)
{
if (is_null($localeCode) || preg_match('/[^a-zA-Z_]/', $localeCode)) {
$localeCode = $this->getLocale();
}

$filePath = Mage::getBaseDir('locale') . DS
$filePath = Mage::getBaseDir('locale') . DS
. $localeCode . DS . 'template' . DS . $type . DS . $file;

/** START - MaWoScha */
/** START - MaWoScha */
if (!file_exists($filePath)) { // If template doesn't exist for this locale, use fallback locale
$filePath = Mage::getBaseDir('locale') . DS
. Mage::getStoreConfig('general/locale/code_fallback')
. DS . 'template' . DS . $type . DS . $file;
}
/** END - MaWoScha */
/** END - MaWoScha */

if (!file_exists($filePath)) { // If template doesn't exist for fallback locale, use store default
$filePath = Mage::getBaseDir('locale') . DS
Expand Down Expand Up @@ -205,7 +243,7 @@ public function fetchTranslation($locale)
$tmp_locale_original = $this->getLocale();

$this->setLocale($locale);
Mage::getSingleton('core/locale')->setLocale($locale); /* by access3000 */
Mage::getSingleton('core/locale')->setLocale($locale); /* by access3000 */

$this->_data = array();
foreach ($this->getModulesConfig() as $moduleName => $info) {
Expand All @@ -218,9 +256,9 @@ public function fetchTranslation($locale)
$this->_loadDbTranslation(false);

// restore original locale
$this->setLocale($tmp_locale_original); /* by access3000 */
$this->setLocale($tmp_locale_original); /* by access3000 */
// restore global original locale
Mage::getSingleton('core/locale')->setLocale($tmp_locale_original); /* by access3000 */
Mage::getSingleton('core/locale')->setLocale($tmp_locale_original); /* by access3000 */

return $this->getData();
}
Expand Down
Loading

0 comments on commit 2239814

Please sign in to comment.