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