예제 #1
0
 /**
  * Output translations to string
  *
  * @param array $translations Array of translations ( key => translated string )
  * @return string
  */
 public static function outputTranslation($translations)
 {
     if (!self::$baseTranslation) {
         self::$baseTranslation = self::loadTranslation('en');
     }
     $en = self::$baseTranslation;
     $output = array('<?php', '$translations = array(');
     $deferoutput = array();
     /* write all the translations that exist in en.php */
     foreach ($en as $key => $en_translation) {
         if (isset($translations[$key]) && !empty($translations[$key])) {
             $tmp = self::quote($translations[$key]);
             $output[] = "\t'{$key}' => {$tmp},";
         }
     }
     /* write the remaining translations (that don't exist in en.php) */
     foreach ($translations as $key => $translation) {
         if (!isset($en[$key]) && !empty($translation)) {
             $tmp = self::quote($translation);
             $deferoutput[] = "\t'{$key}' => {$tmp},";
         }
     }
     if (count($deferoutput) > 0) {
         $output[] = "\n\t// FOR REVIEW";
         $output = array_merge($output, $deferoutput);
     }
     $output[] = ');';
     return implode($output, "\n") . "\n";
 }