static function translate($locale_code, $module_name, $key, $replace = null, $do_translation = true) { // DON'T EVER LEAVE THIS UNCOMMENTED // ob_clean(); // can be useful for debugging since using dd() will dump out into the existing markup and be hard to see // but this clears out all the other markup so the debug data can be seen clearly $translation = $key; if ($do_translation) { if (Bolts_Registry::get('enable_localization') == '1' && !is_null($module_name) && trim($module_name) != "" && !is_null($key) && trim($key) != "") { $locale_code = Bolts_Translate::cleanZendLocaleCode($locale_code); $path_to_csv = Bolts_Registry::get('basepath') . "/modules/" . $module_name . "/languages/" . $locale_code . ".csv"; if (file_exists($path_to_csv)) { try { $translate = new Zend_Translate("csv", $path_to_csv, $locale_code, array('delimiter' => ",")); $translation = $translate->_($key); // this next bit will populate the locale file with untranslated terms // so it's easier for someone to go through and translate them if (Bolts_Registry::get('auto_populate_language_files') == '1') { if (!$translate->isTranslated($key, true, $locale_code)) { $key_no_quotes = str_replace('"', '"', $key); $str = '"' . $key_no_quotes . '","' . $key_no_quotes . '"' . "\n"; file_put_contents($path_to_csv, $str, FILE_APPEND); } } } catch (Exception $e) { $translation = $key; } } else { // create the file file_put_contents($path_to_csv, $key . ',' . $key); } } } $output = ""; if (is_null($replace)) { // no replace, no sprintf $output = $translation; } else { if (is_array($replace)) { if (count($replace) > 1) { // there are multiple indices, use vsprintf $output = vsprintf($translation, $replace); } else { // there's only one index, use the cheaper sprintf instead $output = sprintf($translation, $replace[0]); } } else { // $replace is not an array, so try using it straight $output = sprintf($translation, $replace); } } return $output; }