| @@ -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,12 +11,10 @@ | ||
| 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 | - 'azb' => __( 'South Azerbaijani', 'bogo' ), | |
| 20 | 17 | 'be_BY' => __( 'Belarusian', 'bogo' ), |
| 21 | 18 | 'bg_BG' => __( 'Bulgarian', 'bogo' ), |
| 22 | 19 | 'bn_BD' => __( 'Bangla', 'bogo' ), |
| 23 | 20 | 'bn_IN' => __( 'Indian Bengali', 'bogo' ), |
| @@ -23,9 +20,8 @@ | ||
| 23 | 20 | 'bn_IN' => __( 'Indian Bengali', 'bogo' ), |
| 24 | 21 | 'bo' => __( 'Tibetan', 'bogo' ), |
| 25 | 22 | 'bs_BA' => __( 'Bosnian', 'bogo' ), |
| 26 | 23 | 'ca' => __( 'Catalan', 'bogo' ), |
| 27 | - 'ceb' => __( 'Cebuano', 'bogo' ), | |
| 28 | 24 | 'ckb' => __( 'Central Kurdish', 'bogo' ), |
| 29 | 25 | 'co' => __( 'Corsican', 'bogo' ), |
| 30 | 26 | 'cs_CZ' => __( 'Czech', 'bogo' ), |
| 31 | 27 | 'cy' => __( 'Welsh', 'bogo' ), |
| @@ -30,11 +26,8 @@ | ||
| 30 | 26 | 'cs_CZ' => __( 'Czech', 'bogo' ), |
| 31 | 27 | 'cy' => __( 'Welsh', 'bogo' ), |
| 32 | 28 | 'da_DK' => __( 'Danish', 'bogo' ), |
| 33 | 29 | 'de_DE' => __( 'German', 'bogo' ), |
| 34 | - 'de_DE_formal' => __( 'German (Formal)', 'bogo' ), | |
| 35 | - 'de_CH' => __( 'German (Switzerland)', 'bogo' ), | |
| 36 | - 'de_CH_informal' => __( 'German (Switzerland) (Informal)', 'bogo' ), | |
| 37 | 30 | 'dv' => __( 'Dhivehi', 'bogo' ), |
| 38 | 31 | 'el' => __( 'Greek', 'bogo' ), |
| 39 | 32 | 'en_US' => __( 'English (United States)', 'bogo' ), |
| 40 | 33 | 'en_AU' => __( 'English (Australia)', 'bogo' ), |
| @@ -39,17 +32,12 @@ | ||
| 39 | 32 | 'en_US' => __( 'English (United States)', 'bogo' ), |
| 40 | 33 | 'en_AU' => __( 'English (Australia)', 'bogo' ), |
| 41 | 34 | 'en_CA' => __( 'English (Canada)', 'bogo' ), |
| 42 | 35 | 'en_GB' => __( 'English (UK)', 'bogo' ), |
| 43 | - 'en_NZ' => __( 'English (New Zealand)', 'bogo' ), | |
| 44 | - 'en_ZA' => __( 'English (South Africa)', 'bogo' ), | |
| 45 | 36 | 'eo' => __( 'Esperanto', 'bogo' ), |
| 46 | 37 | 'es_ES' => __( 'Spanish (Spain)', 'bogo' ), |
| 47 | - 'es_AR' => __( 'Spanish (Argentina)', 'bogo' ), | |
| 48 | 38 | 'es_CL' => __( 'Spanish (Chile)', 'bogo' ), |
| 49 | - 'es_CO' => __( 'Spanish (Colombia)', 'bogo' ), | |
| 50 | - 'es_GT' => __( 'Spanish (Guatemala)', 'bogo' ), | |
| 51 | - 'es_MX' => __( 'Spanish (Mexico)', 'bogo' ), | |
| 39 | + 'es_MX' => __( 'Mexican Spanish', 'bogo' ), | |
| 52 | 40 | 'es_PE' => __( 'Spanish (Peru)', 'bogo' ), |
| 53 | 41 | 'es_VE' => __( 'Spanish (Venezuela)', 'bogo' ), |
| 54 | 42 | 'et' => __( 'Estonian', 'bogo' ), |
| 55 | 43 | 'eu' => __( 'Basque', 'bogo' ), |
| @@ -56,16 +44,13 @@ | ||
| 56 | 44 | 'fa_IR' => __( 'Persian', 'bogo' ), |
| 57 | 45 | 'fi' => __( 'Finnish', 'bogo' ), |
| 58 | 46 | 'fo' => __( 'Faroese', 'bogo' ), |
| 59 | 47 | 'fr_FR' => __( 'French (France)', 'bogo' ), |
| 60 | - 'fr_BE' => __( 'French (Belgium)', 'bogo' ), | |
| 61 | - 'fr_CA' => __( 'French (Canada)', 'bogo' ), | |
| 62 | 48 | 'fy' => __( 'Frisian', 'bogo' ), |
| 63 | 49 | 'ga' => __( 'Irish', 'bogo' ), |
| 64 | 50 | 'gd' => __( 'Scottish Gaelic', 'bogo' ), |
| 65 | 51 | 'gl_ES' => __( 'Galician', 'bogo' ), |
| 66 | 52 | 'gu' => __( 'Gujarati', 'bogo' ), |
| 67 | - 'haz' => __( 'Hazaragi', 'bogo' ), | |
| 68 | 53 | 'he_IL' => __( 'Hebrew', 'bogo' ), |
| 69 | 54 | 'hi_IN' => __( 'Hindi', 'bogo' ), |
| 70 | 55 | 'hr' => __( 'Croatian', 'bogo' ), |
| 71 | 56 | 'ht' => __( 'Haitian', 'bogo' ), |
| @@ -96,15 +81,11 @@ | ||
| 96 | 81 | 'nb_NO' => __( 'Norwegian (Bokmål)', 'bogo' ), |
| 97 | 82 | 'ne_NP' => __( 'Nepali', 'bogo' ), |
| 98 | 83 | 'ni_ID' => __( 'Nias', 'bogo' ), |
| 99 | 84 | 'nl_NL' => __( 'Dutch', 'bogo' ), |
| 100 | - 'nl_NL_formal' => __( 'Dutch (Formal)', 'bogo' ), | |
| 101 | - 'nn_NO' => __( 'Norwegian (Nynorsk)', 'bogo' ), | |
| 102 | - 'oci' => __( 'Occitan', 'bogo' ), | |
| 103 | 85 | 'os' => __( 'Ossetic', 'bogo' ), |
| 104 | 86 | 'pa_IN' => __( 'Punjabi', 'bogo' ), |
| 105 | 87 | 'pl_PL' => __( 'Polish', 'bogo' ), |
| 106 | - 'ps' => __( 'Pashto', 'bogo' ), | |
| 107 | 88 | 'pt_BR' => __( 'Portuguese (Brazil)', 'bogo' ), |
| 108 | 89 | 'pt_PT' => __( 'Portuguese (Portugal)', 'bogo' ), |
| 109 | 90 | 'ro_RO' => __( 'Romanian', 'bogo' ), |
| 110 | 91 | 'ru_RU' => __( 'Russian', 'bogo' ), |
| @@ -117,9 +98,8 @@ | ||
| 117 | 98 | 'sr_RS' => __( 'Serbian', 'bogo' ), |
| 118 | 99 | 'sv_SE' => __( 'Swedish', 'bogo' ), |
| 119 | 100 | 'su_ID' => __( 'Sundanese', 'bogo' ), |
| 120 | 101 | 'sw' => __( 'Swahili', 'bogo' ), |
| 121 | - 'szl' => __( 'Silesian', 'bogo' ), | |
| 122 | 102 | 'ta_IN' => __( 'Tamil', 'bogo' ), |
| 123 | 103 | 'te' => __( 'Telugu', 'bogo' ), |
| 124 | 104 | 'tg' => __( 'Tajik', 'bogo' ), |
| 125 | 105 | 'th' => __( 'Thai', 'bogo' ), |
| @@ -131,19 +111,16 @@ | ||
| 131 | 111 | 'ur' => __( 'Urdu', 'bogo' ), |
| 132 | 112 | 'uz_UZ' => __( 'Uzbek', 'bogo' ), |
| 133 | 113 | 'vi' => __( 'Vietnamese', 'bogo' ), |
| 134 | 114 | 'zh_CN' => __( 'Chinese (China)', 'bogo' ), |
| 135 | - 'zh_HK' => __( 'Chinese (Hong Kong)', 'bogo' ), | |
| 136 | 115 | 'zh_TW' => __( 'Chinese (Taiwan)', 'bogo' ) |
| 137 | 116 | ); |
| 138 | 117 | |
| 139 | - if ( is_textdomain_loaded( 'bogo' ) ) { | |
| 140 | - $textdomain_loaded = true; | |
| 141 | - } | |
| 118 | + asort( $languages, SORT_STRING ); | |
| 142 | 119 | |
| 143 | - asort( $languages, SORT_STRING ); | |
| 120 | + $languages = apply_filters( 'bogo_languages', $languages ); | |
| 144 | 121 | |
| 145 | - return apply_filters( 'bogo_languages', $languages ); | |
| 122 | + return $languages; | |
| 146 | 123 | } |
| 147 | 124 | |
| 148 | 125 | function bogo_get_language( $locale ) { |
| 149 | 126 | $languages = bogo_languages(); |
| @@ -153,30 +130,8 @@ | ||
| 153 | 130 | |
| 154 | 131 | return null; |
| 155 | 132 | } |
| 156 | 133 | |
| 157 | -function bogo_get_language_native_name( $locale ) { | |
| 158 | - if ( 'en_US' == $locale ) { | |
| 159 | - return 'English (United States)'; | |
| 160 | - } | |
| 161 | - | |
| 162 | - if ( ! function_exists( 'wp_get_available_translations' ) ) { | |
| 163 | - require_once ABSPATH . 'wp-admin/includes/translation-install.php'; | |
| 164 | - } | |
| 165 | - | |
| 166 | - static $available_translations = array(); | |
| 167 | - | |
| 168 | - if ( empty( $available_translations ) ) { | |
| 169 | - $available_translations = wp_get_available_translations(); | |
| 170 | - } | |
| 171 | - | |
| 172 | - if ( isset( $available_translations[$locale]['native_name'] ) ) { | |
| 173 | - return $available_translations[$locale]['native_name']; | |
| 174 | - } | |
| 175 | - | |
| 176 | - return false; | |
| 177 | -} | |
| 178 | - | |
| 179 | 134 | function bogo_get_default_locale() { |
| 180 | 135 | if ( defined( 'WPLANG' ) ) { |
| 181 | 136 | $locale = WPLANG; |
| 182 | 137 | } |
| @@ -213,9 +168,8 @@ | ||
| 213 | 168 | |
| 214 | 169 | function bogo_available_locales( $args = '' ) { |
| 215 | 170 | $defaults = array( |
| 216 | 171 | 'exclude' => array(), |
| 217 | - 'exclude_enus_if_inactive' => false, | |
| 218 | 172 | 'current_user_can_access' => false ); |
| 219 | 173 | |
| 220 | 174 | $args = wp_parse_args( $args, $defaults ); |
| 221 | 175 | |
| @@ -220,16 +174,9 @@ | ||
| 220 | 174 | $args = wp_parse_args( $args, $defaults ); |
| 221 | 175 | |
| 222 | 176 | $installed_locales = get_available_languages(); |
| 223 | 177 | $installed_locales[] = bogo_get_default_locale(); |
| 224 | - | |
| 225 | - $exclude_enus = $args['exclude_enus_if_inactive'] | |
| 226 | - && bogo_get_prop( 'enus_deactivated' ); | |
| 227 | - | |
| 228 | - if ( ! $exclude_enus ) { | |
| 229 | - $installed_locales[] = 'en_US'; | |
| 230 | - } | |
| 231 | - | |
| 178 | + $installed_locales[] = 'en_US'; | |
| 232 | 179 | $installed_locales = array_unique( $installed_locales ); |
| 233 | 180 | $installed_locales = array_filter( $installed_locales ); |
| 234 | 181 | |
| 235 | 182 | $available_locales = array(); |
| @@ -304,19 +251,13 @@ | ||
| 304 | 251 | function bogo_filter_locales( $locales, $filter = 'available' ) { |
| 305 | 252 | return array_intersect( $locales, bogo_available_locales() ); |
| 306 | 253 | } |
| 307 | 254 | |
| 308 | -/** | |
| 309 | - * @see http://www.ietf.org/rfc/bcp/bcp47.txt | |
| 310 | - */ | |
| 311 | 255 | function bogo_language_tag( $locale ) { |
| 256 | + // http://www.ietf.org/rfc/bcp/bcp47.txt | |
| 312 | 257 | $tag = preg_replace( '/[^0-9a-zA-Z]+/', '-', $locale ); |
| 313 | 258 | $tag = trim( $tag, '-' ); |
| 314 | 259 | |
| 315 | - if ( '-formal' == substr( $tag, -7 ) ) { | |
| 316 | - $tag = substr( $tag, 0, -7 ); | |
| 317 | - } | |
| 318 | - | |
| 319 | 260 | return apply_filters( 'bogo_language_tag', $tag, $locale ); |
| 320 | 261 | } |
| 321 | 262 | |
| 322 | 263 | function bogo_lang_slug( $locale ) { |
| @@ -424,19 +365,17 @@ | ||
| 424 | 365 | $url .= $_SERVER['HTTP_HOST']; |
| 425 | 366 | $url .= $_SERVER['REQUEST_URI']; |
| 426 | 367 | } |
| 427 | 368 | |
| 428 | - if ( $frag = strstr( $url, '#' ) ) { | |
| 369 | + if ( $frag = strstr( $url, '#' ) ) | |
| 429 | 370 | $url = substr( $url, 0, - strlen( $frag ) ); |
| 430 | - } | |
| 431 | 371 | |
| 432 | 372 | if ( $query = @parse_url( $url, PHP_URL_QUERY ) ) { |
| 433 | 373 | parse_str( $query, $query_vars ); |
| 434 | 374 | |
| 435 | 375 | foreach ( array_keys( $query_vars ) as $qv ) { |
| 436 | - if ( ! get_query_var( $qv ) ) { | |
| 376 | + if ( ! get_query_var( $qv ) ) | |
| 437 | 377 | $url = remove_query_arg( $qv, $url ); |
| 438 | - } | |
| 439 | 378 | } |
| 440 | 379 | } |
| 441 | 380 | } |
| 442 | 381 | |
| @@ -441,18 +380,11 @@ | ||
| 441 | 380 | } |
| 442 | 381 | |
| 443 | 382 | $default_locale = bogo_get_default_locale(); |
| 444 | 383 | |
| 445 | - if ( ! $lang ) { | |
| 384 | + if ( ! $lang ) | |
| 446 | 385 | $lang = $default_locale; |
| 447 | - } | |
| 448 | 386 | |
| 449 | - $use_implicit_lang = apply_filters( 'bogo_use_implicit_lang', true ); | |
| 450 | - | |
| 451 | - $lang_slug = ( $use_implicit_lang && $lang == $default_locale ) | |
| 452 | - ? '' | |
| 453 | - : bogo_lang_slug( $lang ); | |
| 454 | - | |
| 455 | 387 | $home = set_url_scheme( get_option( 'home' ) ); |
| 456 | 388 | $home = trailingslashit( $home ); |
| 457 | 389 | |
| 458 | 390 | $url = remove_query_arg( 'lang', $url ); |
| @@ -457,11 +389,10 @@ | ||
| 457 | 389 | |
| 458 | 390 | $url = remove_query_arg( 'lang', $url ); |
| 459 | 391 | |
| 460 | 392 | if ( ! $args['using_permalinks'] ) { |
| 461 | - if ( $lang_slug ) { | |
| 462 | - $url = add_query_arg( array( 'lang' => $lang_slug ), $url ); | |
| 463 | - } | |
| 393 | + if ( $lang != $default_locale ) | |
| 394 | + $url = add_query_arg( array( 'lang' => bogo_lang_slug( $lang ) ), $url ); | |
| 464 | 395 | |
| 465 | 396 | return $url; |
| 466 | 397 | } |
| 467 | 398 | |
| @@ -466,19 +397,13 @@ | ||
| 466 | 397 | } |
| 467 | 398 | |
| 468 | 399 | $available_languages = array_map( 'bogo_lang_slug', bogo_available_locales() ); |
| 469 | 400 | |
| 470 | - $tail_slashed = ( '/' == substr( $url, -1 ) ); | |
| 471 | - | |
| 472 | 401 | $url = preg_replace( |
| 473 | 402 | '#^' . preg_quote( $home ) . '((' . implode( '|', $available_languages ) . ')/)?#', |
| 474 | - $home . ( $lang_slug ? trailingslashit( $lang_slug ) : '' ), | |
| 403 | + $home . ( $lang == $default_locale ? '' : bogo_lang_slug( $lang ) . '/' ), | |
| 475 | 404 | trailingslashit( $url ) ); |
| 476 | 405 | |
| 477 | - if ( ! $tail_slashed ) { | |
| 478 | - $url = untrailingslashit( $url ); | |
| 479 | - } | |
| 480 | - | |
| 481 | 406 | return $url; |
| 482 | 407 | } |
| 483 | 408 | |
| 484 | 409 | function bogo_get_lang_from_url( $url = '' ) { |
| @@ -514,11 +439,10 @@ | ||
| 514 | 439 | |
| 515 | 440 | function bogo_get_prop( $prop ) { |
| 516 | 441 | $option = get_option( 'bogo' ); |
| 517 | 442 | |
| 518 | - if ( ! is_array( $option ) ) { | |
| 443 | + if ( ! is_array( $option ) ) | |
| 519 | 444 | $option = array(); |
| 520 | - } | |
| 521 | 445 | |
| 522 | 446 | return isset( $option[$prop] ) ? $option[$prop] : ''; |
| 523 | 447 | } |
| 524 | 448 | |
| @@ -524,11 +448,10 @@ | ||
| 524 | 448 | |
| 525 | 449 | function bogo_set_prop( $prop, $value ) { |
| 526 | 450 | $option = get_option( 'bogo' ); |
| 527 | 451 | |
| 528 | - if ( ! is_array( $option ) ) { | |
| 452 | + if ( ! is_array( $option ) ) | |
| 529 | 453 | $option = array(); |
| 530 | - } | |
| 531 | 454 | |
| 532 | 455 | $option[$prop] = $value; |
| 533 | 456 | |
| 534 | 457 | update_option( 'bogo', $option ); |
| @@ -533,27 +456,5 @@ | ||
| 533 | 456 | |
| 534 | 457 | update_option( 'bogo', $option ); |
| 535 | 458 | } |
| 536 | 459 | |
| 537 | -function bogo_delete_prop( $prop ) { | |
| 538 | - $option = get_option( 'bogo' ); | |
| 539 | - | |
| 540 | - if ( ! is_array( $option ) ) { | |
| 541 | - $option = array(); | |
| 542 | - } | |
| 543 | - | |
| 544 | - if ( isset( $option[$prop] ) ) { | |
| 545 | - unset( $option[$prop] ); | |
| 546 | - } | |
| 547 | - | |
| 548 | - update_option( 'bogo', $option ); | |
| 549 | -} | |
| 550 | - | |
| 551 | -function bogo_plugin_url( $path = '' ) { | |
| 552 | - $url = plugins_url( $path, BOGO_PLUGIN ); | |
| 553 | - | |
| 554 | - if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) { | |
| 555 | - $url = 'https:' . substr( $url, 5 ); | |
| 556 | - } | |
| 557 | - | |
| 558 | - return $url; | |
| 559 | -} | |
| 460 | +?> | |