Index: class-plugin-i18n.php
===================================================================
--- class-plugin-i18n.php	(revision 7873)
+++ class-plugin-i18n.php	(working copy)
@@ -368,84 +368,102 @@ class Plugin_I18n {
 		$post->stable_tag = get_post_meta( $post->ID, 'stable_tag', true ) ?: 'trunk';
 
 		if ( empty( $slug ) ) {
 			return $content;
 		}
 
 		$branch = ( empty( $post->stable_tag ) || 'trunk' === $post->stable_tag ) ? 'dev' : 'stable';
 
 		if ( empty( $args['code_i18n'] ) || true !== $args['code_i18n'] ) {
 			$branch .= '-readme';
 		}
 
 		$cache_suffix = "{$locale}:{$key}";
 
 		// Try the cache.
-		if ( false !== ( $cache = $this->cache_get( $slug, $branch, $cache_suffix ) ) ) {
+		// TODO reenable
+		/* if ( false !== ( $cache = $this->cache_get( $slug, $branch, $cache_suffix ) ) ) {
 			// DEBUG
-			// var_dump( array( $slug, $branch, $cache_suffix, $cache ) );
+			var_dump( array( $slug, $branch, $cache_suffix, $cache ) );
 			return $cache;
-		}
+		}*/
 
 		$originals = $this->get_gp_originals( $slug, $branch, $key, $content );
 
 		if ( empty( $originals ) ) {
 			return $content;
 		}
 
 		$translation_set_id = $this->get_gp_translation_set_id( $slug, $branch, $locale );
 
 		if ( empty( $translation_set_id ) ) {
 			return $content;
 		}
 
 		$translations = $this->get_gp_translations( $slug, $branch, $originals, $translation_set_id );
 
+		// Sort the originals so that we match the longer originals first.
+		uasort( $originals, function( $a, $b ) {
+			$a_len = strlen( $a->singular );
+			$b_len = strlen( $b->singular );
+
+			return $a_len == $b_len ? 0 : ($a_len > $b_len ? -1 : 1);
+		} );
+
+		// Mark each original for translation
 		foreach ( $originals as $original ) {
-			if ( ! empty( $original->id ) && array_key_exists( $original->id, $translations ) ) {
-				$content = $this->translate_gp_original( $original->singular, $translations[ $original->id ], $content );
+			if ( ! empty( $original->id ) ) {
+				$content = $this->mark_gp_original( $original, $content );
 			}
 		}
 
-		$this->cache_set( $slug, $branch, $content, $cache_suffix );
+		// Translate each original marked
+		$content = preg_replace_callback( '!___TRANSLATION_(\d+)___!', function( $m ) use( $originals, $translations ) {
+			return $translations[ $m[1] ] ?? $originals[ $m[1] ];
+		}, $content );
+
+		return $content;
+		// TODO reenable
+		//$this->cache_set( $slug, $branch, $content, $cache_suffix );
 
 		return $content;
 	}
 
 	/**
 	 * Takes content, searches for $original, and replaces it by $translation.
 	 *
 	 * @param string $original    English string.
 	 * @param string $translation Translation.
 	 * @param string $content     Content to be searched.
 	 * @return mixed
 	 */
-	public function translate_gp_original( $original, $translation, $content ) {
+	public function mark_gp_original( $original_obj, $content ) {
+		$marker = "___TRANSLATION_{$original_obj->id}___";
+		$original = $original_obj->singular;
+
 		if ( $original === $content ) {
-			$content = $translation;
+			$content = $marker;
 		} else {
 			$original = preg_quote( $original, '/' );
 
 			if ( false === strpos( $content, '<' ) ) {
 				// Don't use $translation, it may contain backreference-like characters.
-				$content = preg_replace( "/\b{$original}\b/", '___TRANSLATION___', $content );
+				$content = preg_replace( "/\b{$original}\b/", $marker, $content );
 			} else {
 				// Don't use $translation, it may contain backreference-like characters.
-				$content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", '${1}___TRANSLATION___${3}', $content );
+				$content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", "\${1}{$marker}\${3}", $content );
 			}
-
-			$content = str_replace( '___TRANSLATION___', $translation, $content );
 		}
 
 		return $content;
 	}
 
 	/**
 	 * Returns a list of translation locales for a given plugin slug and branch.
 	 *
 	 * @param string $slug        Plugin slug.
 	 * @param string $branch      Branch - 'stable-readme' for example.
 	 * @param int    $min_percent Optional. Only return locales where percent_translated is >= this value.
 	 * @return array
 	 */
 	public function find_all_translations_for_plugin( $slug, $branch, $min_percent = 0 ) {
 		$post = Plugin_Directory::get_plugin_post( $slug );
