Apache Zeta Components Manual :: File Source for bork_filter.php

Source for file bork_filter.php

Documentation is available at bork_filter.php

  1. <?php
  2. /**
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  *
  21.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22.  * @version //autogentag//
  23.  * @filesource
  24.  * @package Translation
  25.  */
  26.  
  27. /**
  28.  * Implements the Bork translation filter.
  29.  *
  30.  * The bork filter mangles text in cases where the translatable string is
  31.  * defined in the translation definition, but when it it marked as an
  32.  * "unfinished" translation.  This makes it obvious which text is translatable,
  33.  * but not yet translated.
  34.  *
  35.  * @package Translation
  36.  * @version //autogentag//
  37.  */
  38. class ezcTranslationBorkFilter implements ezcTranslationFilter
  39. {
  40.     /**
  41.      * @param ezcTranslationBorkFilter Instance
  42.      */
  43.     static private $instance null;
  44.  
  45.     /**
  46.      * Private constructor to prevent non-singleton use
  47.      */
  48.     private function __construct()
  49.     {
  50.     }
  51.  
  52.     /**
  53.      * Returns an instance of the class ezcTranslationFilterBork
  54.      *
  55.      * @return ezcTranslationFilterBork Instance of ezcTranslationFilterBork
  56.      */
  57.     public static function getInstance()
  58.     
  59.         if is_nullself::$instance ) ) 
  60.         
  61.             self::$instance new ezcTranslationBorkFilter()
  62.         
  63.         return self::$instance
  64.     }
  65.  
  66.     /**
  67.      * This "borkifies" the $text.
  68.      *
  69.      * @param string $text 
  70.      * @return string 
  71.      */
  72.     static private function borkify$text )
  73.     {
  74.         $textBlocks preg_split'/(%[^ ]+)/'$text-1PREG_SPLIT_DELIM_CAPTURE );
  75.         $newTextBlocks array();
  76.         foreach $textBlocks as $text )
  77.         {
  78.             if strlen$text && $text[0== '%' )
  79.             {
  80.                 $newTextBlocks[= (string) $text;
  81.                 continue;
  82.             }
  83.  
  84.             $orgtext $text;
  85.  
  86.             $searchMap array(
  87.                 '/au/''/\Bu/''/\Btion/''/an/''/a\B/''/en\b/',
  88.                 '/\Bew/''/\Bf/''/\Bir/''/\Bi/''/\bo/''/ow/''/ph/',
  89.                 '/th\b/''/\bU/''/y\b/''/v/''/w/''/ooo/',
  90.             );
  91.             $replaceMap array(
  92.                 'oo''oo''shun''un''e''ee',
  93.                 'oo''ff''ur''ee''oo''oo''f',
  94.                 't''Oo''ai''f''v''oo',
  95.             );
  96.             $text preg_replace$searchMap$replaceMap$text );
  97.  
  98.             if $orgtext == $text && count$newTextBlocks ) )
  99.             {
  100.                 $text .= '-a';
  101.             }
  102.             $newTextBlocks[= (string) $text;
  103.         }
  104.         $text implode''$newTextBlocks );
  105.         $text preg_replace'/([:.?!])(.*)/''\\2\\1'$text );
  106.         return "[$text]";
  107.     }
  108.  
  109.     /**
  110.      * Filters a context
  111.      *
  112.      * Applies the "bork" filter on the given context. The bork filter mangles
  113.      * non-finished or non-translated text so that it is obvious which text is
  114.      * translatable, but not yet translated.
  115.      *
  116.      * @param array(ezcTranslationData) $context 
  117.      * @return void 
  118.      */
  119.     public function runFilterarray $context )
  120.     {
  121.         foreach $context as $element )
  122.         {
  123.             if $element->status !== ezcTranslationData::TRANSLATED )
  124.             {
  125.                 $element->translation self::borkify$element->original );
  126.             }
  127.         }
  128.     }
  129. }
  130. ?>
Documentation generated by phpDocumentor 1.4.3