Codestyling localization plugin fix
| February 8, 2011 | Posted by Ivan under Other plugins and themes |
The Codestyling localization is the great plugin that helps theme and plugin translators greatly. This is really the best plugin ever for translators.
Unfortunately it has one very annoying bug on my web-server configuration – it cannot deal with quotas and “\n” sequence. The plugin adds additional slashes before the symbols.
I don’t know if this is something specific on my web-server or it happens everywhere (I tested two different servers), but it shouldn’t happen anyway. I’ve written to the author but will he fix it? Anyway I fixed the bugs.
Important: I don’t guarantee that this fix will work everywhere, it just works for me and if you have similar problems, you can try it.
So the fix is:
1. in codestyling-localization.php add to the beginning of csp_po_ajax_handle_save_catalog_entry function the line:
function csp_po_ajax_handle_save_catalog_entry() { $_POST['msgstr'] = stripslashes($_POST['msgstr']);// ADD THIS LINE
2.In class-translationfile.php change two functions:
function _convert_for_js($str) { //$search = array( '"\"', "\\", "\n", "\r", "\t", "\""); //$replace = array( '"\\\\"', '\\\\', '\\\\n', '\\\\r', '\\\\t', '\\\\\"'); $search = array( '"\"', "\\", "\n", "\r", "\t", '"'); $replace = array( '"\\\\"', '\\\\', '\\\\n', '\\\\r', '\\\\t', '\\' .'"'); $str = str_replace( $search, $replace, $str ); return $str; } function _convert_js_input($str) { //$search = array('\\\\\\\"', '\\\\\"','\\\\n', '\\\\t','\\0', "\\'", '\\\\'); //old //$replace = array('\"', '"', "\n", "\\t", "\0", "'", "\\");//old $search = array('\\"', '\\\\\"','\\\\n', '\\\\t','\\0', "\\'", '\\\\'); $replace = array('"', '"', "\n", "\\t", "\0", "'", "\\"); $str = str_replace( $search, $replace, $str ); return $str; }
This will fix slashes with quotes.
To fix slashes with “\n”:
3 .In class-translationfile.php to the end of function _clean_export add one line:
$po = str_replace("$newline$quote$quote", '', $po);
$po = str_replace('\\'.'\\'.'n', '\\'.'n', $po); // ADD THIS LINE
return $po;
That’s all

Very cool. Thanks for the great share of info.