<!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][897] trunk: Add abstract class GP_Format and abstract print_exported_file() into that class.</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/897">897</a></dd>
<dt>Author</dt> <dd>markoheijnen</dd>
<dt>Date</dt> <dd>2014-05-07 20:55:26 +0000 (Wed, 07 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add abstract class GP_Format and abstract print_exported_file() into that class. See <a href="http://glotpress.trac.wordpress.org/ticket/317">#317</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgpincludesformatsformat_androidphp">trunk/gp-includes/formats/format_android.php</a></li>
<li><a href="#trunkgpincludesformatsformat_pomophp">trunk/gp-includes/formats/format_pomo.php</a></li>
<li><a href="#trunkgpincludesformatsformat_resxphp">trunk/gp-includes/formats/format_resx.php</a></li>
<li><a href="#trunkgpincludesformatsformat_rrcphp">trunk/gp-includes/formats/format_rrc.php</a></li>
<li><a href="#trunkgpincludesformatsformat_stringsphp">trunk/gp-includes/formats/format_strings.php</a></li>
<li><a href="#trunkgpsettingsphp">trunk/gp-settings.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkgpincludesformatphp">trunk/gp-includes/format.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgpincludesformatphp"></a>
<div class="addfile"><h4>Added: trunk/gp-includes/format.php (0 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/format.php (rev 0)
+++ trunk/gp-includes/format.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -0,0 +1,53 @@
</span><ins>+<?php
+
+/**
+ * GlotPress Format base class. It is supposed to be inherited.
+ */
+abstract class GP_Format {
+
+ public $name = '';
+ public $extension = '';
+
+ public abstract function print_exported_file( $project, $locale, $translation_set, $entries );
+ public abstract function read_originals_from_file( $file_name );
+
+
+ public function read_translations_from_file( $file_name, $project = null ) {
+ if ( is_null( $project ) ) {
+ return false;
+ }
+
+ $translations = $this->read_originals_from_file( $file_name );
+
+ if ( ! $translations ) {
+ return false;
+ }
+
+ $originals = GP::$original->by_project_id( $project->id );
+ $new_translations = new Translations;
+
+ foreach( $translations->entries as $key => $entry ) {
+ // we have been using read_originals_from_file to parse the file
+ // so we need to swap singular and translation
+ $entry->translations = array( $entry->singular );
+ $entry->singular = null;
+
+ foreach( $originals as $original ) {
+ if ( $original->context == $entry->context ) {
+ $entry->singular = $original->singular;
+ break;
+ }
+ }
+
+ if ( ! $entry->singular ) {
+ error_log( sprintf( __("Missing context %s in project #%d"), $entry->context, $project->id ) );
+ continue;
+ }
+
+ $new_translations->add_entry( $entry );
+ }
+
+ return $new_translations;
+ }
+
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkgpincludesformatsformat_androidphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/formats/format_android.php (896 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/formats/format_android.php 2014-05-07 09:36:26 UTC (rev 896)
+++ trunk/gp-includes/formats/format_android.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -1,17 +1,13 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-class GP_Format_Android {
</del><ins>+class GP_Format_Android extends GP_Format {
</ins><span class="cx">
</span><del>- var $name = 'Android XML (.xml)';
- var $extension = 'xml';
</del><ins>+ public $name = 'Android XML (.xml)';
+ public $extension = 'xml';
</ins><span class="cx">
</span><del>- var $exported = '';
-
- function line( $string, $prepend_tabs = 0 ) {
- $this->exported .= str_repeat( "\t", $prepend_tabs ) . "$string\n";
- }
</del><ins>+ public $exported = '';
</ins><span class="cx">
</span><del>- function print_exported_file( $project, $locale, $translation_set, $entries ) {
</del><ins>+ public function print_exported_file( $project, $locale, $translation_set, $entries ) {
</ins><span class="cx"> $this->exported = '';
</span><span class="cx"> $this->line( '<?xml version="1.0" encoding="utf-8"?>' );
</span><span class="cx"> $this->line( '<resources>' );
</span><span class="lines">@@ -39,82 +35,7 @@
</span><span class="cx"> return $this->exported;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function string_arrays($entries)
- {
- $mapping = array();
-
- uasort( $entries, array( $this, 'cmp_context' ) );
-
- foreach( $entries as $entry )
- {
- $array_name = preg_replace( '/\[\d+\]$/', '', $entry->context );
-
- if ( ! isset( $mapping[ $array_name ] ) )
- $mapping[ $array_name ] = array();
-
- //Because android doesn't fallback on the original language
- //in string-arrays, we fill the non-translated ones with original language string.
- $value = $entry->translations[0];
-
- if ( ! $value )
- $value = $entry->singular;
-
- $mapping[ $array_name ][] = $this->escape( $value );
- }
-
- foreach ( array_keys( $mapping ) as $array_name )
- {
- $this->line( '<string-array name="' . $array_name . '">', 1 );
-
- foreach ( $mapping[ $array_name ] as $item )
- {
- $this->line('<item>' . $item . '</item>', 2);
- }
-
- $this->line( '</string-array>', 1 );
- }
- }
-
- function cmp_context( $a, $b ) {
- return strnatcmp( $a->context, $b->context );
- }
-
- function read_translations_from_file( $file_name, $project = null ) {
- if ( is_null( $project ) )
- return false;
-
- $translations = $this->read_originals_from_file( $file_name );
-
- if ( ! $translations )
- return false;
-
- $originals = GP::$original->by_project_id( $project->id );
- $new_translations = new Translations;
-
- foreach( $translations->entries as $key => $entry ) {
- // we have been using read_originals_from_file to parse the file
- // so we need to swap singular and translation
- $entry->translations = array( $entry->singular );
- $entry->singular = null;
- foreach( $originals as $original ) {
- if ( $original->context == $entry->context ) {
- $entry->singular = $original->singular;
- break;
- }
- }
-
- if ( ! $entry->singular ) {
- error_log( sprintf( __("Missing context %s in project #%d"), $entry->context, $project->id ) );
- continue;
- }
-
- $new_translations->add_entry( $entry );
- }
-
- return $new_translations;
- }
-
- function read_originals_from_file( $file_name ) {
</del><ins>+ public function read_originals_from_file( $file_name ) {
</ins><span class="cx"> $errors = libxml_use_internal_errors( true );
</span><span class="cx"> $data = simplexml_load_string( file_get_contents( $file_name ) );
</span><span class="cx"> libxml_use_internal_errors( $errors );
</span><span class="lines">@@ -167,15 +88,61 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><del>- function unescape( $string ) {
</del><ins>+ private function line( $string, $prepend_tabs = 0 ) {
+ $this->exported .= str_repeat( "\t", $prepend_tabs ) . "$string\n";
+ }
+
+ private function string_arrays($entries)
+ {
+ $mapping = array();
+
+ uasort( $entries, array( $this, 'cmp_context' ) );
+
+ foreach( $entries as $entry )
+ {
+ $array_name = preg_replace( '/\[\d+\]$/', '', $entry->context );
+
+ if ( ! isset( $mapping[ $array_name ] ) )
+ $mapping[ $array_name ] = array();
+
+ //Because android doesn't fallback on the original language
+ //in string-arrays, we fill the non-translated ones with original language string.
+ $value = $entry->translations[0];
+
+ if ( ! $value )
+ $value = $entry->singular;
+
+ $mapping[ $array_name ][] = $this->escape( $value );
+ }
+
+ foreach ( array_keys( $mapping ) as $array_name )
+ {
+ $this->line( '<string-array name="' . $array_name . '">', 1 );
+
+ foreach ( $mapping[ $array_name ] as $item )
+ {
+ $this->line('<item>' . $item . '</item>', 2);
+ }
+
+ $this->line( '</string-array>', 1 );
+ }
+ }
+
+ private function cmp_context( $a, $b ) {
+ return strnatcmp( $a->context, $b->context );
+ }
+
+ private function unescape( $string ) {
</ins><span class="cx"> return stripcslashes( $string );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function escape( $string ) {
</del><ins>+ private function escape( $string ) {
</ins><span class="cx"> $string = addcslashes( $string, "'\n");
</span><span class="cx"> $string = str_replace( array( '&', '<' ), array( '&', '<' ), $string );
</span><ins>+
</ins><span class="cx"> return $string;
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> GP::$formats['android'] = new GP_Format_Android;
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkgpincludesformatsformat_pomophp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/formats/format_pomo.php (896 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/formats/format_pomo.php 2014-05-07 09:36:26 UTC (rev 896)
+++ trunk/gp-includes/formats/format_pomo.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -1,12 +1,13 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-class GP_Format_PO {
</del><ins>+class GP_Format_PO extends GP_Format {
</ins><span class="cx">
</span><del>- var $name = 'Portable Object Message Catalog (.po)';
- var $extension = 'po';
- var $class = 'PO';
</del><ins>+ public $name = 'Portable Object Message Catalog (.po)';
+ public $extension = 'po';
</ins><span class="cx">
</span><del>- function print_exported_file( $project, $locale, $translation_set, $entries ) {
</del><ins>+ public $class = 'PO';
+
+ public function print_exported_file( $project, $locale, $translation_set, $entries ) {
</ins><span class="cx"> $po = new $this->class;
</span><span class="cx"> // TODO: add more meta data in the project: language team, report URL
</span><span class="cx"> $po->set_header( 'PO-Revision-Date', GP::$translation->last_modified( $translation_set ) . '+0000' );
</span><span class="lines">@@ -31,22 +32,24 @@
</span><span class="cx"> echo $po->export();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function read_translations_from_file( $file_name, $project = null ) {
- $po = new $this->class;
</del><ins>+ public function read_translations_from_file( $file_name, $project = null ) {
+ $po = new $this->class;
</ins><span class="cx"> $result = $po->import_from_file( $file_name );
</span><ins>+
</ins><span class="cx"> return $result ? $po : $result;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function read_originals_from_file( $file_name ) {
</del><ins>+ public function read_originals_from_file( $file_name ) {
</ins><span class="cx"> return $this->read_translations_from_file( $file_name );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> class GP_Format_MO extends GP_Format_PO {
</span><del>- var $name = 'Machine Object Message Catalog (.mo)';
- var $extension = 'mo';
- var $class = 'MO';
</del><ins>+ public $name = 'Machine Object Message Catalog (.mo)';
+ public $extension = 'mo';
+
+ public $class = 'MO';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> GP::$formats['po'] = new GP_Format_PO;
</span></span></pre></div>
<a id="trunkgpincludesformatsformat_resxphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/formats/format_resx.php (896 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/formats/format_resx.php 2014-05-07 09:36:26 UTC (rev 896)
+++ trunk/gp-includes/formats/format_resx.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -1,23 +1,13 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-class GP_Format_ResX {
</del><ins>+class GP_Format_ResX extends GP_Format {
</ins><span class="cx">
</span><del>- var $name = '.NET Resource (.resx)';
- var $extension = 'resx.xml';
</del><ins>+ public $name = '.NET Resource (.resx)';
+ public $extension = 'resx.xml';
</ins><span class="cx">
</span><del>- var $exported = '';
</del><ins>+ public $exported = '';
</ins><span class="cx">
</span><del>- function line( $string, $prepend_tabs = 0 ) {
- $this->exported .= str_repeat( "\t", $prepend_tabs ) . "$string\n";
- }
-
- function res_header( $name, $value ) {
- $this->line( '<resheader name="'.$name.'">', 1 );
- $this->line( '<value>'.$value.'</value>', 2 );
- $this->line( '</resheader>', 1 );
- }
-
- function print_exported_file( $project, $locale, $translation_set, $entries ) {
</del><ins>+ public function print_exported_file( $project, $locale, $translation_set, $entries ) {
</ins><span class="cx"> $this->exported = '';
</span><span class="cx"> $this->line( '<?xml version="1.0" encoding="utf-8"?>' );
</span><span class="cx"> $this->line( '<root>' );
</span><span class="lines">@@ -49,35 +39,7 @@
</span><span class="cx"> return $this->exported;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function read_translations_from_file( $file_name, $project = null ) {
- if ( is_null( $project ) ) return false;
- $translations = $this->read_originals_from_file( $file_name );
- if ( !$translations ) return false;
- $originals = GP::$original->by_project_id( $project->id );
- $new_translations = new Translations;
- foreach( $translations->entries as $key => $entry ) {
- // we have been using read_originals_from_file to parse the file
- // so we need to swap singular and translation
- $entry->translations = array( $entry->singular );
- $entry->singular = null;
- foreach( $originals as $original ) {
- if ( $original->context == $entry->context ) {
- $entry->singular = $original->singular;
- break;
- }
- }
- if ( !$entry->singular ) {
- error_log( sprintf( __("Missing context %s in project #%d"), $entry->context, $project->id ) );
- continue;
- }
-
- $new_translations->add_entry( $entry );
- }
- return $new_translations;
-
- }
-
- function read_originals_from_file( $file_name ) {
</del><ins>+ public function read_originals_from_file( $file_name ) {
</ins><span class="cx"> $errors = libxml_use_internal_errors( 'true' );
</span><span class="cx"> $data = simplexml_load_string( file_get_contents( $file_name ) );
</span><span class="cx"> libxml_use_internal_errors( $errors );
</span><span class="lines">@@ -100,11 +62,21 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><del>- function unescape( $string ) {
</del><ins>+ private function line( $string, $prepend_tabs = 0 ) {
+ $this->exported .= str_repeat( "\t", $prepend_tabs ) . "$string\n";
+ }
+
+ private function res_header( $name, $value ) {
+ $this->line( '<resheader name="'.$name.'">', 1 );
+ $this->line( '<value>'.$value.'</value>', 2 );
+ $this->line( '</resheader>', 1 );
+ }
+
+ private function unescape( $string ) {
</ins><span class="cx"> return $string;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function escape( $string ) {
</del><ins>+ private function escape( $string ) {
</ins><span class="cx"> $string = str_replace( array( '&', '<' ), array( '&', '<' ), $string );
</span><span class="cx"> return $string;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkgpincludesformatsformat_rrcphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/formats/format_rrc.php (896 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/formats/format_rrc.php 2014-05-07 09:36:26 UTC (rev 896)
+++ trunk/gp-includes/formats/format_rrc.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -1,11 +1,11 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-class GP_Format_RRC {
</del><ins>+class GP_Format_RRC extends GP_Format {
</ins><span class="cx">
</span><del>- var $name = 'Blackberry Resource (.rrc)';
- var $extension = 'rrc';
</del><ins>+ public $name = 'Blackberry Resource (.rrc)';
+ public $extension = 'rrc';
</ins><span class="cx">
</span><del>- function print_exported_file( $project, $locale, $translation_set, $entries ) {
</del><ins>+ public function print_exported_file( $project, $locale, $translation_set, $entries ) {
</ins><span class="cx"> $rrc = array();
</span><span class="cx"> foreach( $entries as $entry ) {
</span><span class="cx"> if ( !preg_match( '/^([A-Z0-9_]+)(?:\[(\d+)\])?$/', $entry->context, $matches ) ) {
</span><span class="lines">@@ -36,34 +36,7 @@
</span><span class="cx"> return $result;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function read_translations_from_file( $file_name, $project = null ) {
- if ( is_null( $project ) ) return false;
- $translations = $this->read_originals_from_file( $file_name );
- if ( !$translations ) return false;
- $originals = GP::$original->by_project_id( $project->id );
- $new_translations = new Translations;
- foreach( $translations->entries as $key => $entry ) {
- // we have been using read_originals_from_file to parse the file
- // so we need to swap singular and translation
- $entry->translations = array( $entry->singular );
- $entry->singular = null;
- foreach( $originals as $original ) {
- if ( $original->context == $entry->context ) {
- $entry->singular = $original->singular;
- break;
- }
- }
- if ( !$entry->singular ) {
- error_log( sprintf( __("Missing context %s in project #%d"), $entry->context, $project->id ) );
- continue;
- }
-
- $new_translations->add_entry( $entry );
- }
- return $new_translations;
- }
-
- function read_originals_from_file( $file_name ) {
</del><ins>+ public function read_originals_from_file( $file_name ) {
</ins><span class="cx"> $entries = new Translations;
</span><span class="cx"> $f = fopen( $file_name, 'r' );
</span><span class="cx"> if ( !$f ) return false;
</span><span class="lines">@@ -112,7 +85,7 @@
</span><span class="cx"> * characters are encoded via \uXXXX notation, where XXXX is 0-paded hex unicode code-point
</span><span class="cx"> * Newlines, tabs and carriage returns are backslash-escaped.
</span><span class="cx"> */
</span><del>- function escape( $string ) {
</del><ins>+ private function escape( $string ) {
</ins><span class="cx"> $string = addcslashes( $string, "\"\n\t\r" );
</span><span class="cx"> preg_match_all( '/./us', $string, $matches );
</span><span class="cx"> $characters = $matches[0];
</span><span class="lines">@@ -136,7 +109,7 @@
</span><span class="cx"> /**
</span><span class="cx"> * The reverse of {@see escape}
</span><span class="cx"> */
</span><del>- function unescape( $string ) {
</del><ins>+ private function unescape( $string ) {
</ins><span class="cx"> // in the resource file all the strings should be in iso-8859-1
</span><span class="cx"> $string = utf8_encode( $string );
</span><span class="cx"> // except for the unicode code points like \uABCD
</span><span class="lines">@@ -144,6 +117,7 @@
</span><span class="cx"> $string = preg_replace_callback( '/\\\\u([a-fA-F0-9]{4})/', $decode_codepoints_callback, $string );
</span><span class="cx"> return stripcslashes( $string );
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> GP::$formats['rrc'] = new GP_Format_RRC;
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkgpincludesformatsformat_stringsphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/formats/format_strings.php (896 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/formats/format_strings.php 2014-05-07 09:36:26 UTC (rev 896)
+++ trunk/gp-includes/formats/format_strings.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -1,20 +1,13 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-class GP_Format_Strings {
</del><ins>+class GP_Format_Strings extends GP_Format {
</ins><span class="cx">
</span><del>- var $name = 'Mac OS X / iOS Strings File (.strings)';
- var $extension = 'strings';
</del><ins>+ public $name = 'Mac OS X / iOS Strings File (.strings)';
+ public $extension = 'strings';
</ins><span class="cx">
</span><del>- var $exported = '';
</del><ins>+ public $exported = '';
</ins><span class="cx">
</span><del>- function sort_entries( $a, $b ) {
- if ( $a->context == $b->context ) {
- return 0;
- }
- return ( $a->context > $b->context ) ? +1 : -1;
- }
-
- function print_exported_file( $project, $locale, $translation_set, $entries ) {
</del><ins>+ public function print_exported_file( $project, $locale, $translation_set, $entries ) {
</ins><span class="cx"> $result = '';
</span><span class="cx"> $prefix = pack( 'CC', 0xff, 0xfe ); // Add BOM
</span><span class="cx">
</span><span class="lines">@@ -39,12 +32,20 @@
</span><span class="cx"> return $prefix . mb_convert_encoding( $result, 'UTF-16LE' );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function read_translations_from_file( $file_name, $project = null ) {
- if ( is_null( $project ) ) return false;
</del><ins>+ public function read_translations_from_file( $file_name, $project = null ) {
+ if ( is_null( $project ) ) {
+ return false;
+ }
+
</ins><span class="cx"> $translations = $this->read_originals_from_file( $file_name );
</span><del>- if ( !$translations ) return false;
- $originals = GP::$original->by_project_id( $project->id );
</del><ins>+
+ if ( ! $translations ) {
+ return false;
+ }
+
+ $originals = GP::$original->by_project_id( $project->id );
</ins><span class="cx"> $new_translations = new Translations;
</span><ins>+
</ins><span class="cx"> foreach( $translations->entries as $key => $entry ) {
</span><span class="cx"> // we have been using read_originals_from_file to parse the file
</span><span class="cx"> // so we need to swap singular and translation
</span><span class="lines">@@ -53,25 +54,28 @@
</span><span class="cx"> } else {
</span><span class="cx"> $entry->translations = array( $entry->singular );
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> $entry->singular = null;
</span><ins>+
</ins><span class="cx"> foreach( $originals as $original ) {
</span><span class="cx"> if ( $original->context == $entry->context ) {
</span><span class="cx"> $entry->singular = $original->singular;
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>- if ( !$entry->singular ) {
</del><ins>+
+ if ( ! $entry->singular ) {
</ins><span class="cx"> error_log( sprintf( __("Missing context %s in project #%d"), $entry->context, $project->id ) );
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $new_translations->add_entry( $entry );
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> return $new_translations;
</span><del>-
</del><span class="cx"> }
</span><span class="cx">
</span><del>- function read_originals_from_file( $file_name ) {
</del><ins>+ public function read_originals_from_file( $file_name ) {
</ins><span class="cx"> $entries = new Translations;
</span><span class="cx"> $file = file_get_contents( $file_name );
</span><span class="cx"> if ( false === $file ) return false;
</span><span class="lines">@@ -107,13 +111,22 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><del>- function unescape( $string ) {
</del><ins>+ private function sort_entries( $a, $b ) {
+ if ( $a->context == $b->context ) {
+ return 0;
+ }
+
+ return ( $a->context > $b->context ) ? +1 : -1;
+ }
+
+ private function unescape( $string ) {
</ins><span class="cx"> return stripcslashes( $string );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function escape( $string ) {
</del><ins>+ private function escape( $string ) {
</ins><span class="cx"> return addcslashes( $string, '"\\/' );
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> GP::$formats['strings'] = new GP_Format_Strings;
</span></span></pre></div>
<a id="trunkgpsettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-settings.php (896 => 897)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-settings.php 2014-05-07 09:36:26 UTC (rev 896)
+++ trunk/gp-settings.php 2014-05-07 20:55:26 UTC (rev 897)
</span><span class="lines">@@ -317,6 +317,7 @@
</span><span class="cx"> GP::$router = new GP_Router();
</span><span class="cx"> GP::$formats = array();
</span><span class="cx">
</span><ins>+require_once GP_PATH . GP_INC . 'format.php';
</ins><span class="cx"> require_once GP_PATH . GP_INC . 'formats/format_android.php';
</span><span class="cx"> require_once GP_PATH . GP_INC . 'formats/format_pomo.php';
</span><span class="cx"> require_once GP_PATH . GP_INC . 'formats/format_resx.php';
</span></span></pre>
</div>
</div>
</body>
</html>