Skip to content

Commit

Permalink
Version 0.4.0, Fallback locale now takes effect also on email templates
Browse files Browse the repository at this point in the history
  • Loading branch information
MaWoScha committed Feb 14, 2015
1 parent dfba4cc commit 87efc65
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ Now you can individually expand the list of locales and fallbacks.
Einige Einstellmöglichkeiten wurden ergänzt.

Nun können Sie individuell die Liste der Sprachumgebungen und Ausweichsprachen erweitern.

v0.4.0

The fallback locale has now also effect on email templates.

Die Ausweichsprache greift nun auch bei den E-Mail-Vorlagen.
58 changes: 55 additions & 3 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.2.0
* @version 0.4.0
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @source http://github.com/magento-hackathon/Hackathon_LocaleFallback
*/
Expand Down Expand Up @@ -33,6 +33,7 @@ protected function _getGettextFileData($file)
/**
* iterates thru files, replaces .csv with .mo and tries to load the gettext translation
*
* @autor Bastian Ike <b-ike@b-ike.de>
* @param string $moduleName
* @param array $files
* @param bool $forceReload
Expand All @@ -55,6 +56,7 @@ protected function _loadGettextModuleTranslation($moduleName, $files, $forceRelo
/**
* loads design locale gettext file
*
* @autor Bastian Ike <b-ike@b-ike.de>
* @param bool $forceReload
* @return German_LocaleFallback_Model_Translate
*/
Expand All @@ -72,6 +74,7 @@ private function _loadGettextTranslation($forceReload)
* rewritten to add gettext
* gettext is loaded after .csv-files!
*
* @modified_by Bastian Ike <b-ike@b-ike.de>
* @param string $area
* @param boolean $forceReload
* @return German_LocaleFallback_Model_Translate
Expand All @@ -95,6 +98,7 @@ public function init($area, $forceReload = false)

$this->_data = array();

/** START - Bastian Ike */
if ($localeFallback = Mage::getStoreConfig('general/locale/code_fallback')) {
// save original locale
$tmp_locale_original = $this->getLocale();
Expand All @@ -116,15 +120,16 @@ public function init($area, $forceReload = false)
// restore original locale
$this->setLocale($tmp_locale_original);
}
/** END - Bastian Ike */

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

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

if (!$forceReload && $this->_canUseCache()) {
Expand All @@ -134,9 +139,56 @@ public function init($area, $forceReload = false)
return $this;
}

/**
* Retrive translated template file
* line 460 in Mage_Core_Model_Translate
*
* @modified_by MaWoScha <mawoscha@siempro.co>
* @param string $file
* @param string $type
* @param string $localeCode
* @return string
*/
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
. $localeCode . DS . 'template' . DS . $type . DS . $file;

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

if (!file_exists($filePath)) { // If no template specified for this locale, use store default
$filePath = Mage::getBaseDir('locale') . DS
. Mage::app()->getLocale()->getDefaultLocale()
. DS . 'template' . DS . $type . DS . $file;
}

if (!file_exists($filePath)) { // If no template specified as store default locale, use en_US
$filePath = Mage::getBaseDir('locale') . DS
. Mage_Core_Model_Locale::DEFAULT_LOCALE
. DS . 'template' . DS . $type . DS . $file;
}

$ioAdapter = new Varien_Io_File();
$ioAdapter->open(array('path' => Mage::getBaseDir('locale')));

return (string) $ioAdapter->read($filePath);
}

/**
* Load Translation for specific locale and return translation data
* Used in: German_LocaleFallback_Model_Observer
*
* @autor Bastian Ike <b-ike@b-ike.de>
* @param $locale
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/German/LocaleFallback/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<config>
<modules>
<German_LocaleFallback>
<version>0.3.2</version>
<version>0.4.0</version>
<title>Locale Fallback</title>
<link_git>https://github.com/MaWoScha/German_LocaleFallback</link_git>
</German_LocaleFallback>
Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"name": "magento-german/localefallback",
"name": "mawoscha/german-localefallback",
"license": "OSL-3.0",
"type": "magento-module",
"description": "Allows a fallback for locales (translations, emails etc.)",
"authors":[
{
"name":"Bastian Ike"
},
{
"name":"MaWoScha"
}
],
"homepage": "https://github.com/MaWoScha/German_LocaleFallback",
"require": {
"magento-german/magento-composer-installer": "*"
Expand Down
2 changes: 1 addition & 1 deletion var/connect/German_LocaleFallback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Complemento de paquetes de idioma para Magento Commerce
* Definido además de la configuración regional un idioma de segunda opción</description>
<license>OSL</license>
<license_uri>http://www.opensource.org/licenses/osl-3.0.php</license_uri>
<version>0.3.2</version>
<version>0.4.0</version>
<stability>stable</stability>
<notes>none/keine</notes>
<authors>
Expand Down

0 comments on commit 87efc65

Please sign in to comment.