コード例 #1
0
ファイル: thing.php プロジェクト: rmccue/GlotPress
 function __call($name, $args)
 {
     $suffix = '_no_map';
     if (gp_endswith($name, $suffix)) {
         $name = substr($name, 0, strlen($name) - strlen($suffix));
         $this->map_results = false;
         return call_user_func_array(array(&$this, $name), $args);
         $this->map_results = true;
     }
     trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $name), E_USER_ERROR);
 }
コード例 #2
0
ファイル: url.php プロジェクト: rmccue/GlotPress
/**
 * Joins paths, and takes care of slashes between them
 */
function gp_url_join()
{
    $args = func_get_args();
    // we need array_values() in order to make sure the indices of $args are consecutive from 0 to count()-1
    $args = array_values(array_filter(gp_array_flatten($args)));
    if (empty($args)) {
        return '';
    }
    $start_slash = gp_startswith($args[0], '/') && trim($args[0], '/') != '' ? '/' : '';
    $end_slash = gp_endswith($args[count($args) - 1], '/') && trim($args[count($args) - 1], '/') != '' ? '/' : '';
    $args = array_map(create_function('$x', 'return trim($x, "/");'), $args);
    return $start_slash . implode('/', $args) . $end_slash;
}
コード例 #3
0
 public function warning_should_not_end_on_newline($original, $translation, $locale)
 {
     if (!gp_endswith($original, "\n") && gp_endswith($translation, "\n")) {
         return __('Translation should not end on newline.', 'glotpress');
     }
     return true;
 }
コード例 #4
0
ファイル: warnings.php プロジェクト: rmccue/GlotPress
 function warning_both_begin_end_on_newlines($original, $translation, $locale)
 {
     if (gp_endswith($original, "\n") xor gp_endswith($translation, "\n")) {
         return 'Original and translation should both end on newline.';
     }
     if (gp_startswith($original, "\n") xor gp_startswith($translation, "\n")) {
         return 'Original and translation should both begin on newline.';
     }
     return true;
 }
コード例 #5
0
ファイル: misc.php プロジェクト: ramiy/GlotPress-WP
/**
 * Determines the format to use based on the selected format type or by auto detection based on the file name.
 *
 * Used during import of translations and originals.
 *
 * @param string $selected_format The format that the user selected on the import page.
 * @param string $filename The filname that was uploaded by the user.
 * @return object|null A GP_Format child object or null if not found.
 */
function gp_get_import_file_format($selected_format, $filename)
{
    $format = gp_array_get(GP::$formats, $selected_format, null);
    if (!$format) {
        $matched_ext_len = 0;
        foreach (GP::$formats as $format_entry) {
            $format_extensions = $format_entry->get_file_extensions();
            foreach ($format_extensions as $extension) {
                $current_ext_len = strlen($extension);
                if (gp_endswith($filename, $extension) && $current_ext_len > $matched_ext_len) {
                    $format = $format_entry;
                    $matched_ext_len = $current_ext_len;
                }
            }
        }
    }
    return $format;
}
コード例 #6
0
ファイル: po.php プロジェクト: joshquila/demo2-youse
 function read_line($f, $action = 'read')
 {
     static $last_line = '';
     static $use_last_line = false;
     if ('clear' == $action) {
         $last_line = '';
         return true;
     }
     if ('put-back' == $action) {
         $use_last_line = true;
         return true;
     }
     $line = $use_last_line ? $last_line : fgets($f);
     $line = gp_endswith($line, "\r\n") ? rtrim($line, "\r\n") . "\n" : $line;
     $last_line = $line;
     $use_last_line = false;
     return $line;
 }
コード例 #7
0
 /**
  * Reads a set of original strings from a properties file.
  *
  * @since 2.0.0
  *
  * @param string $file_name The filename of the uploaded properties file.
  *
  * @return Translations|bool
  */
 public function read_originals_from_file($file_name)
 {
     $entries = new Translations();
     $file = file_get_contents($file_name);
     if (false === $file) {
         return false;
     }
     $entry = $comment = null;
     $inline = false;
     $lines = explode("\n", $file);
     $key = '';
     $value = '';
     foreach ($lines as $line) {
         if (preg_match('/^(#|!)\\s*(.*)\\s*$/', $line, $matches)) {
             // If we have been processing a multi-line entry, save it now.
             if (true === $inline) {
                 $entries->add_entry($entry);
                 $inline = false;
             }
             $matches[1] = trim($matches[1]);
             if ($matches[1] !== "No comment provided.") {
                 if (null !== $comment) {
                     $comment = $comment . "\n" . $matches[2];
                 } else {
                     $comment = $matches[2];
                 }
             } else {
                 $comment = null;
             }
         } else {
             if (false === $inline && $this->split_properties_line($line, $key, $value)) {
                 // Check to see if this line continues on to the next
                 if (gp_endswith($line, '\\')) {
                     $inline = true;
                     $value = trim($value, '\\');
                 }
                 $entry = new Translation_Entry();
                 $entry->context = rtrim($this->unescape($key));
                 /* So the following line looks a little weird, why encode just to decode?
                  *
                  * The reason is simple, properties files are in ISO-8859-1 aka Latin-1 format
                  * and can have extended characters above 127 but below 256 represented by a
                  * single byte.  That will break things later as PHP/MySQL will not accept
                  * a mixed encoding string with these high single byte characters in them.
                  *
                  * So let's convert everything to escaped unicode first and then decode
                  * the whole kit and kaboodle to UTF-8.
                  */
                 $entry->singular = $this->uni_decode($this->ascii_uni_encode($value));
                 if (!is_null($comment)) {
                     $entry->extracted_comments = $comment;
                     $comment = null;
                 }
                 $entry->translations = array();
                 // Only save this entry if we're not in a multi line translation.
                 if (false === $inline) {
                     $entries->add_entry($entry);
                 }
             } else {
                 // If we're processing a multi-line entry, add the line to the translation.
                 if (true === $inline) {
                     // Check to make sure we're not a blank line.
                     if ('' != trim($line)) {
                         // If there's still more lines to add, trim off the trailing slash.
                         if (gp_endswith($line, '\\')) {
                             $line = rtrim($line, '\\');
                         }
                         // Strip off leading spaces.
                         $line = ltrim($line);
                         // Decode the translation and add it to the current entry.
                         $entry->singular = $entry->singular . $this->uni_decode($line);
                     } else {
                         // Any blank line signals end of the entry.
                         $entries->add_entry($entry);
                         $inline = false;
                     }
                 } else {
                     // If we hit a blank line and are not processing a multi-line entry, reset the comment.
                     $comment = null;
                 }
             }
         }
     }
     // Make sure we save the last entry if it is a multi-line entry.
     if (true === $inline) {
         $entries->add_entry($entry);
     }
     return $entries;
 }