@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; |
|
| 14 | + exit; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,510 +21,510 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Countries { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * An array that will contain country codes => country names pairs. It gets lazily loaded the first time by the |
|
| 26 | - * `get_countries` function. |
|
| 27 | - * |
|
| 28 | - * @since 3.18.0 |
|
| 29 | - * @var array An array of country codes => country names pairs or NULL if not initialized yet. |
|
| 30 | - */ |
|
| 31 | - private static $countries = array(); |
|
| 24 | + /** |
|
| 25 | + * An array that will contain country codes => country names pairs. It gets lazily loaded the first time by the |
|
| 26 | + * `get_countries` function. |
|
| 27 | + * |
|
| 28 | + * @since 3.18.0 |
|
| 29 | + * @var array An array of country codes => country names pairs or NULL if not initialized yet. |
|
| 30 | + */ |
|
| 31 | + private static $countries = array(); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The list of supported country codes, this is populated by self::lazy_populate_codes_and_country_codes_array. |
|
| 35 | - * |
|
| 36 | - * WARNING! If you change the list of supported countries, *you have* to add the related flag |
|
| 37 | - * in the images/flags folder. |
|
| 38 | - * |
|
| 39 | - * @since 3.18.0 |
|
| 40 | - * |
|
| 41 | - * @var array An array of country codes => supported_languages_array |
|
| 42 | - */ |
|
| 43 | - public static $codes = array(); |
|
| 33 | + /** |
|
| 34 | + * The list of supported country codes, this is populated by self::lazy_populate_codes_and_country_codes_array. |
|
| 35 | + * |
|
| 36 | + * WARNING! If you change the list of supported countries, *you have* to add the related flag |
|
| 37 | + * in the images/flags folder. |
|
| 38 | + * |
|
| 39 | + * @since 3.18.0 |
|
| 40 | + * |
|
| 41 | + * @var array An array of country codes => supported_languages_array |
|
| 42 | + */ |
|
| 43 | + public static $codes = array(); |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The list of country codes, this is populated by self::lazy_populate_codes_and_country_codes_array. |
|
| 47 | - * |
|
| 48 | - * WARNING! If you change the list of supported countries, *you have* to add the related flag |
|
| 49 | - * in the images/flags folder. |
|
| 50 | - * |
|
| 51 | - * @since 3.18.0 |
|
| 52 | - * |
|
| 53 | - * @var array An array of country codes => country names. |
|
| 54 | - */ |
|
| 55 | - private static $country_codes = array(); |
|
| 45 | + /** |
|
| 46 | + * The list of country codes, this is populated by self::lazy_populate_codes_and_country_codes_array. |
|
| 47 | + * |
|
| 48 | + * WARNING! If you change the list of supported countries, *you have* to add the related flag |
|
| 49 | + * in the images/flags folder. |
|
| 50 | + * |
|
| 51 | + * @since 3.18.0 |
|
| 52 | + * |
|
| 53 | + * @var array An array of country codes => country names. |
|
| 54 | + */ |
|
| 55 | + private static $country_codes = array(); |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * An array of flag filenames. |
|
| 59 | - * |
|
| 60 | - * @since 3.20.0 |
|
| 61 | - * |
|
| 62 | - * @var array An array of flag filenames. |
|
| 63 | - */ |
|
| 64 | - private static $country_flags = array( |
|
| 65 | - 'af' => 'Afghanistan', |
|
| 66 | - 'ax' => 'Aland', |
|
| 67 | - 'al' => 'Albania', |
|
| 68 | - 'dz' => 'Algeria', |
|
| 69 | - 'as' => 'American-Samoa', |
|
| 70 | - 'ad' => 'Andorra', |
|
| 71 | - 'ao' => 'Angola', |
|
| 72 | - 'ai' => 'Anguilla', |
|
| 73 | - 'aq' => 'Antarctica', |
|
| 74 | - 'ag' => 'Antigua-and-Barbuda', |
|
| 75 | - 'ar' => 'Argentina', |
|
| 76 | - 'am' => 'Armenia', |
|
| 77 | - 'aw' => 'Aruba', |
|
| 78 | - 'au' => 'Australia', |
|
| 79 | - 'at' => 'Austria', |
|
| 80 | - 'az' => 'Azerbaijan', |
|
| 81 | - 'bs' => 'Bahamas', |
|
| 82 | - 'bh' => 'Bahrain', |
|
| 83 | - 'bd' => 'Bangladesh', |
|
| 84 | - 'bb' => 'Barbados', |
|
| 85 | - 'by' => 'Belarus', |
|
| 86 | - 'be' => 'Belgium', |
|
| 87 | - 'bz' => 'Belize', |
|
| 88 | - 'bj' => 'Benin', |
|
| 89 | - 'bm' => 'Bermuda', |
|
| 90 | - 'bt' => 'Bhutan', |
|
| 91 | - 'bo' => 'Bolivia', |
|
| 92 | - // Uses Netherlands' flag, see https://en.wikipedia.org/wiki/Caribbean_Netherlands. |
|
| 93 | - 'bq' => 'Netherlands', |
|
| 94 | - 'ba' => 'Bosnia-and-Herzegovina', |
|
| 95 | - 'bw' => 'Botswana', |
|
| 96 | - 'bv' => 'Bouvet Island', |
|
| 97 | - 'br' => 'Brazil', |
|
| 98 | - 'io' => null, |
|
| 99 | - 'bn' => 'Brunei', |
|
| 100 | - 'bg' => 'Bulgaria', |
|
| 101 | - 'bf' => 'Burkina-Faso', |
|
| 102 | - 'bi' => 'Burundi', |
|
| 103 | - 'kh' => 'Cambodia', |
|
| 104 | - 'cm' => 'Cameroon', |
|
| 105 | - 'ca' => 'Canada', |
|
| 106 | - 'cv' => 'Cape-Verde', |
|
| 107 | - 'ky' => 'Cayman-Islands', |
|
| 108 | - 'cf' => 'Central-African-Republic', |
|
| 109 | - 'td' => 'Chad', |
|
| 110 | - 'cl' => 'Chile', |
|
| 111 | - 'cn' => 'China', |
|
| 112 | - 'cx' => 'Christmas-Island', |
|
| 113 | - 'cc' => 'Cocos-Keeling-Islands', |
|
| 114 | - 'co' => 'Colombia', |
|
| 115 | - 'km' => 'Comoros', |
|
| 116 | - 'cg' => 'Republic-of-the-Congo', |
|
| 117 | - 'cd' => 'Democratic-Republic-of-the-Congo', |
|
| 118 | - 'ck' => 'Cook-Islands', |
|
| 119 | - 'cr' => 'Costa-Rica', |
|
| 120 | - 'ci' => 'Cote-dIvoire', |
|
| 121 | - 'hr' => 'Croatia', |
|
| 122 | - 'cu' => 'Cuba', |
|
| 123 | - 'cw' => 'Curacao', |
|
| 124 | - 'cy' => 'Cyprus', |
|
| 125 | - 'cz' => 'Czech-Republic', |
|
| 126 | - 'dk' => 'Denmark', |
|
| 127 | - 'dj' => 'Djibouti', |
|
| 128 | - 'dm' => 'Dominica', |
|
| 129 | - 'do' => 'Dominican-Republic', |
|
| 130 | - 'ec' => 'Ecuador', |
|
| 131 | - 'eg' => 'Egypt', |
|
| 132 | - 'sv' => 'El-Salvador', |
|
| 133 | - 'gq' => 'Equatorial-Guinea', |
|
| 134 | - 'er' => 'Eritrea', |
|
| 135 | - 'ee' => 'Estonia', |
|
| 136 | - 'et' => 'Ethiopia', |
|
| 137 | - 'fk' => 'Falkland-Islands', |
|
| 138 | - 'fo' => 'Faroes', |
|
| 139 | - 'fj' => 'Fiji', |
|
| 140 | - 'fi' => 'Finland', |
|
| 141 | - 'fr' => 'France', |
|
| 142 | - // Uses France's flag, see https://en.wikipedia.org/wiki/French_Guiana. |
|
| 143 | - 'gf' => 'France', |
|
| 144 | - 'pf' => 'French-Polynesia', |
|
| 145 | - 'tf' => 'French-Southern-Territories', |
|
| 146 | - 'ga' => 'Gabon', |
|
| 147 | - 'gm' => 'Gambia', |
|
| 148 | - 'ge' => 'Georgia', |
|
| 149 | - 'de' => 'Germany', |
|
| 150 | - 'gh' => 'Ghana', |
|
| 151 | - 'gi' => 'Gibraltar', |
|
| 152 | - 'gr' => 'Greece', |
|
| 153 | - 'gl' => 'Greenland', |
|
| 154 | - 'gd' => 'Grenada', |
|
| 155 | - // Uses France's flag, see https://en.wikipedia.org/wiki/Guadeloupe. |
|
| 156 | - 'gp' => 'France', |
|
| 157 | - 'gu' => 'Guam', |
|
| 158 | - 'gt' => 'Guatemala', |
|
| 159 | - 'gg' => 'Guernsey', |
|
| 160 | - 'gn' => 'Guinea', |
|
| 161 | - 'gw' => 'Guinea-Bissau', |
|
| 162 | - 'gy' => 'Guyana', |
|
| 163 | - 'ht' => 'Haiti', |
|
| 164 | - // Uses Australia's flag, see https://en.wikipedia.org/wiki/Heard_Island_and_McDonald_Islands. |
|
| 165 | - 'hm' => 'Australia', |
|
| 166 | - 'va' => 'Vatican-City', |
|
| 167 | - 'hn' => 'Honduras', |
|
| 168 | - 'hk' => 'Hong-Kong', |
|
| 169 | - 'hu' => 'Hungary', |
|
| 170 | - 'is' => 'Iceland', |
|
| 171 | - 'in' => 'India', |
|
| 172 | - 'id' => 'Indonesia', |
|
| 173 | - 'ir' => 'Iran', |
|
| 174 | - 'iq' => 'Iraq', |
|
| 175 | - 'ie' => 'Ireland', |
|
| 176 | - 'im' => 'Isle-of-Man', |
|
| 177 | - 'il' => 'Israel', |
|
| 178 | - 'it' => 'Italy', |
|
| 179 | - 'jm' => 'Jamaica', |
|
| 180 | - 'jp' => 'Japan', |
|
| 181 | - 'je' => 'Jersey', |
|
| 182 | - 'jo' => 'Jordan', |
|
| 183 | - 'kz' => 'Kazakhstan', |
|
| 184 | - 'ke' => 'Kenya', |
|
| 185 | - 'ki' => 'Kiribati', |
|
| 186 | - 'kp' => 'North-Korea', |
|
| 187 | - 'kr' => 'South-Korea', |
|
| 188 | - 'kw' => 'Kuwait', |
|
| 189 | - 'kg' => 'Kyrgyzstan', |
|
| 190 | - 'la' => 'Laos', |
|
| 191 | - 'lv' => 'Latvia', |
|
| 192 | - 'lb' => 'Lebanon', |
|
| 193 | - 'ls' => 'Lesotho', |
|
| 194 | - 'lr' => 'Liberia', |
|
| 195 | - 'ly' => 'Libya', |
|
| 196 | - 'li' => 'Liechtenstein', |
|
| 197 | - 'lt' => 'Lithuania', |
|
| 198 | - 'lu' => 'Luxembourg', |
|
| 199 | - 'mo' => 'Macau', |
|
| 200 | - 'mk' => 'Macedonia', |
|
| 201 | - 'mg' => 'Madagascar', |
|
| 202 | - 'mw' => 'Malawi', |
|
| 203 | - 'my' => 'Malaysia', |
|
| 204 | - 'mv' => 'Maldives', |
|
| 205 | - 'ml' => 'Mali', |
|
| 206 | - 'mt' => 'Malta', |
|
| 207 | - 'mh' => 'Marshall-Islands', |
|
| 208 | - 'mq' => 'Martinique', |
|
| 209 | - 'mr' => 'Mauritania', |
|
| 210 | - 'mu' => 'Mauritius', |
|
| 211 | - 'yt' => 'Mayotte', |
|
| 212 | - 'mx' => 'Mexico', |
|
| 213 | - 'fm' => 'Micronesia', |
|
| 214 | - 'md' => 'Moldova', |
|
| 215 | - 'mc' => 'Monaco', |
|
| 216 | - 'mn' => 'Mongolia', |
|
| 217 | - 'me' => 'Montenegro', |
|
| 218 | - 'ms' => 'Montserrat', |
|
| 219 | - 'ma' => 'Morocco', |
|
| 220 | - 'mz' => 'Mozambique', |
|
| 221 | - 'mm' => 'Myanmar', |
|
| 222 | - 'na' => 'Namibia', |
|
| 223 | - 'nr' => 'Nauru', |
|
| 224 | - 'np' => 'Nepal', |
|
| 225 | - 'nl' => 'Netherlands', |
|
| 226 | - 'nc' => 'New-Caledonia', |
|
| 227 | - 'nz' => 'New-Zealand', |
|
| 228 | - 'ni' => 'Nicaragua', |
|
| 229 | - 'ne' => 'Niger', |
|
| 230 | - 'ng' => 'Nigeria', |
|
| 231 | - 'nu' => 'Niue', |
|
| 232 | - 'nf' => 'Norfolk-Island', |
|
| 233 | - 'mp' => 'Northern-Mariana-Islands', |
|
| 234 | - 'no' => 'Norway', |
|
| 235 | - 'om' => 'Oman', |
|
| 236 | - 'pk' => 'Pakistan', |
|
| 237 | - 'pw' => 'Palau', |
|
| 238 | - 'ps' => 'Palestine', |
|
| 239 | - 'pa' => 'Panama', |
|
| 240 | - 'pg' => 'Papua-New-Guinea', |
|
| 241 | - 'py' => 'Paraguay', |
|
| 242 | - 'pe' => 'Peru', |
|
| 243 | - 'ph' => 'Philippines', |
|
| 244 | - 'pn' => 'Pitcairn-Islands', |
|
| 245 | - 'pl' => 'Poland', |
|
| 246 | - 'pt' => 'Portugal', |
|
| 247 | - 'pr' => 'Puerto Rico', |
|
| 248 | - 'qa' => 'Qatar', |
|
| 249 | - // Uses France's flag, see https://en.wikipedia.org/wiki/R%C3%A9union. |
|
| 250 | - 're' => 'France', |
|
| 251 | - 'ro' => 'Romania', |
|
| 252 | - 'ru' => 'Russia', |
|
| 253 | - 'rw' => 'Rwanda', |
|
| 254 | - 'bl' => 'Saint-Barthelemy', |
|
| 255 | - 'sh' => 'Saint-Helena', |
|
| 256 | - 'kn' => 'Saint-Kitts-and-Nevis', |
|
| 257 | - 'lc' => 'Saint-Lucia', |
|
| 258 | - 'mf' => 'Saint-Martin', |
|
| 259 | - // Uses France's flag, see https://en.wikipedia.org/wiki/Saint_Pierre_and_Miquelon. |
|
| 260 | - 'pm' => 'France', |
|
| 261 | - 'vc' => 'Saint-Vincent-and-the-Grenadines', |
|
| 262 | - 'ws' => 'Samoa', |
|
| 263 | - 'sm' => 'San-Marino', |
|
| 264 | - 'st' => 'Sao-Tome-and-Principe', |
|
| 265 | - 'sa' => 'Saudi-Arabia', |
|
| 266 | - 'sn' => 'Senegal', |
|
| 267 | - 'rs' => 'Serbia', |
|
| 268 | - 'sc' => 'Seychelles', |
|
| 269 | - 'sl' => 'Sierra-Leone', |
|
| 270 | - 'sg' => 'Singapore', |
|
| 271 | - 'sx' => null, |
|
| 272 | - 'sk' => 'Slovakia', |
|
| 273 | - 'si' => 'Slovenia', |
|
| 274 | - 'sb' => 'Solomon-Islands', |
|
| 275 | - 'so' => 'Somalia', |
|
| 276 | - 'za' => 'South-Africa', |
|
| 277 | - 'gs' => 'South-Georgia-and-the-South-Sandwich-Islands', |
|
| 278 | - 'ss' => 'South-Sudan', |
|
| 279 | - 'es' => 'Spain', |
|
| 280 | - 'lk' => 'Sri-Lanka', |
|
| 281 | - 'sd' => 'Sudan', |
|
| 282 | - 'sr' => 'Suriname', |
|
| 283 | - // Uses Norway's flag, see https://en.wikipedia.org/wiki/Svalbard_and_Jan_Mayen. |
|
| 284 | - 'sj' => 'Norway', |
|
| 285 | - 'sz' => 'Swaziland', |
|
| 286 | - 'se' => 'Sweden', |
|
| 287 | - 'ch' => 'Switzerland', |
|
| 288 | - 'sy' => 'Syria', |
|
| 289 | - 'tw' => 'Taiwan', |
|
| 290 | - 'tj' => 'Tajikistan', |
|
| 291 | - 'tz' => 'Tanzania', |
|
| 292 | - 'th' => 'Thailand', |
|
| 293 | - 'tl' => 'East-Timor', |
|
| 294 | - 'tg' => 'Togo', |
|
| 295 | - 'tk' => 'Tokelau', |
|
| 296 | - 'to' => 'Tonga', |
|
| 297 | - 'tt' => 'Trinidad-and-Tobago', |
|
| 298 | - 'tn' => 'Tunisia', |
|
| 299 | - 'tr' => 'Turkey', |
|
| 300 | - 'tm' => 'Turkmenistan', |
|
| 301 | - 'tc' => 'Turks-and-Caicos-Islands', |
|
| 302 | - 'tv' => 'Tuvalu', |
|
| 303 | - 'ug' => 'Uganda', |
|
| 304 | - 'ua' => 'Ukraine', |
|
| 305 | - 'ae' => 'United-Arab-Emirates', |
|
| 306 | - 'gb' => 'United-Kingdom', |
|
| 307 | - 'uk' => 'United-Kingdom', |
|
| 308 | - 'us' => 'United-States', |
|
| 309 | - 'um' => 'United-States', |
|
| 310 | - 'uy' => 'Uruguay', |
|
| 311 | - 'uz' => 'Uzbekistan', |
|
| 312 | - 'vu' => 'Vanuatu', |
|
| 313 | - 've' => 'Venezuela', |
|
| 314 | - 'vn' => 'Vietnam', |
|
| 315 | - 'vg' => 'British-Virgin-Islands', |
|
| 316 | - 'vi' => 'US-Virgin-Islands', |
|
| 317 | - 'wf' => 'Wallis-And-Futuna', |
|
| 318 | - 'eh' => 'Western-Sahara', |
|
| 319 | - 'ye' => 'Yemen', |
|
| 320 | - 'zm' => 'Zambia', |
|
| 321 | - 'zw' => 'Zimbabwe', |
|
| 322 | - ); |
|
| 57 | + /** |
|
| 58 | + * An array of flag filenames. |
|
| 59 | + * |
|
| 60 | + * @since 3.20.0 |
|
| 61 | + * |
|
| 62 | + * @var array An array of flag filenames. |
|
| 63 | + */ |
|
| 64 | + private static $country_flags = array( |
|
| 65 | + 'af' => 'Afghanistan', |
|
| 66 | + 'ax' => 'Aland', |
|
| 67 | + 'al' => 'Albania', |
|
| 68 | + 'dz' => 'Algeria', |
|
| 69 | + 'as' => 'American-Samoa', |
|
| 70 | + 'ad' => 'Andorra', |
|
| 71 | + 'ao' => 'Angola', |
|
| 72 | + 'ai' => 'Anguilla', |
|
| 73 | + 'aq' => 'Antarctica', |
|
| 74 | + 'ag' => 'Antigua-and-Barbuda', |
|
| 75 | + 'ar' => 'Argentina', |
|
| 76 | + 'am' => 'Armenia', |
|
| 77 | + 'aw' => 'Aruba', |
|
| 78 | + 'au' => 'Australia', |
|
| 79 | + 'at' => 'Austria', |
|
| 80 | + 'az' => 'Azerbaijan', |
|
| 81 | + 'bs' => 'Bahamas', |
|
| 82 | + 'bh' => 'Bahrain', |
|
| 83 | + 'bd' => 'Bangladesh', |
|
| 84 | + 'bb' => 'Barbados', |
|
| 85 | + 'by' => 'Belarus', |
|
| 86 | + 'be' => 'Belgium', |
|
| 87 | + 'bz' => 'Belize', |
|
| 88 | + 'bj' => 'Benin', |
|
| 89 | + 'bm' => 'Bermuda', |
|
| 90 | + 'bt' => 'Bhutan', |
|
| 91 | + 'bo' => 'Bolivia', |
|
| 92 | + // Uses Netherlands' flag, see https://en.wikipedia.org/wiki/Caribbean_Netherlands. |
|
| 93 | + 'bq' => 'Netherlands', |
|
| 94 | + 'ba' => 'Bosnia-and-Herzegovina', |
|
| 95 | + 'bw' => 'Botswana', |
|
| 96 | + 'bv' => 'Bouvet Island', |
|
| 97 | + 'br' => 'Brazil', |
|
| 98 | + 'io' => null, |
|
| 99 | + 'bn' => 'Brunei', |
|
| 100 | + 'bg' => 'Bulgaria', |
|
| 101 | + 'bf' => 'Burkina-Faso', |
|
| 102 | + 'bi' => 'Burundi', |
|
| 103 | + 'kh' => 'Cambodia', |
|
| 104 | + 'cm' => 'Cameroon', |
|
| 105 | + 'ca' => 'Canada', |
|
| 106 | + 'cv' => 'Cape-Verde', |
|
| 107 | + 'ky' => 'Cayman-Islands', |
|
| 108 | + 'cf' => 'Central-African-Republic', |
|
| 109 | + 'td' => 'Chad', |
|
| 110 | + 'cl' => 'Chile', |
|
| 111 | + 'cn' => 'China', |
|
| 112 | + 'cx' => 'Christmas-Island', |
|
| 113 | + 'cc' => 'Cocos-Keeling-Islands', |
|
| 114 | + 'co' => 'Colombia', |
|
| 115 | + 'km' => 'Comoros', |
|
| 116 | + 'cg' => 'Republic-of-the-Congo', |
|
| 117 | + 'cd' => 'Democratic-Republic-of-the-Congo', |
|
| 118 | + 'ck' => 'Cook-Islands', |
|
| 119 | + 'cr' => 'Costa-Rica', |
|
| 120 | + 'ci' => 'Cote-dIvoire', |
|
| 121 | + 'hr' => 'Croatia', |
|
| 122 | + 'cu' => 'Cuba', |
|
| 123 | + 'cw' => 'Curacao', |
|
| 124 | + 'cy' => 'Cyprus', |
|
| 125 | + 'cz' => 'Czech-Republic', |
|
| 126 | + 'dk' => 'Denmark', |
|
| 127 | + 'dj' => 'Djibouti', |
|
| 128 | + 'dm' => 'Dominica', |
|
| 129 | + 'do' => 'Dominican-Republic', |
|
| 130 | + 'ec' => 'Ecuador', |
|
| 131 | + 'eg' => 'Egypt', |
|
| 132 | + 'sv' => 'El-Salvador', |
|
| 133 | + 'gq' => 'Equatorial-Guinea', |
|
| 134 | + 'er' => 'Eritrea', |
|
| 135 | + 'ee' => 'Estonia', |
|
| 136 | + 'et' => 'Ethiopia', |
|
| 137 | + 'fk' => 'Falkland-Islands', |
|
| 138 | + 'fo' => 'Faroes', |
|
| 139 | + 'fj' => 'Fiji', |
|
| 140 | + 'fi' => 'Finland', |
|
| 141 | + 'fr' => 'France', |
|
| 142 | + // Uses France's flag, see https://en.wikipedia.org/wiki/French_Guiana. |
|
| 143 | + 'gf' => 'France', |
|
| 144 | + 'pf' => 'French-Polynesia', |
|
| 145 | + 'tf' => 'French-Southern-Territories', |
|
| 146 | + 'ga' => 'Gabon', |
|
| 147 | + 'gm' => 'Gambia', |
|
| 148 | + 'ge' => 'Georgia', |
|
| 149 | + 'de' => 'Germany', |
|
| 150 | + 'gh' => 'Ghana', |
|
| 151 | + 'gi' => 'Gibraltar', |
|
| 152 | + 'gr' => 'Greece', |
|
| 153 | + 'gl' => 'Greenland', |
|
| 154 | + 'gd' => 'Grenada', |
|
| 155 | + // Uses France's flag, see https://en.wikipedia.org/wiki/Guadeloupe. |
|
| 156 | + 'gp' => 'France', |
|
| 157 | + 'gu' => 'Guam', |
|
| 158 | + 'gt' => 'Guatemala', |
|
| 159 | + 'gg' => 'Guernsey', |
|
| 160 | + 'gn' => 'Guinea', |
|
| 161 | + 'gw' => 'Guinea-Bissau', |
|
| 162 | + 'gy' => 'Guyana', |
|
| 163 | + 'ht' => 'Haiti', |
|
| 164 | + // Uses Australia's flag, see https://en.wikipedia.org/wiki/Heard_Island_and_McDonald_Islands. |
|
| 165 | + 'hm' => 'Australia', |
|
| 166 | + 'va' => 'Vatican-City', |
|
| 167 | + 'hn' => 'Honduras', |
|
| 168 | + 'hk' => 'Hong-Kong', |
|
| 169 | + 'hu' => 'Hungary', |
|
| 170 | + 'is' => 'Iceland', |
|
| 171 | + 'in' => 'India', |
|
| 172 | + 'id' => 'Indonesia', |
|
| 173 | + 'ir' => 'Iran', |
|
| 174 | + 'iq' => 'Iraq', |
|
| 175 | + 'ie' => 'Ireland', |
|
| 176 | + 'im' => 'Isle-of-Man', |
|
| 177 | + 'il' => 'Israel', |
|
| 178 | + 'it' => 'Italy', |
|
| 179 | + 'jm' => 'Jamaica', |
|
| 180 | + 'jp' => 'Japan', |
|
| 181 | + 'je' => 'Jersey', |
|
| 182 | + 'jo' => 'Jordan', |
|
| 183 | + 'kz' => 'Kazakhstan', |
|
| 184 | + 'ke' => 'Kenya', |
|
| 185 | + 'ki' => 'Kiribati', |
|
| 186 | + 'kp' => 'North-Korea', |
|
| 187 | + 'kr' => 'South-Korea', |
|
| 188 | + 'kw' => 'Kuwait', |
|
| 189 | + 'kg' => 'Kyrgyzstan', |
|
| 190 | + 'la' => 'Laos', |
|
| 191 | + 'lv' => 'Latvia', |
|
| 192 | + 'lb' => 'Lebanon', |
|
| 193 | + 'ls' => 'Lesotho', |
|
| 194 | + 'lr' => 'Liberia', |
|
| 195 | + 'ly' => 'Libya', |
|
| 196 | + 'li' => 'Liechtenstein', |
|
| 197 | + 'lt' => 'Lithuania', |
|
| 198 | + 'lu' => 'Luxembourg', |
|
| 199 | + 'mo' => 'Macau', |
|
| 200 | + 'mk' => 'Macedonia', |
|
| 201 | + 'mg' => 'Madagascar', |
|
| 202 | + 'mw' => 'Malawi', |
|
| 203 | + 'my' => 'Malaysia', |
|
| 204 | + 'mv' => 'Maldives', |
|
| 205 | + 'ml' => 'Mali', |
|
| 206 | + 'mt' => 'Malta', |
|
| 207 | + 'mh' => 'Marshall-Islands', |
|
| 208 | + 'mq' => 'Martinique', |
|
| 209 | + 'mr' => 'Mauritania', |
|
| 210 | + 'mu' => 'Mauritius', |
|
| 211 | + 'yt' => 'Mayotte', |
|
| 212 | + 'mx' => 'Mexico', |
|
| 213 | + 'fm' => 'Micronesia', |
|
| 214 | + 'md' => 'Moldova', |
|
| 215 | + 'mc' => 'Monaco', |
|
| 216 | + 'mn' => 'Mongolia', |
|
| 217 | + 'me' => 'Montenegro', |
|
| 218 | + 'ms' => 'Montserrat', |
|
| 219 | + 'ma' => 'Morocco', |
|
| 220 | + 'mz' => 'Mozambique', |
|
| 221 | + 'mm' => 'Myanmar', |
|
| 222 | + 'na' => 'Namibia', |
|
| 223 | + 'nr' => 'Nauru', |
|
| 224 | + 'np' => 'Nepal', |
|
| 225 | + 'nl' => 'Netherlands', |
|
| 226 | + 'nc' => 'New-Caledonia', |
|
| 227 | + 'nz' => 'New-Zealand', |
|
| 228 | + 'ni' => 'Nicaragua', |
|
| 229 | + 'ne' => 'Niger', |
|
| 230 | + 'ng' => 'Nigeria', |
|
| 231 | + 'nu' => 'Niue', |
|
| 232 | + 'nf' => 'Norfolk-Island', |
|
| 233 | + 'mp' => 'Northern-Mariana-Islands', |
|
| 234 | + 'no' => 'Norway', |
|
| 235 | + 'om' => 'Oman', |
|
| 236 | + 'pk' => 'Pakistan', |
|
| 237 | + 'pw' => 'Palau', |
|
| 238 | + 'ps' => 'Palestine', |
|
| 239 | + 'pa' => 'Panama', |
|
| 240 | + 'pg' => 'Papua-New-Guinea', |
|
| 241 | + 'py' => 'Paraguay', |
|
| 242 | + 'pe' => 'Peru', |
|
| 243 | + 'ph' => 'Philippines', |
|
| 244 | + 'pn' => 'Pitcairn-Islands', |
|
| 245 | + 'pl' => 'Poland', |
|
| 246 | + 'pt' => 'Portugal', |
|
| 247 | + 'pr' => 'Puerto Rico', |
|
| 248 | + 'qa' => 'Qatar', |
|
| 249 | + // Uses France's flag, see https://en.wikipedia.org/wiki/R%C3%A9union. |
|
| 250 | + 're' => 'France', |
|
| 251 | + 'ro' => 'Romania', |
|
| 252 | + 'ru' => 'Russia', |
|
| 253 | + 'rw' => 'Rwanda', |
|
| 254 | + 'bl' => 'Saint-Barthelemy', |
|
| 255 | + 'sh' => 'Saint-Helena', |
|
| 256 | + 'kn' => 'Saint-Kitts-and-Nevis', |
|
| 257 | + 'lc' => 'Saint-Lucia', |
|
| 258 | + 'mf' => 'Saint-Martin', |
|
| 259 | + // Uses France's flag, see https://en.wikipedia.org/wiki/Saint_Pierre_and_Miquelon. |
|
| 260 | + 'pm' => 'France', |
|
| 261 | + 'vc' => 'Saint-Vincent-and-the-Grenadines', |
|
| 262 | + 'ws' => 'Samoa', |
|
| 263 | + 'sm' => 'San-Marino', |
|
| 264 | + 'st' => 'Sao-Tome-and-Principe', |
|
| 265 | + 'sa' => 'Saudi-Arabia', |
|
| 266 | + 'sn' => 'Senegal', |
|
| 267 | + 'rs' => 'Serbia', |
|
| 268 | + 'sc' => 'Seychelles', |
|
| 269 | + 'sl' => 'Sierra-Leone', |
|
| 270 | + 'sg' => 'Singapore', |
|
| 271 | + 'sx' => null, |
|
| 272 | + 'sk' => 'Slovakia', |
|
| 273 | + 'si' => 'Slovenia', |
|
| 274 | + 'sb' => 'Solomon-Islands', |
|
| 275 | + 'so' => 'Somalia', |
|
| 276 | + 'za' => 'South-Africa', |
|
| 277 | + 'gs' => 'South-Georgia-and-the-South-Sandwich-Islands', |
|
| 278 | + 'ss' => 'South-Sudan', |
|
| 279 | + 'es' => 'Spain', |
|
| 280 | + 'lk' => 'Sri-Lanka', |
|
| 281 | + 'sd' => 'Sudan', |
|
| 282 | + 'sr' => 'Suriname', |
|
| 283 | + // Uses Norway's flag, see https://en.wikipedia.org/wiki/Svalbard_and_Jan_Mayen. |
|
| 284 | + 'sj' => 'Norway', |
|
| 285 | + 'sz' => 'Swaziland', |
|
| 286 | + 'se' => 'Sweden', |
|
| 287 | + 'ch' => 'Switzerland', |
|
| 288 | + 'sy' => 'Syria', |
|
| 289 | + 'tw' => 'Taiwan', |
|
| 290 | + 'tj' => 'Tajikistan', |
|
| 291 | + 'tz' => 'Tanzania', |
|
| 292 | + 'th' => 'Thailand', |
|
| 293 | + 'tl' => 'East-Timor', |
|
| 294 | + 'tg' => 'Togo', |
|
| 295 | + 'tk' => 'Tokelau', |
|
| 296 | + 'to' => 'Tonga', |
|
| 297 | + 'tt' => 'Trinidad-and-Tobago', |
|
| 298 | + 'tn' => 'Tunisia', |
|
| 299 | + 'tr' => 'Turkey', |
|
| 300 | + 'tm' => 'Turkmenistan', |
|
| 301 | + 'tc' => 'Turks-and-Caicos-Islands', |
|
| 302 | + 'tv' => 'Tuvalu', |
|
| 303 | + 'ug' => 'Uganda', |
|
| 304 | + 'ua' => 'Ukraine', |
|
| 305 | + 'ae' => 'United-Arab-Emirates', |
|
| 306 | + 'gb' => 'United-Kingdom', |
|
| 307 | + 'uk' => 'United-Kingdom', |
|
| 308 | + 'us' => 'United-States', |
|
| 309 | + 'um' => 'United-States', |
|
| 310 | + 'uy' => 'Uruguay', |
|
| 311 | + 'uz' => 'Uzbekistan', |
|
| 312 | + 'vu' => 'Vanuatu', |
|
| 313 | + 've' => 'Venezuela', |
|
| 314 | + 'vn' => 'Vietnam', |
|
| 315 | + 'vg' => 'British-Virgin-Islands', |
|
| 316 | + 'vi' => 'US-Virgin-Islands', |
|
| 317 | + 'wf' => 'Wallis-And-Futuna', |
|
| 318 | + 'eh' => 'Western-Sahara', |
|
| 319 | + 'ye' => 'Yemen', |
|
| 320 | + 'zm' => 'Zambia', |
|
| 321 | + 'zw' => 'Zimbabwe', |
|
| 322 | + ); |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Parse_country_code_json_file_to_array. |
|
| 326 | - * |
|
| 327 | - * @param string $file_name The json file name where the supported country |
|
| 328 | - * and languages are present. |
|
| 329 | - * |
|
| 330 | - * @return array An Array having two maps, country_code_language_map and country_code_name_map. |
|
| 331 | - */ |
|
| 332 | - public static function parse_country_code_json_file_to_array( $file_name ) { |
|
| 333 | - $json_file_contents = file_get_contents( $file_name ); |
|
| 334 | - $decoded_array = json_decode( $json_file_contents, true ); |
|
| 335 | - // decoded array would be null if the json_decode parses |
|
| 336 | - // invalid content. |
|
| 337 | - if ( null === $decoded_array ) { |
|
| 338 | - return array( |
|
| 339 | - 'country_code_name_map' => array(), |
|
| 340 | - 'country_code_language_map' => array(), |
|
| 341 | - ); |
|
| 342 | - } |
|
| 343 | - $result = array(); |
|
| 344 | - // country_code => country_language map. |
|
| 345 | - $country_code_language_map = array(); |
|
| 346 | - // country_code => country_name map. |
|
| 347 | - $country_code_name_map = array(); |
|
| 348 | - foreach ( $decoded_array as $key => $value ) { |
|
| 349 | - $country_code_language_map[ $key ] = $value['supportedLang']; |
|
| 350 | - $country_code_name_map [ $key ] = $value['defaultLoc']['loc_name']; |
|
| 351 | - } |
|
| 352 | - $result['country_code_language_map'] = $country_code_language_map; |
|
| 353 | - $result['country_code_name_map'] = $country_code_name_map; |
|
| 354 | - return $result; |
|
| 355 | - } |
|
| 356 | - /** |
|
| 357 | - * Get the list of WordLift's supported country codes from json file mapping country_code => languages. |
|
| 358 | - * |
|
| 359 | - * @since 3.22.5.1 |
|
| 360 | - * |
|
| 361 | - * @param string $file_name The json file where the supported country codes and language_codes are stored. |
|
| 362 | - * |
|
| 363 | - * @return array An Array having two maps, country_code_language_map and country_code_name_map. |
|
| 364 | - */ |
|
| 365 | - public static function get_codes_from_json_file( $file_name ) { |
|
| 366 | - if ( file_exists( $file_name ) ) { |
|
| 367 | - return self::parse_country_code_json_file_to_array( $file_name ); |
|
| 368 | - } |
|
| 369 | - return array( |
|
| 370 | - 'country_code_name_map' => array(), |
|
| 371 | - 'country_code_language_map' => array(), |
|
| 372 | - ); |
|
| 373 | - } |
|
| 324 | + /** |
|
| 325 | + * Parse_country_code_json_file_to_array. |
|
| 326 | + * |
|
| 327 | + * @param string $file_name The json file name where the supported country |
|
| 328 | + * and languages are present. |
|
| 329 | + * |
|
| 330 | + * @return array An Array having two maps, country_code_language_map and country_code_name_map. |
|
| 331 | + */ |
|
| 332 | + public static function parse_country_code_json_file_to_array( $file_name ) { |
|
| 333 | + $json_file_contents = file_get_contents( $file_name ); |
|
| 334 | + $decoded_array = json_decode( $json_file_contents, true ); |
|
| 335 | + // decoded array would be null if the json_decode parses |
|
| 336 | + // invalid content. |
|
| 337 | + if ( null === $decoded_array ) { |
|
| 338 | + return array( |
|
| 339 | + 'country_code_name_map' => array(), |
|
| 340 | + 'country_code_language_map' => array(), |
|
| 341 | + ); |
|
| 342 | + } |
|
| 343 | + $result = array(); |
|
| 344 | + // country_code => country_language map. |
|
| 345 | + $country_code_language_map = array(); |
|
| 346 | + // country_code => country_name map. |
|
| 347 | + $country_code_name_map = array(); |
|
| 348 | + foreach ( $decoded_array as $key => $value ) { |
|
| 349 | + $country_code_language_map[ $key ] = $value['supportedLang']; |
|
| 350 | + $country_code_name_map [ $key ] = $value['defaultLoc']['loc_name']; |
|
| 351 | + } |
|
| 352 | + $result['country_code_language_map'] = $country_code_language_map; |
|
| 353 | + $result['country_code_name_map'] = $country_code_name_map; |
|
| 354 | + return $result; |
|
| 355 | + } |
|
| 356 | + /** |
|
| 357 | + * Get the list of WordLift's supported country codes from json file mapping country_code => languages. |
|
| 358 | + * |
|
| 359 | + * @since 3.22.5.1 |
|
| 360 | + * |
|
| 361 | + * @param string $file_name The json file where the supported country codes and language_codes are stored. |
|
| 362 | + * |
|
| 363 | + * @return array An Array having two maps, country_code_language_map and country_code_name_map. |
|
| 364 | + */ |
|
| 365 | + public static function get_codes_from_json_file( $file_name ) { |
|
| 366 | + if ( file_exists( $file_name ) ) { |
|
| 367 | + return self::parse_country_code_json_file_to_array( $file_name ); |
|
| 368 | + } |
|
| 369 | + return array( |
|
| 370 | + 'country_code_name_map' => array(), |
|
| 371 | + 'country_code_language_map' => array(), |
|
| 372 | + ); |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * Returns the country language pairs. |
|
| 377 | - * |
|
| 378 | - * @since 3.18.0 |
|
| 379 | - * |
|
| 380 | - * @return array The country language pairs. |
|
| 381 | - */ |
|
| 382 | - public static function get_codes() { |
|
| 383 | - return self::$codes; |
|
| 384 | - } |
|
| 385 | - /** |
|
| 386 | - * Populate self::codes and self::country_codes if not done before. |
|
| 387 | - * |
|
| 388 | - * @since 3.22.5.1 |
|
| 389 | - * |
|
| 390 | - * @param string $file_name The json file where the supported country codes and language_codes are stored. |
|
| 391 | - * |
|
| 392 | - * @return void |
|
| 393 | - */ |
|
| 394 | - private static function lazy_populate_codes_and_country_codes_array( $file_name ) { |
|
| 395 | - if ( null === $file_name ) { |
|
| 396 | - $file_name = __DIR__ . '/supported-countries.json'; |
|
| 397 | - } |
|
| 398 | - if ( 0 === count( self::$codes ) || 0 === count( self::$country_codes ) ) { |
|
| 399 | - // populate the two arrays. |
|
| 400 | - $result_array = self::get_codes_from_json_file( $file_name ); |
|
| 401 | - self::$codes = $result_array['country_code_language_map']; |
|
| 402 | - self::$country_codes = $result_array['country_code_name_map']; |
|
| 403 | - } |
|
| 375 | + /** |
|
| 376 | + * Returns the country language pairs. |
|
| 377 | + * |
|
| 378 | + * @since 3.18.0 |
|
| 379 | + * |
|
| 380 | + * @return array The country language pairs. |
|
| 381 | + */ |
|
| 382 | + public static function get_codes() { |
|
| 383 | + return self::$codes; |
|
| 384 | + } |
|
| 385 | + /** |
|
| 386 | + * Populate self::codes and self::country_codes if not done before. |
|
| 387 | + * |
|
| 388 | + * @since 3.22.5.1 |
|
| 389 | + * |
|
| 390 | + * @param string $file_name The json file where the supported country codes and language_codes are stored. |
|
| 391 | + * |
|
| 392 | + * @return void |
|
| 393 | + */ |
|
| 394 | + private static function lazy_populate_codes_and_country_codes_array( $file_name ) { |
|
| 395 | + if ( null === $file_name ) { |
|
| 396 | + $file_name = __DIR__ . '/supported-countries.json'; |
|
| 397 | + } |
|
| 398 | + if ( 0 === count( self::$codes ) || 0 === count( self::$country_codes ) ) { |
|
| 399 | + // populate the two arrays. |
|
| 400 | + $result_array = self::get_codes_from_json_file( $file_name ); |
|
| 401 | + self::$codes = $result_array['country_code_language_map']; |
|
| 402 | + self::$country_codes = $result_array['country_code_name_map']; |
|
| 403 | + } |
|
| 404 | 404 | |
| 405 | - } |
|
| 405 | + } |
|
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * Reset codes_and_country_codes static variable, used for testing |
|
| 409 | - * |
|
| 410 | - * @since 3.22.5.1 |
|
| 411 | - * |
|
| 412 | - * @return void |
|
| 413 | - */ |
|
| 414 | - public static function reset_codes_and_country_codes() { |
|
| 415 | - self::$codes = array(); |
|
| 416 | - self::$country_codes = array(); |
|
| 417 | - } |
|
| 407 | + /** |
|
| 408 | + * Reset codes_and_country_codes static variable, used for testing |
|
| 409 | + * |
|
| 410 | + * @since 3.22.5.1 |
|
| 411 | + * |
|
| 412 | + * @return void |
|
| 413 | + */ |
|
| 414 | + public static function reset_codes_and_country_codes() { |
|
| 415 | + self::$codes = array(); |
|
| 416 | + self::$country_codes = array(); |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | 419 | |
| 420 | - /** |
|
| 421 | - * Get the list of WordLift's supported countries in an array with country code => country name pairs. |
|
| 422 | - * |
|
| 423 | - * @since 3.18.0 |
|
| 424 | - * |
|
| 425 | - * @param string|false $lang Optional. The language code we are looking for. Default `any`. |
|
| 426 | - * |
|
| 427 | - * @param string|null $file_name Optional. The json file containing country codes |
|
| 428 | - * and language data. |
|
| 429 | - * |
|
| 430 | - * @return array An array with country code => country name pairs. |
|
| 431 | - */ |
|
| 432 | - public static function get_countries( $lang = false, $file_name = null ) { |
|
| 433 | - // populate the codes and countries array if it is not done before. |
|
| 434 | - self::lazy_populate_codes_and_country_codes_array( $file_name ); |
|
| 435 | - // Lazily load the countries. |
|
| 436 | - $lang_key = false === $lang ? 'any' : $lang; |
|
| 437 | - if ( isset( self::$countries[ $lang_key ] ) ) { |
|
| 438 | - return self::$countries[ $lang_key ]; |
|
| 439 | - } |
|
| 420 | + /** |
|
| 421 | + * Get the list of WordLift's supported countries in an array with country code => country name pairs. |
|
| 422 | + * |
|
| 423 | + * @since 3.18.0 |
|
| 424 | + * |
|
| 425 | + * @param string|false $lang Optional. The language code we are looking for. Default `any`. |
|
| 426 | + * |
|
| 427 | + * @param string|null $file_name Optional. The json file containing country codes |
|
| 428 | + * and language data. |
|
| 429 | + * |
|
| 430 | + * @return array An array with country code => country name pairs. |
|
| 431 | + */ |
|
| 432 | + public static function get_countries( $lang = false, $file_name = null ) { |
|
| 433 | + // populate the codes and countries array if it is not done before. |
|
| 434 | + self::lazy_populate_codes_and_country_codes_array( $file_name ); |
|
| 435 | + // Lazily load the countries. |
|
| 436 | + $lang_key = false === $lang ? 'any' : $lang; |
|
| 437 | + if ( isset( self::$countries[ $lang_key ] ) ) { |
|
| 438 | + return self::$countries[ $lang_key ]; |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - // Prepare the array. |
|
| 442 | - self::$countries[ $lang ] = array(); |
|
| 441 | + // Prepare the array. |
|
| 442 | + self::$countries[ $lang ] = array(); |
|
| 443 | 443 | |
| 444 | - // Get the country names from WP's own (multisite) function. |
|
| 445 | - foreach ( self::$codes as $key => $languages ) { |
|
| 446 | - if ( |
|
| 447 | - // Process all countries if there is no language specified. |
|
| 448 | - empty( $lang ) || |
|
| 444 | + // Get the country names from WP's own (multisite) function. |
|
| 445 | + foreach ( self::$codes as $key => $languages ) { |
|
| 446 | + if ( |
|
| 447 | + // Process all countries if there is no language specified. |
|
| 448 | + empty( $lang ) || |
|
| 449 | 449 | |
| 450 | - // Or if there are no language limitations for current country. |
|
| 451 | - empty( self::$codes[ $key ] ) || |
|
| 450 | + // Or if there are no language limitations for current country. |
|
| 451 | + empty( self::$codes[ $key ] ) || |
|
| 452 | 452 | |
| 453 | - // Or if the language code exists for current country. |
|
| 454 | - ! empty( $lang ) && in_array( $lang, self::$codes[ $key ] ) |
|
| 455 | - ) { |
|
| 456 | - self::$countries[ $lang_key ][ $key ] = self::format_country_code( $key ); |
|
| 457 | - } |
|
| 458 | - } |
|
| 453 | + // Or if the language code exists for current country. |
|
| 454 | + ! empty( $lang ) && in_array( $lang, self::$codes[ $key ] ) |
|
| 455 | + ) { |
|
| 456 | + self::$countries[ $lang_key ][ $key ] = self::format_country_code( $key ); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - // Sort by country name. |
|
| 461 | - asort( self::$countries[ $lang_key ] ); |
|
| 460 | + // Sort by country name. |
|
| 461 | + asort( self::$countries[ $lang_key ] ); |
|
| 462 | 462 | |
| 463 | - // We don't sort here because `asort` returns bool instead of sorted array. |
|
| 464 | - return self::$countries[ $lang_key ]; |
|
| 465 | - } |
|
| 463 | + // We don't sort here because `asort` returns bool instead of sorted array. |
|
| 464 | + return self::$countries[ $lang_key ]; |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - /** |
|
| 468 | - * Returns the country for a country code. This function is a clone of WP's function provided in `ms.php`. |
|
| 469 | - * |
|
| 470 | - * @since 3.18.0 |
|
| 471 | - * |
|
| 472 | - * @param string $code Optional. The two-letter country code. Default empty. |
|
| 473 | - * |
|
| 474 | - * @return string The country corresponding to $code if it exists. If it does not exist, |
|
| 475 | - * then the first two letters of $code is returned. |
|
| 476 | - */ |
|
| 477 | - private static function format_country_code( $code = '' ) { |
|
| 467 | + /** |
|
| 468 | + * Returns the country for a country code. This function is a clone of WP's function provided in `ms.php`. |
|
| 469 | + * |
|
| 470 | + * @since 3.18.0 |
|
| 471 | + * |
|
| 472 | + * @param string $code Optional. The two-letter country code. Default empty. |
|
| 473 | + * |
|
| 474 | + * @return string The country corresponding to $code if it exists. If it does not exist, |
|
| 475 | + * then the first two letters of $code is returned. |
|
| 476 | + */ |
|
| 477 | + private static function format_country_code( $code = '' ) { |
|
| 478 | 478 | |
| 479 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 480 | - /** |
|
| 481 | - * Filters the country codes. |
|
| 482 | - * |
|
| 483 | - * @since 3.18.0 |
|
| 484 | - * |
|
| 485 | - * @param array $country_codes Key/value pair of country codes where key is the short version. |
|
| 486 | - * @param string $code A two-letter designation of the country. |
|
| 487 | - */ |
|
| 488 | - $country_codes = apply_filters( 'country_code', self::$country_codes, $code ); |
|
| 479 | + $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 480 | + /** |
|
| 481 | + * Filters the country codes. |
|
| 482 | + * |
|
| 483 | + * @since 3.18.0 |
|
| 484 | + * |
|
| 485 | + * @param array $country_codes Key/value pair of country codes where key is the short version. |
|
| 486 | + * @param string $code A two-letter designation of the country. |
|
| 487 | + */ |
|
| 488 | + $country_codes = apply_filters( 'country_code', self::$country_codes, $code ); |
|
| 489 | 489 | |
| 490 | - return strtr( $code, $country_codes ); |
|
| 491 | - } |
|
| 490 | + return strtr( $code, $country_codes ); |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | - /** |
|
| 494 | - * Get a flag URL. |
|
| 495 | - * |
|
| 496 | - * @since 3.20.0 |
|
| 497 | - * |
|
| 498 | - * @param string $country_code The country code. |
|
| 499 | - * |
|
| 500 | - * @return string|null The flag url or null if not available. |
|
| 501 | - */ |
|
| 502 | - public static function get_flag_url( $country_code ) { |
|
| 493 | + /** |
|
| 494 | + * Get a flag URL. |
|
| 495 | + * |
|
| 496 | + * @since 3.20.0 |
|
| 497 | + * |
|
| 498 | + * @param string $country_code The country code. |
|
| 499 | + * |
|
| 500 | + * @return string|null The flag url or null if not available. |
|
| 501 | + */ |
|
| 502 | + public static function get_flag_url( $country_code ) { |
|
| 503 | 503 | |
| 504 | - // Bail out if we don't have the flag. |
|
| 505 | - if ( ! isset( self::$country_flags[ $country_code ] ) |
|
| 506 | - || is_null( self::$country_flags[ $country_code ] ) ) { |
|
| 507 | - return null; |
|
| 508 | - } |
|
| 504 | + // Bail out if we don't have the flag. |
|
| 505 | + if ( ! isset( self::$country_flags[ $country_code ] ) |
|
| 506 | + || is_null( self::$country_flags[ $country_code ] ) ) { |
|
| 507 | + return null; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - return plugin_dir_url( dirname( __FILE__ ) ) |
|
| 511 | - . 'images/flags/16/' |
|
| 512 | - . self::$country_flags[ $country_code ] |
|
| 513 | - . '.png'; |
|
| 514 | - } |
|
| 510 | + return plugin_dir_url( dirname( __FILE__ ) ) |
|
| 511 | + . 'images/flags/16/' |
|
| 512 | + . self::$country_flags[ $country_code ] |
|
| 513 | + . '.png'; |
|
| 514 | + } |
|
| 515 | 515 | |
| 516 | - /** |
|
| 517 | - * Get a country name given a country code. |
|
| 518 | - * |
|
| 519 | - * @since 3.20.0 |
|
| 520 | - * |
|
| 521 | - * @param string $country_code The 2-letters country code. |
|
| 522 | - * |
|
| 523 | - * @return null|string The country name (in English) or null if not found. |
|
| 524 | - */ |
|
| 525 | - public static function get_country_name( $country_code ) { |
|
| 516 | + /** |
|
| 517 | + * Get a country name given a country code. |
|
| 518 | + * |
|
| 519 | + * @since 3.20.0 |
|
| 520 | + * |
|
| 521 | + * @param string $country_code The 2-letters country code. |
|
| 522 | + * |
|
| 523 | + * @return null|string The country name (in English) or null if not found. |
|
| 524 | + */ |
|
| 525 | + public static function get_country_name( $country_code ) { |
|
| 526 | 526 | |
| 527 | - return self::$country_codes[ $country_code ]; |
|
| 528 | - } |
|
| 527 | + return self::$country_codes[ $country_code ]; |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | 530 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.18.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -329,12 +329,12 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return array An Array having two maps, country_code_language_map and country_code_name_map. |
| 331 | 331 | */ |
| 332 | - public static function parse_country_code_json_file_to_array( $file_name ) { |
|
| 333 | - $json_file_contents = file_get_contents( $file_name ); |
|
| 334 | - $decoded_array = json_decode( $json_file_contents, true ); |
|
| 332 | + public static function parse_country_code_json_file_to_array($file_name) { |
|
| 333 | + $json_file_contents = file_get_contents($file_name); |
|
| 334 | + $decoded_array = json_decode($json_file_contents, true); |
|
| 335 | 335 | // decoded array would be null if the json_decode parses |
| 336 | 336 | // invalid content. |
| 337 | - if ( null === $decoded_array ) { |
|
| 337 | + if (null === $decoded_array) { |
|
| 338 | 338 | return array( |
| 339 | 339 | 'country_code_name_map' => array(), |
| 340 | 340 | 'country_code_language_map' => array(), |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | $country_code_language_map = array(); |
| 346 | 346 | // country_code => country_name map. |
| 347 | 347 | $country_code_name_map = array(); |
| 348 | - foreach ( $decoded_array as $key => $value ) { |
|
| 349 | - $country_code_language_map[ $key ] = $value['supportedLang']; |
|
| 350 | - $country_code_name_map [ $key ] = $value['defaultLoc']['loc_name']; |
|
| 348 | + foreach ($decoded_array as $key => $value) { |
|
| 349 | + $country_code_language_map[$key] = $value['supportedLang']; |
|
| 350 | + $country_code_name_map [$key] = $value['defaultLoc']['loc_name']; |
|
| 351 | 351 | } |
| 352 | 352 | $result['country_code_language_map'] = $country_code_language_map; |
| 353 | 353 | $result['country_code_name_map'] = $country_code_name_map; |
@@ -362,9 +362,9 @@ discard block |
||
| 362 | 362 | * |
| 363 | 363 | * @return array An Array having two maps, country_code_language_map and country_code_name_map. |
| 364 | 364 | */ |
| 365 | - public static function get_codes_from_json_file( $file_name ) { |
|
| 366 | - if ( file_exists( $file_name ) ) { |
|
| 367 | - return self::parse_country_code_json_file_to_array( $file_name ); |
|
| 365 | + public static function get_codes_from_json_file($file_name) { |
|
| 366 | + if (file_exists($file_name)) { |
|
| 367 | + return self::parse_country_code_json_file_to_array($file_name); |
|
| 368 | 368 | } |
| 369 | 369 | return array( |
| 370 | 370 | 'country_code_name_map' => array(), |
@@ -391,13 +391,13 @@ discard block |
||
| 391 | 391 | * |
| 392 | 392 | * @return void |
| 393 | 393 | */ |
| 394 | - private static function lazy_populate_codes_and_country_codes_array( $file_name ) { |
|
| 395 | - if ( null === $file_name ) { |
|
| 396 | - $file_name = __DIR__ . '/supported-countries.json'; |
|
| 394 | + private static function lazy_populate_codes_and_country_codes_array($file_name) { |
|
| 395 | + if (null === $file_name) { |
|
| 396 | + $file_name = __DIR__.'/supported-countries.json'; |
|
| 397 | 397 | } |
| 398 | - if ( 0 === count( self::$codes ) || 0 === count( self::$country_codes ) ) { |
|
| 398 | + if (0 === count(self::$codes) || 0 === count(self::$country_codes)) { |
|
| 399 | 399 | // populate the two arrays. |
| 400 | - $result_array = self::get_codes_from_json_file( $file_name ); |
|
| 400 | + $result_array = self::get_codes_from_json_file($file_name); |
|
| 401 | 401 | self::$codes = $result_array['country_code_language_map']; |
| 402 | 402 | self::$country_codes = $result_array['country_code_name_map']; |
| 403 | 403 | } |
@@ -429,39 +429,39 @@ discard block |
||
| 429 | 429 | * |
| 430 | 430 | * @return array An array with country code => country name pairs. |
| 431 | 431 | */ |
| 432 | - public static function get_countries( $lang = false, $file_name = null ) { |
|
| 432 | + public static function get_countries($lang = false, $file_name = null) { |
|
| 433 | 433 | // populate the codes and countries array if it is not done before. |
| 434 | - self::lazy_populate_codes_and_country_codes_array( $file_name ); |
|
| 434 | + self::lazy_populate_codes_and_country_codes_array($file_name); |
|
| 435 | 435 | // Lazily load the countries. |
| 436 | 436 | $lang_key = false === $lang ? 'any' : $lang; |
| 437 | - if ( isset( self::$countries[ $lang_key ] ) ) { |
|
| 438 | - return self::$countries[ $lang_key ]; |
|
| 437 | + if (isset(self::$countries[$lang_key])) { |
|
| 438 | + return self::$countries[$lang_key]; |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // Prepare the array. |
| 442 | - self::$countries[ $lang ] = array(); |
|
| 442 | + self::$countries[$lang] = array(); |
|
| 443 | 443 | |
| 444 | 444 | // Get the country names from WP's own (multisite) function. |
| 445 | - foreach ( self::$codes as $key => $languages ) { |
|
| 445 | + foreach (self::$codes as $key => $languages) { |
|
| 446 | 446 | if ( |
| 447 | 447 | // Process all countries if there is no language specified. |
| 448 | - empty( $lang ) || |
|
| 448 | + empty($lang) || |
|
| 449 | 449 | |
| 450 | 450 | // Or if there are no language limitations for current country. |
| 451 | - empty( self::$codes[ $key ] ) || |
|
| 451 | + empty(self::$codes[$key]) || |
|
| 452 | 452 | |
| 453 | 453 | // Or if the language code exists for current country. |
| 454 | - ! empty( $lang ) && in_array( $lang, self::$codes[ $key ] ) |
|
| 454 | + ! empty($lang) && in_array($lang, self::$codes[$key]) |
|
| 455 | 455 | ) { |
| 456 | - self::$countries[ $lang_key ][ $key ] = self::format_country_code( $key ); |
|
| 456 | + self::$countries[$lang_key][$key] = self::format_country_code($key); |
|
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // Sort by country name. |
| 461 | - asort( self::$countries[ $lang_key ] ); |
|
| 461 | + asort(self::$countries[$lang_key]); |
|
| 462 | 462 | |
| 463 | 463 | // We don't sort here because `asort` returns bool instead of sorted array. |
| 464 | - return self::$countries[ $lang_key ]; |
|
| 464 | + return self::$countries[$lang_key]; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -474,9 +474,9 @@ discard block |
||
| 474 | 474 | * @return string The country corresponding to $code if it exists. If it does not exist, |
| 475 | 475 | * then the first two letters of $code is returned. |
| 476 | 476 | */ |
| 477 | - private static function format_country_code( $code = '' ) { |
|
| 477 | + private static function format_country_code($code = '') { |
|
| 478 | 478 | |
| 479 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 479 | + $code = strtolower(substr($code, 0, 2)); |
|
| 480 | 480 | /** |
| 481 | 481 | * Filters the country codes. |
| 482 | 482 | * |
@@ -485,9 +485,9 @@ discard block |
||
| 485 | 485 | * @param array $country_codes Key/value pair of country codes where key is the short version. |
| 486 | 486 | * @param string $code A two-letter designation of the country. |
| 487 | 487 | */ |
| 488 | - $country_codes = apply_filters( 'country_code', self::$country_codes, $code ); |
|
| 488 | + $country_codes = apply_filters('country_code', self::$country_codes, $code); |
|
| 489 | 489 | |
| 490 | - return strtr( $code, $country_codes ); |
|
| 490 | + return strtr($code, $country_codes); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** |
@@ -499,17 +499,17 @@ discard block |
||
| 499 | 499 | * |
| 500 | 500 | * @return string|null The flag url or null if not available. |
| 501 | 501 | */ |
| 502 | - public static function get_flag_url( $country_code ) { |
|
| 502 | + public static function get_flag_url($country_code) { |
|
| 503 | 503 | |
| 504 | 504 | // Bail out if we don't have the flag. |
| 505 | - if ( ! isset( self::$country_flags[ $country_code ] ) |
|
| 506 | - || is_null( self::$country_flags[ $country_code ] ) ) { |
|
| 505 | + if ( ! isset(self::$country_flags[$country_code]) |
|
| 506 | + || is_null(self::$country_flags[$country_code])) { |
|
| 507 | 507 | return null; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - return plugin_dir_url( dirname( __FILE__ ) ) |
|
| 510 | + return plugin_dir_url(dirname(__FILE__)) |
|
| 511 | 511 | . 'images/flags/16/' |
| 512 | - . self::$country_flags[ $country_code ] |
|
| 512 | + . self::$country_flags[$country_code] |
|
| 513 | 513 | . '.png'; |
| 514 | 514 | } |
| 515 | 515 | |
@@ -522,9 +522,9 @@ discard block |
||
| 522 | 522 | * |
| 523 | 523 | * @return null|string The country name (in English) or null if not found. |
| 524 | 524 | */ |
| 525 | - public static function get_country_name( $country_code ) { |
|
| 525 | + public static function get_country_name($country_code) { |
|
| 526 | 526 | |
| 527 | - return self::$country_codes[ $country_code ]; |
|
| 527 | + return self::$country_codes[$country_code]; |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | } |