Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -1331,12 +1331,63 @@ |
1332 | 1332 | |
1333 | 1333 | protected function stage_language( $type = 'request' ) { |
1334 | 1334 | $language = strtolower( $this->staged_data['language'] ); |
1335 | | - switch ( $language ){ |
1336 | | - case 'zh' : |
1337 | | - $this->staged_data['language'] = 'sc'; |
1338 | | - break; |
| 1335 | + |
| 1336 | + $count = 0; |
| 1337 | + //Count's just there making sure we don't get stuck here. |
| 1338 | + while ( !in_array( $language, $this->getAvailableLanguages() ) && $count < 3 ){ |
| 1339 | + //find the failback. |
| 1340 | + $language = $this->dataObj->getFailbackLanguage( $language ); |
| 1341 | + $count += 1; |
1339 | 1342 | } |
| 1343 | + |
| 1344 | + if ( !in_array( $language, $this->getAvailableLanguages() ) ){ |
| 1345 | + $language = 'en'; |
| 1346 | + } |
| 1347 | + |
| 1348 | + if ( $language === 'zh' ) { //Handles GC's mutant Chinese code. |
| 1349 | + $language = 'sc'; |
| 1350 | + } |
| 1351 | + |
| 1352 | + $this->staged_data['language'] = $language; |
1340 | 1353 | } |
| 1354 | + |
| 1355 | + /** |
| 1356 | + * OUR language codes which are available to use in GlobalCollect. |
| 1357 | + * @return string |
| 1358 | + */ |
| 1359 | + function getAvailableLanguages(){ |
| 1360 | + $languages = array( |
| 1361 | + 'ar', //Arabic |
| 1362 | + 'cz', //Czech |
| 1363 | + 'da', //Danish |
| 1364 | + 'nl', //Dutch |
| 1365 | + 'en', //English |
| 1366 | + 'fa', //Farsi |
| 1367 | + 'fi', //Finish |
| 1368 | + 'fr', //French |
| 1369 | + 'de', //German |
| 1370 | + 'he', //Hebrew |
| 1371 | + 'hi', //Hindi |
| 1372 | + 'hu', //Hungarian |
| 1373 | + 'it', //Italian |
| 1374 | + 'ja', //Japanese |
| 1375 | + 'ko', //Korean |
| 1376 | + 'no', //Norwegian |
| 1377 | + 'po', //Polish |
| 1378 | + 'pt', //Portuguese |
| 1379 | + 'ro', //Romanian |
| 1380 | + 'sl', //Slovene |
| 1381 | + 'es', //Spanish |
| 1382 | + 'sw', //Swahili |
| 1383 | + 'sv', //Swedish |
| 1384 | + 'th', //Thai |
| 1385 | + 'tr', //Turkish |
| 1386 | + 'ur', //Urdu |
| 1387 | + 'vi', //Vietnamese |
| 1388 | + 'zh', //the REAL chinese code. |
| 1389 | + ); |
| 1390 | + return $languages; |
| 1391 | + } |
1341 | 1392 | |
1342 | 1393 | /** |
1343 | 1394 | * Stage: amount |
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php |
— | — | @@ -944,6 +944,25 @@ |
945 | 945 | ); |
946 | 946 | return $stomp_fields; |
947 | 947 | } |
| 948 | + |
| 949 | + /** |
| 950 | + * getFailbackLanguage should return the code for a next-best-language, in |
| 951 | + * the event it is deemed unavailable by the gateway. |
| 952 | + * @param string $unavailable_language |
| 953 | + * @return string The code which the unavailable language should fail back |
| 954 | + * to. |
| 955 | + */ |
| 956 | + function getFailbackLanguage( $unavailable_language ){ |
| 957 | + $unavailable_language = strtolower($unavailable_language); |
| 958 | + |
| 959 | + //TODO: Something in here more complicated than defaulting to English. |
| 960 | + //Probably get a failback from MediaWiki if one exists, and if the code |
| 961 | + //doesn't change as part of that process, have a next-best language |
| 962 | + //identifier that we write? |
| 963 | + |
| 964 | + $failback = 'en'; |
| 965 | + return strtolower($failback); |
| 966 | + } |
948 | 967 | } |
949 | 968 | |
950 | 969 | ?> |