| 1286 | |
| 1287 | /** |
| 1288 | * Make sure translation actually works. |
| 1289 | * |
| 1290 | * Also make sure apostrophes and closing quotes aren't being confused by default. |
| 1291 | * |
| 1292 | * @ticket 27426 |
| 1293 | * @dataProvider data_tag_avoidance |
| 1294 | */ |
| 1295 | function test_translate( $input, $output ) { |
| 1296 | add_filter( 'gettext_with_context', array( 'Tests_Formatting_WPTexturize', 'filter_translate' ), 10, 4 ); |
| 1297 | |
| 1298 | $result = wptexturize( $input, true ); |
| 1299 | |
| 1300 | remove_filter( 'gettext_with_context', array( 'Tests_Formatting_WPTexturize', 'filter_translate' ), 10, 4 ); |
| 1301 | wptexturize( 'reset', true ); |
| 1302 | |
| 1303 | return $this->assertEquals( $output, $result ); |
| 1304 | } |
| 1305 | |
| 1306 | function filter_translate($translations, $text, $context, $domain) { |
| 1307 | switch ($text) { |
| 1308 | case '–' : return '!endash!'; |
| 1309 | case '—' : return '!emdash!'; |
| 1310 | case '‘' : return '!openq1!'; |
| 1311 | case '’' : |
| 1312 | if ( 'apostrophe' == $context ) { |
| 1313 | return '!apos!'; |
| 1314 | } else { |
| 1315 | return '!closeq1!'; |
| 1316 | } |
| 1317 | case '“' : return '!openq2!'; |
| 1318 | case '”' : return '!closeq2!'; |
| 1319 | case '′' : return '!prime1!'; |
| 1320 | case '″' : return '!prime2!'; |
| 1321 | default : return $translations; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | function data_translate() { |
| 1326 | return array( |
| 1327 | array( |
| 1328 | "word '99 word", |
| 1329 | "word !apos!99 word", |
| 1330 | ), |
| 1331 | array( |
| 1332 | "word'99 word", |
| 1333 | "word!apos!99 word", |
| 1334 | ), |
| 1335 | array( |
| 1336 | "word 'test sentence' word", |
| 1337 | "word !openq1!test sentence!closeq1! word", |
| 1338 | ), |
| 1339 | array( |
| 1340 | "'test sentence'", |
| 1341 | "!openq1!test sentence!closeq1!", |
| 1342 | ), |
| 1343 | array( |
| 1344 | 'word "test sentence" word', |
| 1345 | 'word !openq2!test sentence!closeq2! word', |
| 1346 | ), |
| 1347 | array( |
| 1348 | '"test sentence"', |
| 1349 | '!openq2!test sentence!closeq2!', |
| 1350 | ), |
| 1351 | array( |
| 1352 | "word 'word word", |
| 1353 | "word !openq1!word word", |
| 1354 | ), |
| 1355 | array( |
| 1356 | "word ('word word", |
| 1357 | "word (!openq1!word word", |
| 1358 | ), |
| 1359 | array( |
| 1360 | "word ['word word", |
| 1361 | "word [!openq1!word word", |
| 1362 | ), |
| 1363 | array( |
| 1364 | 'word 99" word', |
| 1365 | 'word 99!prime2! word', |
| 1366 | ), |
| 1367 | array( |
| 1368 | 'word 99"word', |
| 1369 | 'word 99!prime2!word', |
| 1370 | ), |
| 1371 | array( |
| 1372 | 'word99" word', |
| 1373 | 'word99!prime2! word', |
| 1374 | ), |
| 1375 | array( |
| 1376 | 'word99"word', |
| 1377 | 'word99!prime2!word', |
| 1378 | ), |
| 1379 | array( |
| 1380 | "word 99' word", |
| 1381 | "word 99!prime1! word", |
| 1382 | ), |
| 1383 | array( |
| 1384 | "word99' word", |
| 1385 | "word99!prime1! word", |
| 1386 | ), |
| 1387 | array( |
| 1388 | "word word's word", |
| 1389 | "word word!apos!s word", |
| 1390 | ), |
| 1391 | array( |
| 1392 | "word word'. word", |
| 1393 | "word word!closeq1!. word", |
| 1394 | ), |
| 1395 | array( |
| 1396 | "word ]'. word", |
| 1397 | "word ]!closeq1!. word", |
| 1398 | ), |
| 1399 | array( |
| 1400 | 'word "word word', |
| 1401 | 'word !openq2!word word', |
| 1402 | ), |
| 1403 | array( |
| 1404 | 'word ("word word', |
| 1405 | 'word (!openq2!word word', |
| 1406 | ), |
| 1407 | array( |
| 1408 | 'word ["word word', |
| 1409 | 'word [!openq2!word word', |
| 1410 | ), |
| 1411 | array( |
| 1412 | 'word word" word', |
| 1413 | 'word word!closeq2! word', |
| 1414 | ), |
| 1415 | array( |
| 1416 | 'word word") word', |
| 1417 | 'word word!closeq2!) word', |
| 1418 | ), |
| 1419 | array( |
| 1420 | 'word word"] word', |
| 1421 | 'word word!closeq2!] word', |
| 1422 | ), |
| 1423 | array( |
| 1424 | 'word word"', |
| 1425 | 'word word!closeq2!', |
| 1426 | ), |
| 1427 | array( |
| 1428 | 'word word"word', |
| 1429 | 'word word!closeq2!word', |
| 1430 | ), |
| 1431 | array( |
| 1432 | 'test sentence".', |
| 1433 | 'test sentence!closeq2!.', |
| 1434 | ), |
| 1435 | array( |
| 1436 | 'test sentence."', |
| 1437 | 'test sentence.!closeq2!', |
| 1438 | ), |
| 1439 | array( |
| 1440 | 'test sentence." word', |
| 1441 | 'test sentence.!closeq2! word', |
| 1442 | ), |
| 1443 | array( |
| 1444 | "word word' word", |
| 1445 | "word word!closeq1! word", |
| 1446 | ), |
| 1447 | array( |
| 1448 | "word word'. word", |
| 1449 | "word word!closeq1!. word", |
| 1450 | ), |
| 1451 | array( |
| 1452 | "word word'.word", |
| 1453 | "word word!closeq1!.word", |
| 1454 | ), |
| 1455 | array( |
| 1456 | "word word'", |
| 1457 | "word word!closeq1!", |
| 1458 | ), |
| 1459 | array( |
| 1460 | "test sentence'.", |
| 1461 | "test sentence!closeq1!.", |
| 1462 | ), |
| 1463 | array( |
| 1464 | "test sentence.'", |
| 1465 | "test sentence.!closeq1!", |
| 1466 | ), |
| 1467 | array( |
| 1468 | "test sentence'. word", |
| 1469 | "test sentence!closeq1!. word", |
| 1470 | ), |
| 1471 | array( |
| 1472 | "test sentence.' word", |
| 1473 | "test sentence.!closeq1! word", |
| 1474 | ), |
| 1475 | array( |
| 1476 | "word 'tain't word", |
| 1477 | "word !apos!tain!apos!t word", |
| 1478 | ), |
| 1479 | array( |
| 1480 | "word 'twere word", |
| 1481 | "word !apos!twere word", |
| 1482 | ), |
| 1483 | array( |
| 1484 | 'word "42.00" word', |
| 1485 | 'word !openq2!42.00!closeq2! word', |
| 1486 | ), |
| 1487 | array( |
| 1488 | "word '42.00' word", |
| 1489 | "word !openq1!42.00!closeq1! word", |
| 1490 | ), |
| 1491 | array( |
| 1492 | "word word'. word", |
| 1493 | "word word!closeq1!. word", |
| 1494 | ), |
| 1495 | array( |
| 1496 | "word word'.word", |
| 1497 | "word word!closeq1!.word", |
| 1498 | ), |
| 1499 | array( |
| 1500 | "word word', she said", |
| 1501 | "word word!closeq1!, she said", |
| 1502 | ), |
| 1503 | ); |
| 1504 | } |