PluginProbe
Bogo / 3.0
Bogo v3.0
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / includes / flags.php

flags.php in Bogo 3.0, at includes/flags.php

84 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'wp_head', 'bogo_flag_css' );
4
5 function bogo_flag_css() {
6 $flags = array();
7
8 if ( apply_filters( 'bogo_use_flags', true ) ) {
9 $locales = bogo_available_locales();
10
11 foreach ( $locales as $locale ) {
12 if ( $flag = bogo_get_flag( $locale ) ) {
13 $flags[$locale] = $flag;
14 }
15 }
16 }
17
18 if ( ! $flags ) {
19 return;
20 }
21
22 $side = is_rtl() ? 'right' : 'left';
23
24 echo '<style type="text/css">' . "\n";
25
26 foreach ( $flags as $locale => $flag ) {
27 echo '.bogo-language-switcher .' . bogo_language_tag( $locale ) . ' {';
28 echo ' background: url("' . $flag . '") no-repeat ' . $side . ' center;';
29 echo ' }' . "\n";
30 }
31
32 echo '</style>' . "\n";
33 }
34
35 function bogo_get_flag( $locale ) {
36 $locale = explode( '_', $locale );
37 $locale = array_slice( $locale, 0, 2 ); // de_DE_formal => de_DE
38 $locale = implode( '_', $locale );
39
40 $special_cases = array(
41 'ca' => 'catalonia',
42 'gd' => 'scotland',
43 'cy' => 'wales',
44 'am' => 'et',
45 'az' => 'az',
46 'bs' => 'ba',
47 'el' => 'gr',
48 'et' => 'ee',
49 'fi' => 'fi',
50 'ga' => 'ie',
51 'hr' => 'hr',
52 'ht' => 'ht',
53 'hy' => 'am',
54 'ja' => 'jp',
55 'kk' => 'kz',
56 'km' => 'kh',
57 'lo' => 'la',
58 'lv' => 'lv',
59 'mn' => 'mn',
60 'sq' => 'al',
61 'tg' => 'tj',
62 'th' => 'th',
63 'tl' => 'ph',
64 'uk' => 'ua',
65 'vi' => 'vn' );
66
67 if ( isset( $special_cases[$locale] ) ) {
68 $file = $special_cases[$locale] . '.png';
69 } elseif ( preg_match( '/_([A-Z]{2})$/', $locale, $matches ) ) {
70 $file = strtolower( $matches[1] ) . '.png';
71 } else {
72 $file = 'zz.png'; // 'zz.png' doesn't exist, just a dummy.
73 }
74
75 $file = path_join( 'images/flag-icons', $file );
76 $url = '';
77
78 if ( file_exists( path_join( BOGO_PLUGIN_DIR, $file ) ) ) {
79 $url = bogo_plugin_url( $file );
80 }
81
82 return apply_filters( 'bogo_get_flag', $url, $locale );
83 }
84