Skip to content

Commit 5c0645e

Browse files
authored
Merge pull request #40 from php-gettext/check-usascii-exports
Check US-ASCII exports
2 parents b41b3a9 + b1d27f7 commit 5c0645e

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/Language.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,26 +389,23 @@ private static function asciifier(&$value)
389389
{
390390
if (is_string($value) && $value !== '') {
391391
// Avoid converting from 'Ÿ' to '"Y', let's prefer 'Y'
392-
$transliterated = strtr($value, array(
393-
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A',
392+
$value = strtr($value, array(
393+
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A',
394394
'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E',
395395
'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I',
396396
'Ñ' => 'N',
397397
'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O',
398398
'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U',
399399
'Ÿ' => 'Y', 'Ý' => 'Y',
400-
'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a',
400+
'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a',
401401
'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e',
402402
'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
403403
'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o',
404404
'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u',
405405
'ý' => 'y', 'ÿ' => 'y',
406+
'' => '...',
407+
'ʼ' => "'", '' => "'",
406408
));
407-
$transliterated = @iconv('UTF-8', 'US-ASCII//IGNORE//TRANSLIT', $transliterated);
408-
if ($transliterated === false || $transliterated === '') {
409-
throw new Exception("Unable to transliterate '{$value}'");
410-
}
411-
$value = $transliterated;
412409
}
413410
}
414411
}

tests/test/USAsciiTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Gettext\Languages\Test;
4+
5+
use Gettext\Languages\Exporter\Php;
6+
use Gettext\Languages\Language;
7+
8+
class USAsciiTest extends TestCase
9+
{
10+
public function testExportUSAscii()
11+
{
12+
$array = $this->getExportedPhpArray();
13+
foreach ($array as $localeID => $localeData) {
14+
$this->assertUSAscii($localeID, $localeData);
15+
}
16+
}
17+
18+
/**
19+
* @param string $key
20+
*/
21+
private function assertUSAscii($key, $value)
22+
{
23+
switch (gettype($value)) {
24+
case 'string':
25+
$this->assertSame(1, preg_match('/^[\x20-\x7F\n]*$/s', $value), "The string at {$key} does not contain only US-ASCII characters: {$value}");
26+
break;
27+
case 'array':
28+
foreach ($value as $valueKey => $valueValue) {
29+
$this->assertUSAscii("{$key}.{$valueKey}", $valueValue);
30+
}
31+
break;
32+
}
33+
}
34+
35+
/**
36+
* @return array
37+
*/
38+
private function getExportedPhpArray()
39+
{
40+
$phpCode = Php::toString(Language::getAll(), array('us-ascii' => true));
41+
42+
return eval(preg_replace('/^<\?php\n/', '', $phpCode));
43+
}
44+
}

0 commit comments

Comments
 (0)