<!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][1032] trunk: On import, detect when a string has minor changes and keep the original translations.</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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://glotpress.trac.wordpress.org/changeset/1032">1032</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://glotpress.trac.wordpress.org/changeset/1032","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-05-01 15:12:09 +0000 (Fri, 01 May 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>On import, detect when a string has minor changes and keep the original translations. Existing translations will be marked as fuzzy.
props yoavf.
fixes <a href="http://glotpress.trac.wordpress.org/ticket/263">#263</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgpincludesroutesprojectphp">trunk/gp-includes/routes/project.php</a></li>
<li><a href="#trunkgpincludesthingsoriginalphp">trunk/gp-includes/things/original.php</a></li>
<li><a href="#trunkscriptsimportoriginalsphp">trunk/scripts/import-originals.php</a></li>
<li><a href="#trunktteststests_thingstest_thing_originalphp">trunk/t/tests/tests_things/test_thing_original.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgpincludesroutesprojectphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/gp-includes/routes/project.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/gp-includes/routes/project.php 2015-04-30 10:04:00 UTC (rev 1031)
+++ trunk/gp-includes/routes/project.php 2015-05-01 15:12:09 UTC (rev 1032)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -110,8 +110,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- list( $originals_added, $originals_existing ) = GP::$original->import_for_project( $project, $translations );
- $this->notices[] = sprintf(__("%s new strings were added, %s existing were updated."), $originals_added, $originals_existing );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ list( $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted ) = GP::$original->import_for_project( $project, $translations );
+ $this->notices[] = sprintf(
+ __( '%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.' ),
+ $originals_added,
+ $originals_existing,
+ $originals_fuzzied,
+ $originals_obsoleted
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->redirect( gp_url_project( $project, 'import-originals' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunkgpincludesthingsoriginalphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/gp-includes/things/original.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/gp-includes/things/original.php 2015-04-30 10:04:00 UTC (rev 1031)
+++ trunk/gp-includes/things/original.php 2015-05-01 15:12:09 UTC (rev 1032)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,7 +5,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var $field_names = array( 'id', 'project_id', 'context', 'singular', 'plural', 'references', 'comment', 'status', 'priority', 'date_added' );
</span><span class="cx" style="display: block; padding: 0 10px"> var $non_updatable_attributes = array( 'id', 'path' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- static $priorities = array( '-2' => 'hidden', '-1' => 'low', '0' => 'normal', '1' => 'high' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static $priorities = array( '-2' => 'hidden', '-1' => 'low', '0' => 'normal', '1' => 'high' );
</ins><span class="cx" style="display: block; padding: 0 10px"> static $count_cache_group = 'active_originals_count_by_project_id';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function restrict_fields( $original ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -51,8 +51,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function by_project_id_and_entry( $project_id, $entry, $status = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $gpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $entry->plural = isset( $entry->plural ) ? $entry->plural : null;
- $entry->context = isset( $entry->context ) ? $entry->context : null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $entry->plural = isset( $entry->plural ) ? $entry->plural : null;
+ $entry->context = isset( $entry->context ) ? $entry->context : null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $where = array();
</span><span class="cx" style="display: block; padding: 0 10px"> // now each condition has to contain a %s not to break the sequence
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -74,67 +74,188 @@
</span><span class="cx" style="display: block; padding: 0 10px"> global $gpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $project->id, self::$count_cache_group );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $originals_added = $originals_existing = $originals_obsoleted = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $originals_added = $originals_existing = $originals_obsoleted = $originals_fuzzied = 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $all_originals_for_project = $this->many_no_map( "SELECT * FROM $this->table WHERE project_id= %d", $project->id );
</span><span class="cx" style="display: block; padding: 0 10px"> $originals_by_key = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach( $all_originals_for_project as $original ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $entry = new Translation_Entry( array( 'singular' => $original->singular, 'plural' => $original->plural, 'context' => $original->context ) );
- $originals_by_key[$entry->key()] = $original;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $entry = new Translation_Entry( array(
+ 'singular' => $original->singular,
+ 'plural' => $original->plural,
+ 'context' => $original->context
+ ) );
+ $originals_by_key[ $entry->key() ] = $original;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $obsolete_originals = array_filter( $originals_by_key, function( $entry ) {
+ return ( '-obsolete' == $entry->status );
+ } );
+
+ $possibly_added = $possibly_dropped = array();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach( $translations->entries as $entry ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $gpdb->queries = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = array('project_id' => $project->id, 'context' => $entry->context, 'singular' => $entry->singular,
- 'plural' => $entry->plural, 'comment' => $entry->extracted_comments,
- 'references' => implode( ' ', $entry->references ), 'status' => '+active' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = array(
+ 'project_id' => $project->id,
+ 'context' => $entry->context,
+ 'singular' => $entry->singular,
+ 'plural' => $entry->plural,
+ 'comment' => $entry->extracted_comments,
+ 'references' => implode( ' ', $entry->references ),
+ 'status' => '+active'
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = apply_filters( 'import_original_array', $data );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO: do not obsolete similar translations
- if ( isset( $originals_by_key[$entry->key()] ) ) {
- $original = $originals_by_key[$entry->key()];
-
- if ( GP::$original->is_different_from( $data, $original ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Original exists, let's update it.
+ if ( isset( $originals_by_key[ $entry->key() ] ) ) {
+ $original = $originals_by_key[ $entry->key() ];
+ if ( $original->status == '-obsolete' || GP::$original->should_be_updated_with( $data, $original ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->update( $data, array( 'id' => $original->id ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $originals_existing++;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
+ // We can't find this in our originals. Let's keep it for later.
+ $possibly_added[] = $entry;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
+ // Mark missing strings as possible removals.
+ foreach ( $originals_by_key as $key => $value) {
+ if ( $value->status != '-obsolete' && is_array( $translations->entries ) && ! array_key_exists( $key, $translations->entries ) ) {
+ $possibly_dropped[ $key ] = $value;
+ }
+ }
+ $comparison_array = array_unique( array_merge( array_keys( $possibly_dropped ), array_keys( $obsolete_originals ) ) );
+
+ foreach ( $possibly_added as $entry ) {
+ $data = array(
+ 'project_id' => $project->id,
+ 'context' => $entry->context,
+ 'singular' => $entry->singular,
+ 'plural' => $entry->plural,
+ 'comment' => $entry->extracted_comments,
+ 'references' => implode( ' ', $entry->references ),
+ 'status' => '+active'
+ );
+ $data = apply_filters( 'import_original_array', $data );
+
+ // Search for match in the dropped strings and existing obsolete strings.
+ $close_original = $this->closest_original( $entry->key(), $comparison_array );
+
+ // We found a match - probably a slightly changed string.
+ if ( $close_original ) {
+ $original = $originals_by_key[ $close_original ];
+
+ // We'll update the old original...
+ $this->update( $data, array( 'id' => $original->id ) );
+
+ // and set existing translations to fuzzy.
+ $this->set_translations_for_original_to_fuzzy( $original->id );
+
+ // No need to obsolete it now.
+ unset( $possibly_dropped[ $close_original ] );
+
+ $originals_fuzzied++;
+ continue;
+ } else { // Completely new string
</ins><span class="cx" style="display: block; padding: 0 10px"> GP::$original->create( $data );
</span><span class="cx" style="display: block; padding: 0 10px"> $originals_added++;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Mark previously active, but now removed strings as obsolete
- foreach ( $originals_by_key as $key => $value) {
- if ( ! key_exists( $key, $translations->entries ) && '-obsolete' != $value->status ) {
- $this->update( array('status' => '-obsolete'), array( 'id' => $value->id ) );
- $originals_obsoleted++;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Mark remaining possibly dropped strings as obsolete.
+ foreach ( $possibly_dropped as $key => $value) {
+ $this->update( array( 'status' => '-obsolete' ), array( 'id' => $value->id ) );
+ $originals_obsoleted++;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Clear cache when the amount of strings are changed
- if ( $originals_added > 0 || $originals_obsoleted > 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Clear cache when the amount of strings are changed.
+ if ( $originals_added > 0 || $originals_fuzzied > 0 || $originals_obsoleted > 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> gp_clean_translation_sets_cache( $project->id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( 'originals_imported', $project->id, $originals_added, $originals_existing, $originals_obsoleted );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'originals_imported', $project->id, $originals_added, $originals_existing, $originals_obsoleted, $originals_fuzzied );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return array( $originals_added, $originals_existing );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return array( $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function set_translations_for_original_to_fuzzy( $original_id ) {
+ $translations = GP::$translation->find_many( "original_id = '$original_id' AND status = 'current'" );
+ foreach ( $translations as $translation ) {
+ $translation->set_status( 'fuzzy' );
+ }
+ }
+
+ function should_be_updated_with( $data, $original = null ) {
+ if ( ! $original ) {
+ $original = $this;
+ }
+
+ foreach ( $data as $field => $value ) {
+ if ( $original->$field != $value ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function is_different_from( $data, $original = null ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !$original ) $original = $this;
- foreach( $data as $field => $value ) {
- if ( $original->$field != $value ) return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $original ) {
+ $original = $this;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ foreach ( $data as $field => $value ) {
+ if ( $original->$field != $value ) {
+ return true;
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function priority_by_name( $name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $by_name = array_flip( self::$priorities );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return isset( $by_name[$name] )? $by_name[$name] : null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return isset( $by_name[ $name ] )? $by_name[ $name ] : null;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ function closest_original( $input, $other_strings ) {
+ if ( empty( $other_strings ) ) {
+ return null;
+ }
+
+ $input_length = gp_strlen( $input );
+ $closest_similarity = 0;
+
+ foreach ( $other_strings as $compared_string ) {
+ $compared_string_length = gp_strlen( $compared_string );
+ $max_length_diff = apply_filters( 'gp_original_import_max_length_diff', 0.5 );
+
+ if ( abs( ( $input_length - $compared_string_length ) / $input_length ) > $max_length_diff ) {
+ continue;
+ }
+
+ $similarity = gp_string_similarity( $input, $compared_string );
+
+ if ( $similarity > $closest_similarity ) {
+ $closest = $compared_string;
+ $closest_similarity = $similarity;
+ }
+ }
+
+ if ( ! isset( $closest ) ) {
+ return null;
+ }
+
+ $min_score = apply_filters( 'gp_original_import_min_similarity_diff', 0.8 );
+ $close_enough = ( $closest_similarity > $min_score );
+
+ do_action( 'post_string_similiary_test', $input, $closest, $closest_similarity, $close_enough );
+
+ if ( $close_enough ) {
+ return $closest;
+ } else {
+ return null;
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> GP::$original = new GP_Original();
</span></span></pre></div>
<a id="trunkscriptsimportoriginalsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/scripts/import-originals.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/scripts/import-originals.php 2015-04-30 10:04:00 UTC (rev 1031)
+++ trunk/scripts/import-originals.php 2015-05-01 15:12:09 UTC (rev 1032)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -22,8 +22,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->error( __("Couldn't load translations from file!") );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- list( $originals_added, $originals_existing ) = GP::$original->import_for_project( $project, $translations );
- echo sprintf( __("%s new strings were added, %s existing were updated."), $originals_added, $originals_existing )."\n";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ list( $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted ) = GP::$original->import_for_project( $project, $translations );
+ printf(
+ __( '%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.' ),
+ $originals_added,
+ $originals_existing,
+ $originals_fuzzied,
+ $originals_obsoleted
+ );
+ echo "\n";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktteststests_thingstest_thing_originalphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/t/tests/tests_things/test_thing_original.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/t/tests/tests_things/test_thing_original.php 2015-04-30 10:04:00 UTC (rev 1031)
+++ trunk/t/tests/tests_things/test_thing_original.php 2015-05-01 15:12:09 UTC (rev 1032)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -73,6 +73,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'baba', $originals_for_project[0]->singular );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_import_should_mark_translation_of_changed_strings_as_fuzzy() {
+ $set = $this->factory->translation_set->create_with_project_and_locale();
+ $original = $this->factory->original->create( array( 'project_id' => $set->project->id, 'status' => '+active', 'singular' => 'baba baba' ) );
+ $translation = $this->factory->translation->create( array( 'translation_set_id' => $set->id, 'original_id' => $original->id, 'status' => 'current' ) );
+ $translations_for_import = $this->create_translations_with( array( array( 'singular' => 'baba baba.' ) ) );
+
+ list( $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted ) = $original->import_for_project( $set->project, $translations_for_import );
+
+ $this->assertEquals( 0, $originals_added );
+ $this->assertEquals( 0, $originals_existing );
+ $this->assertEquals( 1, $originals_fuzzied );
+ $this->assertEquals( 0, $originals_obsoleted );
+
+ $current_translations = GP::$translation->find_many( "original_id = '{$original->id}' AND status = 'current'" );
+ $fuzzy_translations = GP::$translation->find_many( "original_id = '{$original->id}' AND status = 'fuzzy'" );
+
+ $this->assertEquals( 0, count( $current_translations ) );
+ $this->assertEquals( 1, count( $fuzzy_translations ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_import_should_remove_from_active_missing_strings() {
</span><span class="cx" style="display: block; padding: 0 10px"> $project = $this->factory->project->create();
</span><span class="cx" style="display: block; padding: 0 10px"> $original = $this->factory->original->create( array( 'project_id' => $project->id, 'status' => '+active' ) );
</span></span></pre>
</div>
</div>
</body>
</html>