├── modman ├── README.md ├── src └── app │ ├── etc │ └── modules │ │ └── AvS_MissingTranslations.xml │ ├── locale │ └── de_DE │ │ └── AvS_MissingTranslations.csv │ └── code │ └── community │ └── AvS │ └── MissingTranslations │ ├── etc │ ├── config.xml │ └── system.xml │ └── Model │ └── Translate.php └── composer.json /modman: -------------------------------------------------------------------------------- 1 | src/app/etc/modules/* app/etc/modules/ 2 | src/app/code/community/AvS/* app/code/community/AvS/ 3 | src/app/locale/de_DE/* app/locale/de_DE/ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AvS_MissingTranslations 2 | ======================= 3 | 4 | Logs translations which are not included in any csv file nor in the database and writes them to csv format -------------------------------------------------------------------------------- /src/app/etc/modules/AvS_MissingTranslations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | community 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "avstudnitz/missing-translations", 3 | "type": "magento-module", 4 | "description": "Logs translations which are not included in any csv file nor in the database and writes them to csv format", 5 | "homepage": "https://github.com/avstudnitz/AvS_MissingTranslations", 6 | "suggest": { 7 | "magento-hackathon/magento-composer-installer": "*" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/app/locale/de_DE/AvS_MissingTranslations.csv: -------------------------------------------------------------------------------- 1 | "Missing Translations","Fehlende Übersetzungen" 2 | "Log Missing Frontend Translations","Fehlende Frontend-Übersetzungen loggen" 3 | "Log files can be found at var/translation_log/frontend/","Log-Dateien befinden sich unter var/translation_log/frontend/" 4 | "Log Missing Admin Translations","Fehlende Admin-Übersetzungen loggen" 5 | "Log files can be found at var/translation_log/adminhtml/","Log-Dateien befinden sich unter var/translation_log/adminhtml/" -------------------------------------------------------------------------------- /src/app/code/community/AvS/MissingTranslations/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.1.0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | AvS_MissingTranslations_Model_Translate 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | AvS_MissingTranslations.csv 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/app/code/community/AvS/MissingTranslations/etc/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 35 9 | 1 10 | 1 11 | 1 12 | 13 | 14 | 15 | Log files can be found at var/translation_log/frontend/ 16 | select 17 | adminhtml/system_config_source_yesno 18 | 10 19 | 1 20 | 1 21 | 1 22 | 23 | 24 | 25 | Log files can be found at var/translation_log/adminhtml/ 26 | select 27 | adminhtml/system_config_source_yesno 28 | 20 29 | 1 30 | 0 31 | 0 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/app/code/community/AvS/MissingTranslations/Model/Translate.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class AvS_MissingTranslations_Model_Translate extends Mage_Core_Model_Translate 8 | { 9 | /** 10 | * Return translated string from text. 11 | * 12 | * @param string $text 13 | * @param string $code 14 | * @return string 15 | */ 16 | protected function _getTranslatedString($text, $code) 17 | { 18 | $translated = ''; 19 | if (array_key_exists($code, $this->getData())) { 20 | $translated = $this->_data[$code]; 21 | } 22 | elseif (array_key_exists($text, $this->getData())) { 23 | $translated = $this->_data[$text]; 24 | } 25 | else { 26 | $translated = $text; 27 | $this->_logMissingTranslation($text, $code); 28 | } 29 | return $translated; 30 | } 31 | 32 | /** 33 | * Write missing translations to csv file 34 | * 35 | * @param string $text 36 | * @param string $code 37 | */ 38 | protected function _logMissingTranslation($text, $code) 39 | { 40 | $area = Mage::getDesign()->getArea(); // frontend or adminhtml 41 | 42 | if (!Mage::getStoreConfigFlag('dev/missing_translations/' . $area)) return; 43 | 44 | $langCode = Mage::app()->getLocale()->getLocaleCode(); // i.e. de_DE 45 | 46 | $code = str_replace('"', '""', $code); 47 | $text = str_replace('"', '""', $text); 48 | 49 | try { 50 | $dirname = $this->_getDirName($area); 51 | 52 | $filename = $dirname . $langCode . '.csv'; 53 | 54 | $file = fopen($filename, 'a+'); 55 | 56 | // check if line already exists in file 57 | if ($this->_isInFile($file, $code)) { 58 | fclose($file); 59 | return; 60 | } 61 | 62 | // add new line 63 | fwrite($file, '"' . $code . '","' . $text . '"' . "\n"); 64 | fclose($file); 65 | 66 | } catch (Exception $e) { 67 | Mage::logException($e); 68 | } 69 | } 70 | 71 | /** 72 | * Checks if $code string is already in file $file (first csv column) 73 | * 74 | * @param resource $file 75 | * @param string $code 76 | * @return bool 77 | */ 78 | protected function _isInFile($file, $code) 79 | { 80 | while (($line = fgets($file)) !== false) { 81 | $translation = str_getcsv($line); 82 | if (is_array($translation) && isset($translation[0]) && $translation[0] == $code) { 83 | return true; 84 | } 85 | } 86 | return false; 87 | } 88 | 89 | /** 90 | * Get directory where log files should be saved; create if necessary 91 | * 92 | * @param string $area 93 | * @return string 94 | */ 95 | protected function _getDirName($area) 96 | { 97 | $dirname = Mage::getBaseDir('var') . DS . 'translation_log' . DS . $area . DS; 98 | if (!is_dir($dirname)) { 99 | mkdir($dirname, 0777, true); 100 | } 101 | return $dirname; 102 | } 103 | } 104 | --------------------------------------------------------------------------------