| @@ -1,12 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function bogo_languages() { |
| 4 | 4 | static $languages = array(); |
| 5 | - static $textdomain_loaded = false; | |
| 6 | 5 | |
| 7 | - if ( $languages && $textdomain_loaded ) { | |
| 8 | - return apply_filters( 'bogo_languages', $languages ); | |
| 6 | + if ( ! empty( $languages ) ) { | |
| 7 | + return $languages; | |
| 9 | 8 | } |
| 10 | 9 | |
| 11 | 10 | $languages = array( |
| 12 | 11 | 'af' => __( 'Afrikaans', 'bogo' ), |
| @@ -12,9 +11,8 @@ | ||
| 12 | 11 | 'af' => __( 'Afrikaans', 'bogo' ), |
| 13 | 12 | 'am' => __( 'Amharic', 'bogo' ), |
| 14 | 13 | 'an' => __( 'Aragonese', 'bogo' ), |
| 15 | 14 | 'ar' => __( 'Arabic', 'bogo' ), |
| 16 | - 'ary' => __( 'Moroccan Arabic', 'bogo' ), | |
| 17 | 15 | 'as' => __( 'Assamese', 'bogo' ), |
| 18 | 16 | 'az' => __( 'Azerbaijani', 'bogo' ), |
| 19 | 17 | 'be_BY' => __( 'Belarusian', 'bogo' ), |
| 20 | 18 | 'bg_BG' => __( 'Bulgarian', 'bogo' ), |
| @@ -28,10 +26,8 @@ | ||
| 28 | 26 | 'cs_CZ' => __( 'Czech', 'bogo' ), |
| 29 | 27 | 'cy' => __( 'Welsh', 'bogo' ), |
| 30 | 28 | 'da_DK' => __( 'Danish', 'bogo' ), |
| 31 | 29 | 'de_DE' => __( 'German', 'bogo' ), |
| 32 | - 'de_DE_formal' => __( 'German (Formal)', 'bogo' ), | |
| 33 | - 'de_CH' => __( 'German (Switzerland)', 'bogo' ), | |
| 34 | 30 | 'dv' => __( 'Dhivehi', 'bogo' ), |
| 35 | 31 | 'el' => __( 'Greek', 'bogo' ), |
| 36 | 32 | 'en_US' => __( 'English (United States)', 'bogo' ), |
| 37 | 33 | 'en_AU' => __( 'English (Australia)', 'bogo' ), |
| @@ -36,15 +32,12 @@ | ||
| 36 | 32 | 'en_US' => __( 'English (United States)', 'bogo' ), |
| 37 | 33 | 'en_AU' => __( 'English (Australia)', 'bogo' ), |
| 38 | 34 | 'en_CA' => __( 'English (Canada)', 'bogo' ), |
| 39 | 35 | 'en_GB' => __( 'English (UK)', 'bogo' ), |
| 40 | - 'en_NZ' => __( 'English (New Zealand)', 'bogo' ), | |
| 41 | - 'en_ZA' => __( 'English (South Africa)', 'bogo' ), | |
| 42 | 36 | 'eo' => __( 'Esperanto', 'bogo' ), |
| 43 | 37 | 'es_ES' => __( 'Spanish (Spain)', 'bogo' ), |
| 44 | 38 | 'es_CL' => __( 'Spanish (Chile)', 'bogo' ), |
| 45 | - 'es_CO' => __( 'Spanish (Colombia)', 'bogo' ), | |
| 46 | - 'es_MX' => __( 'Spanish (Mexico)', 'bogo' ), | |
| 39 | + 'es_MX' => __( 'Mexican Spanish', 'bogo' ), | |
| 47 | 40 | 'es_PE' => __( 'Spanish (Peru)', 'bogo' ), |
| 48 | 41 | 'es_VE' => __( 'Spanish (Venezuela)', 'bogo' ), |
| 49 | 42 | 'et' => __( 'Estonian', 'bogo' ), |
| 50 | 43 | 'eu' => __( 'Basque', 'bogo' ), |
| @@ -51,15 +44,13 @@ | ||
| 51 | 44 | 'fa_IR' => __( 'Persian', 'bogo' ), |
| 52 | 45 | 'fi' => __( 'Finnish', 'bogo' ), |
| 53 | 46 | 'fo' => __( 'Faroese', 'bogo' ), |
| 54 | 47 | 'fr_FR' => __( 'French (France)', 'bogo' ), |
| 55 | - 'fr_BE' => __( 'French (Belgium)', 'bogo' ), | |
| 56 | 48 | 'fy' => __( 'Frisian', 'bogo' ), |
| 57 | 49 | 'ga' => __( 'Irish', 'bogo' ), |
| 58 | 50 | 'gd' => __( 'Scottish Gaelic', 'bogo' ), |
| 59 | 51 | 'gl_ES' => __( 'Galician', 'bogo' ), |
| 60 | 52 | 'gu' => __( 'Gujarati', 'bogo' ), |
| 61 | - 'haz' => __( 'Hazaragi', 'bogo' ), | |
| 62 | 53 | 'he_IL' => __( 'Hebrew', 'bogo' ), |
| 63 | 54 | 'hi_IN' => __( 'Hindi', 'bogo' ), |
| 64 | 55 | 'hr' => __( 'Croatian', 'bogo' ), |
| 65 | 56 | 'ht' => __( 'Haitian', 'bogo' ), |
| @@ -90,14 +81,11 @@ | ||
| 90 | 81 | 'nb_NO' => __( 'Norwegian (Bokmål)', 'bogo' ), |
| 91 | 82 | 'ne_NP' => __( 'Nepali', 'bogo' ), |
| 92 | 83 | 'ni_ID' => __( 'Nias', 'bogo' ), |
| 93 | 84 | 'nl_NL' => __( 'Dutch', 'bogo' ), |
| 94 | - 'nn_NO' => __( 'Norwegian (Nynorsk)', 'bogo' ), | |
| 95 | - 'oci' => __( 'Occitan', 'bogo' ), | |
| 96 | 85 | 'os' => __( 'Ossetic', 'bogo' ), |
| 97 | 86 | 'pa_IN' => __( 'Punjabi', 'bogo' ), |
| 98 | 87 | 'pl_PL' => __( 'Polish', 'bogo' ), |
| 99 | - 'ps' => __( 'Pashto', 'bogo' ), | |
| 100 | 88 | 'pt_BR' => __( 'Portuguese (Brazil)', 'bogo' ), |
| 101 | 89 | 'pt_PT' => __( 'Portuguese (Portugal)', 'bogo' ), |
| 102 | 90 | 'ro_RO' => __( 'Romanian', 'bogo' ), |
| 103 | 91 | 'ru_RU' => __( 'Russian', 'bogo' ), |
| @@ -126,15 +114,13 @@ | ||
| 126 | 114 | 'zh_CN' => __( 'Chinese (China)', 'bogo' ), |
| 127 | 115 | 'zh_TW' => __( 'Chinese (Taiwan)', 'bogo' ) |
| 128 | 116 | ); |
| 129 | 117 | |
| 130 | - if ( is_textdomain_loaded( 'bogo' ) ) { | |
| 131 | - $textdomain_loaded = true; | |
| 132 | - } | |
| 118 | + asort( $languages, SORT_STRING ); | |
| 133 | 119 | |
| 134 | - asort( $languages, SORT_STRING ); | |
| 120 | + $languages = apply_filters( 'bogo_languages', $languages ); | |
| 135 | 121 | |
| 136 | - return apply_filters( 'bogo_languages', $languages ); | |
| 122 | + return $languages; | |
| 137 | 123 | } |
| 138 | 124 | |
| 139 | 125 | function bogo_get_language( $locale ) { |
| 140 | 126 | $languages = bogo_languages(); |
| @@ -144,30 +130,8 @@ | ||
| 144 | 130 | |
| 145 | 131 | return null; |
| 146 | 132 | } |
| 147 | 133 | |
| 148 | -function bogo_get_language_native_name( $locale ) { | |
| 149 | - if ( 'en_US' == $locale ) { | |
| 150 | - return 'English (United States)'; | |
| 151 | - } | |
| 152 | - | |
| 153 | - if ( ! function_exists( 'wp_get_available_translations' ) ) { | |
| 154 | - require_once ABSPATH . 'wp-admin/includes/translation-install.php'; | |
| 155 | - } | |
| 156 | - | |
| 157 | - static $available_translations = array(); | |
| 158 | - | |
| 159 | - if ( empty( $available_translations ) ) { | |
| 160 | - $available_translations = wp_get_available_translations(); | |
| 161 | - } | |
| 162 | - | |
| 163 | - if ( isset( $available_translations[$locale]['native_name'] ) ) { | |
| 164 | - return $available_translations[$locale]['native_name']; | |
| 165 | - } | |
| 166 | - | |
| 167 | - return false; | |
| 168 | -} | |
| 169 | - | |
| 170 | 134 | function bogo_get_default_locale() { |
| 171 | 135 | if ( defined( 'WPLANG' ) ) { |
| 172 | 136 | $locale = WPLANG; |
| 173 | 137 | } |
| @@ -204,9 +168,8 @@ | ||
| 204 | 168 | |
| 205 | 169 | function bogo_available_locales( $args = '' ) { |
| 206 | 170 | $defaults = array( |
| 207 | 171 | 'exclude' => array(), |
| 208 | - 'exclude_enus_if_inactive' => false, | |
| 209 | 172 | 'current_user_can_access' => false ); |
| 210 | 173 | |
| 211 | 174 | $args = wp_parse_args( $args, $defaults ); |
| 212 | 175 | |
| @@ -211,16 +174,9 @@ | ||
| 211 | 174 | $args = wp_parse_args( $args, $defaults ); |
| 212 | 175 | |
| 213 | 176 | $installed_locales = get_available_languages(); |
| 214 | 177 | $installed_locales[] = bogo_get_default_locale(); |
| 215 | - | |
| 216 | - $exclude_enus = $args['exclude_enus_if_inactive'] | |
| 217 | - && bogo_get_prop( 'enus_deactivated' ); | |
| 218 | - | |
| 219 | - if ( ! $exclude_enus ) { | |
| 220 | - $installed_locales[] = 'en_US'; | |
| 221 | - } | |
| 222 | - | |
| 178 | + $installed_locales[] = 'en_US'; | |
| 223 | 179 | $installed_locales = array_unique( $installed_locales ); |
| 224 | 180 | $installed_locales = array_filter( $installed_locales ); |
| 225 | 181 | |
| 226 | 182 | $available_locales = array(); |
| @@ -409,19 +365,17 @@ | ||
| 409 | 365 | $url .= $_SERVER['HTTP_HOST']; |
| 410 | 366 | $url .= $_SERVER['REQUEST_URI']; |
| 411 | 367 | } |
| 412 | 368 | |
| 413 | - if ( $frag = strstr( $url, '#' ) ) { | |
| 369 | + if ( $frag = strstr( $url, '#' ) ) | |
| 414 | 370 | $url = substr( $url, 0, - strlen( $frag ) ); |
| 415 | - } | |
| 416 | 371 | |
| 417 | 372 | if ( $query = @parse_url( $url, PHP_URL_QUERY ) ) { |
| 418 | 373 | parse_str( $query, $query_vars ); |
| 419 | 374 | |
| 420 | 375 | foreach ( array_keys( $query_vars ) as $qv ) { |
| 421 | - if ( ! get_query_var( $qv ) ) { | |
| 376 | + if ( ! get_query_var( $qv ) ) | |
| 422 | 377 | $url = remove_query_arg( $qv, $url ); |
| 423 | - } | |
| 424 | 378 | } |
| 425 | 379 | } |
| 426 | 380 | } |
| 427 | 381 | |
| @@ -426,11 +380,10 @@ | ||
| 426 | 380 | } |
| 427 | 381 | |
| 428 | 382 | $default_locale = bogo_get_default_locale(); |
| 429 | 383 | |
| 430 | - if ( ! $lang ) { | |
| 384 | + if ( ! $lang ) | |
| 431 | 385 | $lang = $default_locale; |
| 432 | - } | |
| 433 | 386 | |
| 434 | 387 | $home = set_url_scheme( get_option( 'home' ) ); |
| 435 | 388 | $home = trailingslashit( $home ); |
| 436 | 389 | |
| @@ -436,11 +389,10 @@ | ||
| 436 | 389 | |
| 437 | 390 | $url = remove_query_arg( 'lang', $url ); |
| 438 | 391 | |
| 439 | 392 | if ( ! $args['using_permalinks'] ) { |
| 440 | - if ( $lang != $default_locale ) { | |
| 393 | + if ( $lang != $default_locale ) | |
| 441 | 394 | $url = add_query_arg( array( 'lang' => bogo_lang_slug( $lang ) ), $url ); |
| 442 | - } | |
| 443 | 395 | |
| 444 | 396 | return $url; |
| 445 | 397 | } |
| 446 | 398 | |
| @@ -445,19 +397,13 @@ | ||
| 445 | 397 | } |
| 446 | 398 | |
| 447 | 399 | $available_languages = array_map( 'bogo_lang_slug', bogo_available_locales() ); |
| 448 | 400 | |
| 449 | - $tail_slashed = ( '/' == substr( $url, -1 ) ); | |
| 450 | - | |
| 451 | 401 | $url = preg_replace( |
| 452 | 402 | '#^' . preg_quote( $home ) . '((' . implode( '|', $available_languages ) . ')/)?#', |
| 453 | 403 | $home . ( $lang == $default_locale ? '' : bogo_lang_slug( $lang ) . '/' ), |
| 454 | 404 | trailingslashit( $url ) ); |
| 455 | 405 | |
| 456 | - if ( ! $tail_slashed ) { | |
| 457 | - $url = untrailingslashit( $url ); | |
| 458 | - } | |
| 459 | - | |
| 460 | 406 | return $url; |
| 461 | 407 | } |
| 462 | 408 | |
| 463 | 409 | function bogo_get_lang_from_url( $url = '' ) { |
| @@ -493,11 +439,10 @@ | ||
| 493 | 439 | |
| 494 | 440 | function bogo_get_prop( $prop ) { |
| 495 | 441 | $option = get_option( 'bogo' ); |
| 496 | 442 | |
| 497 | - if ( ! is_array( $option ) ) { | |
| 443 | + if ( ! is_array( $option ) ) | |
| 498 | 444 | $option = array(); |
| 499 | - } | |
| 500 | 445 | |
| 501 | 446 | return isset( $option[$prop] ) ? $option[$prop] : ''; |
| 502 | 447 | } |
| 503 | 448 | |
| @@ -503,11 +448,10 @@ | ||
| 503 | 448 | |
| 504 | 449 | function bogo_set_prop( $prop, $value ) { |
| 505 | 450 | $option = get_option( 'bogo' ); |
| 506 | 451 | |
| 507 | - if ( ! is_array( $option ) ) { | |
| 452 | + if ( ! is_array( $option ) ) | |
| 508 | 453 | $option = array(); |
| 509 | - } | |
| 510 | 454 | |
| 511 | 455 | $option[$prop] = $value; |
| 512 | 456 | |
| 513 | 457 | update_option( 'bogo', $option ); |
| @@ -512,27 +456,5 @@ | ||
| 512 | 456 | |
| 513 | 457 | update_option( 'bogo', $option ); |
| 514 | 458 | } |
| 515 | 459 | |
| 516 | -function bogo_delete_prop( $prop ) { | |
| 517 | - $option = get_option( 'bogo' ); | |
| 518 | - | |
| 519 | - if ( ! is_array( $option ) ) { | |
| 520 | - $option = array(); | |
| 521 | - } | |
| 522 | - | |
| 523 | - if ( isset( $option[$prop] ) ) { | |
| 524 | - unset( $option[$prop] ); | |
| 525 | - } | |
| 526 | - | |
| 527 | - update_option( 'bogo', $option ); | |
| 528 | -} | |
| 529 | - | |
| 530 | -function bogo_plugin_url( $path = '' ) { | |
| 531 | - $url = plugins_url( $path, BOGO_PLUGIN ); | |
| 532 | - | |
| 533 | - if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) { | |
| 534 | - $url = 'https:' . substr( $url, 5 ); | |
| 535 | - } | |
| 536 | - | |
| 537 | - return $url; | |
| 538 | -} | |
| 460 | +?> | |