| @@ -2,15 +2,11 @@ | ||
| 2 | 2 | |
| 3 | 3 | add_filter( 'bloginfo', 'bogo_bloginfo_filter', 10, 2 ); |
| 4 | 4 | |
| 5 | 5 | function bogo_bloginfo_filter( $output, $show ) { |
| 6 | - if ( ! Bogo_POMO::is_ready() ) { | |
| 7 | - return $output; | |
| 8 | - } | |
| 9 | - | |
| 10 | - if ( 'name' === $show ) { | |
| 6 | + if ( 'name' == $show ) { | |
| 11 | 7 | $output = bogo_translate( 'blogname', 'blogname', $output ); |
| 12 | - } elseif ( 'description' === $show ) { | |
| 8 | + } elseif ( 'description' == $show ) { | |
| 13 | 9 | $output = bogo_translate( 'blogdescription', 'blogdescription', $output ); |
| 14 | 10 | } |
| 15 | 11 | |
| 16 | 12 | return $output; |
| @@ -15,47 +11,12 @@ | ||
| 15 | 11 | |
| 16 | 12 | return $output; |
| 17 | 13 | } |
| 18 | 14 | |
| 19 | - | |
| 20 | -add_filter( 'get_term', 'bogo_get_term_filter', 10, 2 ); | |
| 21 | - | |
| 22 | -function bogo_get_term_filter( $term, $taxonomy ) { | |
| 23 | - if ( ! Bogo_POMO::is_ready() ) { | |
| 24 | - return $term; | |
| 25 | - } | |
| 26 | - | |
| 27 | - if ( $term instanceof WP_Term ) { | |
| 28 | - $term = bogo_translate_term( $term ); | |
| 29 | - } | |
| 30 | - | |
| 31 | - return $term; | |
| 32 | -} | |
| 33 | - | |
| 34 | - | |
| 35 | -add_action( 'load-edit-tags.php', 'bogo_remove_get_term_filter', 10, 0 ); | |
| 36 | - | |
| 37 | -function bogo_remove_get_term_filter() { | |
| 38 | - remove_filter( 'get_term', 'bogo_get_term_filter' ); | |
| 39 | -} | |
| 40 | - | |
| 41 | - | |
| 42 | -function bogo_translate_term( WP_Term $term ) { | |
| 43 | - $term->name = bogo_translate( | |
| 44 | - sprintf( '%s:%d', $term->taxonomy, $term->term_id ), | |
| 45 | - $term->taxonomy, | |
| 46 | - $term->name | |
| 47 | - ); | |
| 48 | - | |
| 49 | - return $term; | |
| 50 | -} | |
| 51 | - | |
| 52 | - | |
| 53 | 15 | function bogo_translate( $singular, $context = '', $default = '' ) { |
| 54 | 16 | return Bogo_POMO::translate( $singular, $context, $default ); |
| 55 | 17 | } |
| 56 | 18 | |
| 57 | - | |
| 58 | 19 | class Bogo_POMO { |
| 59 | 20 | |
| 60 | 21 | private static $mo; |
| 61 | 22 | |
| @@ -65,9 +26,9 @@ | ||
| 65 | 26 | } |
| 66 | 27 | |
| 67 | 28 | $translated = self::$mo->translate( $singular, $context ); |
| 68 | 29 | |
| 69 | - if ( $translated === $singular and '' !== $default ) { | |
| 30 | + if ( $translated == $singular && '' !== $default ) { | |
| 70 | 31 | return $default; |
| 71 | 32 | } else { |
| 72 | 33 | return $translated; |
| 73 | 34 | } |
| @@ -79,12 +40,10 @@ | ||
| 79 | 40 | } |
| 80 | 41 | |
| 81 | 42 | $dir = self::dir(); |
| 82 | 43 | |
| 83 | - $revision_date = new DateTimeImmutable(); | |
| 84 | - | |
| 85 | 44 | $headers = array( |
| 86 | - 'PO-Revision-Date' => $revision_date->format( 'Y-m-d H:i:s' ) . '+0000', | |
| 45 | + 'PO-Revision-Date' => current_time( 'mysql', 'gmt' ) . '+0000', | |
| 87 | 46 | 'MIME-Version' => '1.0', |
| 88 | 47 | 'Content-Type' => 'text/plain; charset=UTF-8', |
| 89 | 48 | 'Content-Transfer-Encoding' => '8bit', |
| 90 | 49 | 'X-Generator' => sprintf( 'Bogo %s', BOGO_VERSION ), |
| @@ -89,10 +48,9 @@ | ||
| 89 | 48 | 'Content-Transfer-Encoding' => '8bit', |
| 90 | 49 | 'X-Generator' => sprintf( 'Bogo %s', BOGO_VERSION ), |
| 91 | 50 | 'Language' => $locale, |
| 92 | 51 | 'Project-Id-Version' => |
| 93 | - sprintf( 'WordPress %s', get_bloginfo( 'version' ) ), | |
| 94 | - ); | |
| 52 | + sprintf( 'WordPress %s', get_bloginfo( 'version' ) ) ); | |
| 95 | 53 | |
| 96 | 54 | require_once ABSPATH . WPINC . '/pomo/po.php'; |
| 97 | 55 | $po = new PO(); |
| 98 | 56 | $po->set_headers( $headers ); |
| @@ -101,13 +59,9 @@ | ||
| 101 | 59 | $entry = new Translation_Entry( $entry ); |
| 102 | 60 | $po->add_entry( $entry ); |
| 103 | 61 | } |
| 104 | 62 | |
| 105 | - $po_file = is_multisite() | |
| 106 | - ? sprintf( '%d-%s.po', get_current_blog_id(), $locale ) | |
| 107 | - : sprintf( '%s.po', $locale ); | |
| 108 | - $po_file = path_join( $dir, $po_file ); | |
| 109 | - $po->export_to_file( $po_file ); | |
| 63 | + $po->export_to_file( path_join( $dir, $locale . '.po' ) ); | |
| 110 | 64 | |
| 111 | 65 | $mo = new MO(); |
| 112 | 66 | $mo->set_headers( $headers ); |
| 113 | 67 | |
| @@ -115,13 +69,9 @@ | ||
| 115 | 69 | $entry = new Translation_Entry( $entry ); |
| 116 | 70 | $mo->add_entry( $entry ); |
| 117 | 71 | } |
| 118 | 72 | |
| 119 | - $mo_file = is_multisite() | |
| 120 | - ? sprintf( '%d-%s.mo', get_current_blog_id(), $locale ) | |
| 121 | - : sprintf( '%s.mo', $locale ); | |
| 122 | - $mo_file = path_join( $dir, $mo_file ); | |
| 123 | - return $mo->export_to_file( $mo_file ); | |
| 73 | + return $mo->export_to_file( path_join( $dir, $locale . '.mo' ) ); | |
| 124 | 74 | } |
| 125 | 75 | |
| 126 | 76 | public static function import( $locale ) { |
| 127 | 77 | if ( ! bogo_is_available_locale( $locale ) ) { |
| @@ -129,12 +79,9 @@ | ||
| 129 | 79 | } |
| 130 | 80 | |
| 131 | 81 | $dir = self::dir(); |
| 132 | 82 | |
| 133 | - $mo_file = is_multisite() | |
| 134 | - ? sprintf( '%d-%s.mo', get_current_blog_id(), $locale ) | |
| 135 | - : sprintf( '%s.mo', $locale ); | |
| 136 | - $mo_file = path_join( $dir, $mo_file ); | |
| 83 | + $mo_file = path_join( $dir, $locale . '.mo' ); | |
| 137 | 84 | |
| 138 | 85 | if ( ! is_readable( $mo_file ) ) { |
| 139 | 86 | return false; |
| 140 | 87 | } |
| @@ -146,16 +93,8 @@ | ||
| 146 | 93 | } |
| 147 | 94 | |
| 148 | 95 | self::$mo = $mo; |
| 149 | 96 | return true; |
| 150 | - } | |
| 151 | - | |
| 152 | - public static function reset() { | |
| 153 | - self::$mo = null; | |
| 154 | - } | |
| 155 | - | |
| 156 | - public static function is_ready() { | |
| 157 | - return (bool) self::$mo; | |
| 158 | 97 | } |
| 159 | 98 | |
| 160 | 99 | private static function dir() { |
| 161 | 100 | $dir = path_join( WP_LANG_DIR, 'bogo' ); |