<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[GlotPress][857] trunk: Escape double quotes for .strings exports.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://glotpress.trac.wordpress.org/changeset/857">857</a></dd>
<dt>Author</dt> <dd>markoheijnen</dd>
<dt>Date</dt> <dd>2014-03-08 17:50:52 +0000 (Sat, 08 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Escape double quotes for .strings exports. Adds unit tests what still fails due some EOL weirdness. See <a href="http://glotpress.trac.wordpress.org/ticket/296">#296</a> </pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgpincludesformatsformat_stringsphp">trunk/gp-includes/formats/format_strings.php</a></li>
<li><a href="#trunktdatatranslationstrings">trunk/t/data/translation.strings</a></li>
<li><a href="#trunktteststest_format_stringsphp">trunk/t/tests/test_format_strings.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgpincludesformatsformat_stringsphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/formats/format_strings.php (856 => 857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/formats/format_strings.php     2014-03-08 16:27:04 UTC (rev 856)
+++ trunk/gp-includes/formats/format_strings.php        2014-03-08 17:50:52 UTC (rev 857)
</span><span class="lines">@@ -20,13 +20,19 @@
</span><span class="cx"> 
</span><span class="cx">          $sorted_entries = $entries;
</span><span class="cx">          usort( $sorted_entries, array( 'GP_Format_Strings', 'sort_entries' ) );
</span><ins>+
</ins><span class="cx">           foreach ( $sorted_entries as $entry ) {
</span><ins>+                       $entry->context = addcslashes( $entry->context, '"\\/');
+                       $translation = empty( $entry->translations ) ? $entry->context : addcslashes( $entry->translations[0], '"\\/');
+
</ins><span class="cx">                   $original = str_replace( "\n", "\\n", $entry->context );
</span><del>-                       $translation = str_replace( "\n", "\\n", empty( $entry->translations ) ? $entry->context : $entry->translations[0] );
</del><ins>+                        $translation = str_replace( "\n", "\\n", $translation );
</ins><span class="cx">                   $comment = preg_replace( "/(^\s+)|(\s+$)/us", "", $entry->extracted_comments );
</span><ins>+
</ins><span class="cx">                   if ( $comment == "" ) {
</span><span class="cx">                          $comment = "No comment provided by engineer.";
</span><span class="cx">                  }
</span><ins>+
</ins><span class="cx">                   $result .= "/* $comment */\n\"$original\" = \"$translation\";\n\n";
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="lines">@@ -111,4 +117,4 @@
</span><span class="cx">  }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-GP::$formats['strings'] = new GP_Format_Strings;
</del><span class="cx">\ No newline at end of file
</span><ins>+GP::$formats['strings'] = new GP_Format_Strings;
</ins></span></pre></div>
<a id="trunktdatatranslationstrings"></a>
<div class="binary"><h4>Modified: trunk/t/data/translation.strings</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<a id="trunktteststest_format_stringsphp"></a>
<div class="modfile"><h4>Modified: trunk/t/tests/test_format_strings.php (856 => 857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/tests/test_format_strings.php    2014-03-08 16:27:04 UTC (rev 856)
+++ trunk/t/tests/test_format_strings.php       2014-03-08 17:50:52 UTC (rev 857)
</span><span class="lines">@@ -17,6 +17,29 @@
</span><span class="cx">          );
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       function test_export() {
+               $entries_for_export = array();
+
+               foreach( $this->entries as $sample ) {
+                       list( $context, $original, $translation, $comment ) = $sample;
+
+                       $entries_for_export[] = (object)array(
+                               'context' => $context,
+                               'singular' => $original,
+                               'translations' => array($translation),
+                               'extracted_comments' => $comment,
+                       );
+               }
+
+               $file     = file_get_contents( 'data/translation.strings' );
+               $exported = $this->strings->print_exported_file( 'p', 'l', 't', $entries_for_export );
+
+               $file     = mb_convert_encoding( $file, 'UTF-8', 'UTF-16LE' );
+               $exported = mb_convert_encoding( $exported, 'UTF-8', 'UTF-16LE' );
+
+               $this->assertEquals( $file, $exported );
+       }
+
</ins><span class="cx">   function test_read_originals() {
</span><span class="cx">          $translations = $this->strings->read_originals_from_file( 'data/originals.utf16le.strings' );
</span><span class="cx">          $this->assertEquals( count( $this->entries ), count( $translations->entries ), 'number of read originals is different from the expected' );
</span></span></pre>
</div>
</div>

</body>
</html>