equal
deleted
inserted
replaced
5 * @version $Id: translations.php 1157 2015-11-20 04:30:11Z dd32 $ |
5 * @version $Id: translations.php 1157 2015-11-20 04:30:11Z dd32 $ |
6 * @package pomo |
6 * @package pomo |
7 * @subpackage translations |
7 * @subpackage translations |
8 */ |
8 */ |
9 |
9 |
10 require_once dirname( __FILE__ ) . '/plural-forms.php'; |
10 require_once __DIR__ . '/plural-forms.php'; |
11 require_once dirname( __FILE__ ) . '/entry.php'; |
11 require_once __DIR__ . '/entry.php'; |
12 |
12 |
13 if ( ! class_exists( 'Translations', false ) ) : |
13 if ( ! class_exists( 'Translations', false ) ) : |
14 class Translations { |
14 class Translations { |
15 var $entries = array(); |
15 var $entries = array(); |
16 var $headers = array(); |
16 var $headers = array(); |
111 * Given the number of items, returns the 0-based index of the plural form to use |
111 * Given the number of items, returns the 0-based index of the plural form to use |
112 * |
112 * |
113 * Here, in the base Translations class, the common logic for English is implemented: |
113 * Here, in the base Translations class, the common logic for English is implemented: |
114 * 0 if there is one element, 1 otherwise |
114 * 0 if there is one element, 1 otherwise |
115 * |
115 * |
116 * This function should be overridden by the sub-classes. For example MO/PO can derive the logic |
116 * This function should be overridden by the subclasses. For example MO/PO can derive the logic |
117 * from their headers. |
117 * from their headers. |
118 * |
118 * |
119 * @param integer $count number of items |
119 * @param integer $count number of items |
120 */ |
120 */ |
121 function select_plural_form( $count ) { |
121 function select_plural_form( $count ) { |
266 * @param string $translation |
266 * @param string $translation |
267 * @return array |
267 * @return array |
268 */ |
268 */ |
269 function make_headers( $translation ) { |
269 function make_headers( $translation ) { |
270 $headers = array(); |
270 $headers = array(); |
271 // sometimes \ns are used instead of real new lines |
271 // Sometimes \n's are used instead of real new lines. |
272 $translation = str_replace( '\n', "\n", $translation ); |
272 $translation = str_replace( '\n', "\n", $translation ); |
273 $lines = explode( "\n", $translation ); |
273 $lines = explode( "\n", $translation ); |
274 foreach ( $lines as $line ) { |
274 foreach ( $lines as $line ) { |
275 $parts = explode( ':', $line, 2 ); |
275 $parts = explode( ':', $line, 2 ); |
276 if ( ! isset( $parts[1] ) ) { |
276 if ( ! isset( $parts[1] ) ) { |
285 * @param string $header |
285 * @param string $header |
286 * @param string $value |
286 * @param string $value |
287 */ |
287 */ |
288 function set_header( $header, $value ) { |
288 function set_header( $header, $value ) { |
289 parent::set_header( $header, $value ); |
289 parent::set_header( $header, $value ); |
290 if ( 'Plural-Forms' == $header ) { |
290 if ( 'Plural-Forms' === $header ) { |
291 list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) ); |
291 list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) ); |
292 $this->_nplurals = $nplurals; |
292 $this->_nplurals = $nplurals; |
293 $this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression ); |
293 $this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression ); |
294 } |
294 } |
295 } |
295 } |