Ticket #3089: localized-headers-in-exts.diff
File localized-headers-in-exts.diff, 9.3 KB (added by , 18 years ago) |
---|
-
wp-includes/theme.php
43 43 44 44 function get_theme_data($theme_file) { 45 45 $theme_data = implode('', file($theme_file)); 46 preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name); 47 preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri); 48 preg_match("|Description:(.*)|i", $theme_data, $description); 49 preg_match("|Author:(.*)|i", $theme_data, $author_name); 50 preg_match("|Author URI:(.*)|i", $theme_data, $author_uri); 51 preg_match("|Template:(.*)|i", $theme_data, $template); 52 if ( preg_match("|Version:(.*)|i", $theme_data, $version) ) 53 $version = trim($version[1]); 46 47 $headers = array( 48 array(&$name, 'Theme Name'), 49 array(&$theme_uri, 'Theme URI'), 50 array(&$description, 'Description'), 51 array(&$author, 'Author'), 52 array(&$author_uri, 'Author URI'), 53 array(&$template, 'Template'), 54 ); 55 56 foreach ($headers as $header) { 57 $header[0] = get_ext_header($header[1], $theme_data); 58 $locale_items = get_ext_l10n_header($header[1], $theme_data); 59 $header[0] = l10n_match_key($locale_items, $header[0]); 60 $header[0] = trim($header[0]); 61 } 62 63 if ( $version = get_ext_header('Version', $theme_data) ) 64 $version = trim($version); 54 65 else 55 66 $version =''; 56 if ( preg_match("|Status:(.*)|i", $theme_data, $status) ) 57 $status = trim($status[1]); 67 68 if ( $status = get_ext_header('Status', $theme_data) ) 69 $status = trim($status); 58 70 else 59 71 $status = 'publish'; 60 72 61 $description = wptexturize( trim($description[1]));73 $description = wptexturize($description); 62 74 63 $name = $theme_name[1];64 $name = trim($name);65 75 $theme = $name; 66 76 67 if ( '' == $author_uri[1] ) { 68 $author = trim($author_name[1]); 69 } else { 70 $author = '<a href="' . trim($author_uri[1]) . '" title="' . __('Visit author homepage') . '">' . trim($author_name[1]) . '</a>'; 77 if ( '' != $author_uri ) { 78 $author = '<a href="' . $author_uri . '" title="' . __('Visit author homepage') . '">' . $author . '</a>'; 71 79 } 72 80 73 return array('Name' => $name, 'Title' => $theme, 'Description' => $description, ' Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status);81 return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'URI' => $theme_uri, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status); 74 82 } 75 83 76 84 function get_themes() { … … 390 398 391 399 return true; 392 400 } 401 /** 402 * get extention (plugin/theme) header from the its source file string 403 * 404 * @param string $name the name of the header, e.g. 'Theme Name' 405 * @param string $source the string from which to extract the header value 406 * @return mixed the value of the given header key or empty string if not found 407 */ 408 function get_ext_header($name, &$source) { 409 410 if ( preg_match("|$name:(.*)|i", $source, $match) ) { 411 return $match[1]; 412 } else { 413 return ''; 414 } 415 } 393 416 417 /** 418 * get localized plugin/theme header 419 * 420 * @param string $name the name of the header 421 * @param string $source the string from which to extract the header values 422 * @return mixed referenece to the array of matches, whose each element is each set of matches 423 */ 424 function &get_ext_l10n_header($name, &$source) { 425 426 if ( preg_match_all("|$name\[(.+?)\]:(.*)|i", $source, $matches, PREG_SET_ORDER) ) { 427 return $matches; 428 } else { 429 return array(); 430 } 431 } 394 432 ?> -
wp-includes/l10n.php
94 94 load_textdomain($domain, $mofile); 95 95 } 96 96 97 ?> 98 No newline at end of file 97 /** 98 * Finds the best key match for a bunch of locales 99 * 100 * Follows the freedesktop.org standart: 101 * <a href="http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html">Localized values for keys</a> 102 * 103 * @param mixed $keys_array each element must be an array, whose 104 * first (not zero) element is the locale and its second is the key value 105 * This format is suitable to come from for preg_match_all results 106 * @param string $default_value the value to be used if a match is not found 107 * @return string the most suitable localized value for the given locales 108 */ 109 function l10n_match_key($keys_array, $default_value) { 110 111 $locale = l10n_parse_locale(get_locale(), true); 112 if ( false === $locale ) { 113 return $default_value; 114 } 115 $keys_dict = array(); 116 foreach ($keys_array as $item) { 117 $keys_dict[strtolower($item[1])] = $item[2]; 118 } 119 120 $lcm = strtolower(l10n_locale_parts($locale, 'lcm')); 121 $lc = strtolower(l10n_locale_parts($locale, 'lc')); 122 $lm = strtolower(l10n_locale_parts($locale, 'lm')); 123 $l = strtolower(l10n_locale_parts($locale, 'l')); 124 125 if ( array_key_exists($lcm, $keys_dict) ) { 126 return $keys_dict[$lcm]; 127 } elseif ( array_key_exists($lc, $keys_dict) ) { 128 return $keys_dict[$lc]; 129 } elseif ( array_key_exists($lm, $keys_dict) ) { 130 return $keys_dict[$lm]; 131 } elseif ( array_key_exists($l, $keys_dict) ) { 132 return $keys_dict[$l]; 133 } 134 return $default_value; 135 } 136 137 /** 138 * Parses a ln_CN.Encoding@Modifier string and returns hash with its parts 139 * 140 * @param string $locale the locale string 141 * @param bool $strip_encoding whether to return empty encoding part 142 * @return mixed hash with following keys: 143 * lang, country, encoding, modifier 144 */ 145 function l10n_parse_locale($locale, $strip_encoding = false) { 146 147 $locale_re = "^([a-z]{2})(?:_([a-z]{2}))?(?:\.([a-z0-9-]+))?(?:\@([a-z0-9-]+))?$"; 148 if ( preg_match("|$locale_re|i", $locale, $matches) ) { 149 if ( $strip_encoding ) { 150 $matches[3] = ''; 151 } 152 return array('locale' => $matches[0], 'lang' => $matches[1], 'country' => $matches[2], 153 'encoding' => $matches[3], 'modifier' => $matches[4]); 154 } else { 155 return false; 156 } 157 } 158 159 /** 160 * Extracts parts of an already parsed locale 161 * 162 * @param mixed $parsed_locale locale string parsed with {@link ln10_parse_locale} 163 * @param string $format some characters are replaced with their corresponding locale parts: 164 * 'l' -> language 165 * 'c' -> _country 166 * 'e' -> .encoding 167 * 'm' -> @modofier 168 * @return string the parts defined by $format, joined together in s string 169 * 170 * @example <code>l10n_locale_parts(l10n_parse_locale('bg_BG@baba'), 'lem')</code> returns <code>bg@baba</code> 171 */ 172 function l10n_locale_parts($parsed_locale, $format) { 173 174 $result = ''; 175 $format = preg_split('//', $format, -1, PREG_SPLIT_NO_EMPTY); 176 foreach ($format as $c) { 177 switch ($c) { 178 case 'l': $result .= !empty($parsed_locale['lang'])? $parsed_locale['lang'] : ''; break; 179 case 'c': $result .= !empty($parsed_locale['country'])? '_'.$parsed_locale['country'] : ''; break; 180 case 'e': $result .= !empty($parsed_locale['encoding'])? '.'.$parsed_locale['encoding'] : ''; break; 181 case 'm': $result .= !empty($parsed_locale['modifier'])? '@'.$parsed_locale['modifier'] : ''; break; 182 } 183 } 184 return $result; 185 } 186 187 ?> -
wp-admin/admin-functions.php
1682 1682 1683 1683 function get_plugin_data($plugin_file) { 1684 1684 $plugin_data = implode('', file($plugin_file)); 1685 preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);1686 preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);1687 preg_match("|Description:(.*)|i", $plugin_data, $description);1688 preg_match("|Author:(.*)|i", $plugin_data, $author_name);1689 preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);1690 if (preg_match("|Version:(.*)|i", $plugin_data, $version))1691 $version = trim($version[1]);1692 else1693 $version = '';1694 1685 1695 $description = wptexturize(trim($description[1])); 1686 $headers = array( 1687 array(&$name, 'Plugin Name'), 1688 array(&$plugin_uri, 'Plugin URI'), 1689 array(&$description, 'Description'), 1690 array(&$author, 'Author'), 1691 array(&$author_uri, 'Author URI'), 1692 ); 1693 1696 1694 1697 $name = $plugin_name[1];1698 $name = trim($name);1699 $plugin = $name;1700 if ('' != $plugin_uri[1] && '' != $name) {1701 $ plugin = '<a href="' . trim($plugin_uri[1]) . '" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>';1695 foreach ($headers as $header) { 1696 $header[0] = get_ext_header($header[1], $plugin_data); 1697 $locale_items = get_ext_l10n_header($header[1], $plugin_data); 1698 $header[0] = l10n_match_key($locale_items, $header[0]); 1699 $header[0] = trim($header[0]); 1702 1700 } 1703 1701 1704 if ( '' == $author_uri[1]) {1705 $ author = trim($author_name[1]);1702 if ( $version = get_ext_header('Version', $plugin_data)) { 1703 $version = trim($version); 1706 1704 } else { 1707 $ author = '<a href="' . trim($author_uri[1]) . '" title="'.__('Visit author homepage').'">' . trim($author_name[1]) . '</a>';1705 $version = ''; 1708 1706 } 1707 1708 $description = wptexturize($description); 1709 1709 1710 return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]); 1710 if ('' != $plugin_uri && '' != $name) { 1711 $plugin = '<a href="' . $plugin_uri . '" title="'.__('Visit plugin homepage').'">'.$name.'</a>'; 1712 } 1713 1714 if ('' != $author_uri) { 1715 $author = '<a href="' . $author_uri . '" title="'.__('Visit author homepage').'">' . $author . '</a>'; 1716 } 1717 1718 return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version); 1711 1719 } 1712 1720 1713 1721 function get_plugins() {