Skip to content

Commit 991bd24

Browse files
authored
feat: ḁdd xx-ŽA (#39)
add xx-ZA pseudo-locale as Zalgo commands
1 parent df8f1dd commit 991bd24

6 files changed

Lines changed: 106 additions & 0 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"ext-intl": "*",
2121
"ext-json": "*",
2222
"ext-mbstring": "*",
23+
"mdwheele/zalgo": "^0.3.1",
2324
"myclabs/php-enum": "^1.8",
2425
"nikic/php-parser": "^4.13",
2526
"psr/log": "^1 || ^2",

src/PseudoLocale/Converter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use FormatPHP\PseudoLocale\Locale\XxAc;
3636
use FormatPHP\PseudoLocale\Locale\XxHa;
3737
use FormatPHP\PseudoLocale\Locale\XxLs;
38+
use FormatPHP\PseudoLocale\Locale\XxZa;
3839
use FormatPHP\Util\FileSystemHelper;
3940
use FormatPHP\Util\FormatHelper;
4041
use Psr\Log\LoggerInterface;
@@ -58,6 +59,7 @@ class Converter
5859
PseudoLocale::XX_AC => XxAc::class,
5960
PseudoLocale::XX_HA => XxHa::class,
6061
PseudoLocale::XX_LS => XxLs::class,
62+
PseudoLocale::XX_ZA => XxZa::class,
6163
];
6264

6365
private ConverterOptions $options;

src/PseudoLocale/Locale/XxZa.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/**
4+
* This file is part of skillshare/formatphp
5+
*
6+
* skillshare/formatphp is open source software: you can distribute
7+
* it and/or modify it under the terms of the MIT License
8+
* (the "License"). You may not use this file except in
9+
* compliance with the License.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14+
* implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*
17+
* @copyright Copyright (c) Skillshare, Inc. <https://www.skillshare.com>
18+
* @license https://opensource.org/licenses/MIT MIT License
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace FormatPHP\PseudoLocale\Locale;
24+
25+
use FormatPHP\Icu\MessageFormat\Parser;
26+
use Zalgo\Mood;
27+
use Zalgo\Soul;
28+
use Zalgo\Zalgo;
29+
30+
/**
31+
* T̫̺̳o̬̜ ì̬͎̲̟nv̖̗̻̣̹̕o͖̗̠̜̤k͍͚̹͖̼e̦̗̪͍̪͍ ̬ͅt̕h̠͙̮͕͓e̱̜̗͙̭ ̥͔̫͙̪͍̣͝ḥi̼̦͈̼v҉̩̟͚̞͎e͈̟̻͙̦̤-m̷̘̝̱í͚̞̦̳n̝̲̯̙̮͞d̴̺̦͕̫ ̗̭̘͎͖r̞͎̜̜͖͎̫͢ep͇r̝̯̝͖͉͎̺e̴s̥e̵̖̳͉͍̩̗n̢͓̪͕̜̰̠̦t̺̞̰i͟n҉̮̦̖̟g̮͍̱̻͍̜̳ ̳c̖̮̙̣̰̠̩h̷̗͍̖͙̭͇͈a̧͎̯̹̲̺̫ó̭̞̜̣̯͕s̶̤̮̩̘.̨̻̪̖͔
32+
* ̳̭̦̭̭̦̞́I̠͍̮n͇̹̪̬v̴͖̭̗̖o̸k҉̬̤͓͚̠͍i͜n̛̩̹͉̘̹g͙ ̠̥ͅt̰͖͞h̫̼̪e̟̩̝ ̭̠̲̫͔fe̤͇̝̱e͖̮̠̹̭͖͕l͖̲̘͖̠̪i̢̖͎̮̗̯͓̩n̸̰g̙̱̘̗͚̬ͅ ͍o͍͍̩̮͢f̖͓̦̥ ̘͘c̵̫̱̗͚͓̦h͝a̝͍͍̳̣͖͉o͙̟s̤̞.̙̝̭̣̳̼͟
33+
* ̢̻͖͓̬̞̰̦W̮̲̝̼̩̝͖i͖͖͡ͅt̘̯͘h̷̬̖̞̙̰̭̳ ̭̪̕o̥̤̺̝̼̰̯͟ṳ̞̭̤t̨͚̥̗ ̟̺̫̩̤̳̩o̟̰̩̖ͅr̞̘̫̩̼d̡͍̬͎̪̺͚͔e͓͖̝̙r̰͖̲̲̻̠.̺̝̺̟͈
34+
* ̣̭T̪̩̼h̥̫̪͔̀e̫̯͜ ̨N̟e҉͔̤zp̮̭͈̟é͉͈ṛ̹̜̺̭͕d̺̪̜͇͓i̞á͕̹̣̻n͉͘ ̗͔̭͡h̲͖̣̺̺i͔̣̖̤͎̯v̠̯̘͖̭̱̯e̡̥͕-m͖̭̣̬̦͈i͖n̞̩͕̟̼̺͜d̘͉ ̯o̷͇̹͕̦f̰̱ ̝͓͉̱̪̪c͈̲̜̺h̘͚a̞͔̭̰̯̗̝o̙͍s͍͇̱͓.̵͕̰͙͈ͅ ̯̞͈̞̱̖Z̯̮̺̤̥̪̕a͏̺̗̼̬̗ḻg͢o̥̱̼.̺̜͇͡ͅ ̴͓͖̭̩͎̗
35+
* ̧̪͈̱̹̳͖͙H̵̰̤̰͕̖e̛ ͚͉̗̼̞w̶̩̥͉̮h̩̺̪̩͘ͅọ͎͉̟ ̜̩͔̦̘ͅW̪̫̩̣̲͔̳a͏͔̳͖i͖͜t͓̤̠͓͙s̘̰̩̥̙̝ͅ ̲̠̬̥Be̡̙̫̦h̰̩i̛̫͙͔̭̤̗̲n̳͞d̸ ͎̻͘T̛͇̝̲̹̠̗ͅh̫̦̝ͅe̩̫͟ ͓͖̼W͕̳͎͚̙̥ą̙l̘͚̺͔͞ͅl̳͍̙̤̤̮̳.̢
36+
* ̟̺̜̙͉Z̤̲̙̙͎̥̝A͎̣͔̙͘L̥̻̗̳̻̳̳͢G͉̖̯͓̞̩̦O̹̹̺!̙͈͎̞̬ *
37+
*/
38+
class XxZa extends AbstractLocale
39+
{
40+
private Zalgo $zalgo;
41+
42+
public function __construct()
43+
{
44+
/** @var Mood $mood */
45+
$mood = Mood::soothed();
46+
47+
$this->zalgo = new Zalgo(new Soul(), $mood);
48+
}
49+
50+
protected function generate(Parser\Type\ElementCollection $elementCollection): Parser\Type\ElementCollection
51+
{
52+
foreach ($elementCollection as $element) {
53+
if ($element instanceof Parser\Type\LiteralElement) {
54+
/** @var string $theWordOfZalgo */
55+
$theWordOfZalgo = $this->zalgo->speaks($element->value);
56+
$element->value = $theWordOfZalgo;
57+
} elseif ($element instanceof Parser\Type\PluralElement || $element instanceof Parser\Type\SelectElement) {
58+
foreach ($element->options as $option) {
59+
$this->generate($option->value);
60+
}
61+
} elseif ($element instanceof Parser\Type\TagElement) {
62+
$this->generate($element->children);
63+
}
64+
}
65+
66+
return $elementCollection;
67+
}
68+
}

src/PseudoLocale/PseudoLocale.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ class PseudoLocale
3232
public const XX_AC = 'xx-AC';
3333
public const XX_HA = 'xx-HA';
3434
public const XX_LS = 'xx-LS';
35+
public const XX_ZA = 'xx-ZA';
3536

3637
public const LOCALES = [
3738
self::EN_XA,
3839
self::EN_XB,
3940
self::XX_AC,
4041
self::XX_HA,
4142
self::XX_LS,
43+
self::XX_ZA,
4244
];
4345
}

tests/PseudoLocale/ConverterTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,35 @@ public function testConvertThrowsExceptionForUnknownPseudoLocale(): void
143143

144144
$converter->convert(__DIR__ . '/../fixtures/locales/en.json', 'en');
145145
}
146+
147+
/**
148+
* Zalgo is non-deterministic, so we can't use snapshot testing for it.
149+
*/
150+
public function testZalgo(): void
151+
{
152+
$outFile = 'php://output';
153+
154+
$fileSystemHelper = $this->mockery(FileSystemHelper::class)->makePartial();
155+
$fileSystemHelper->shouldReceive('writeContents')->withArgs(
156+
function (string $file, string $contents) use ($outFile): bool {
157+
$this->assertSame($outFile, $file);
158+
159+
// We're unable to deterministically test the $contents, since
160+
// Zalgo text changes each time it's generated.
161+
162+
return true;
163+
},
164+
);
165+
166+
$logger = $this->mockery(LoggerInterface::class);
167+
168+
$converter = new Converter(
169+
new ConverterOptions(),
170+
$fileSystemHelper,
171+
new FormatHelper($fileSystemHelper),
172+
$logger,
173+
);
174+
175+
$converter->convert(__DIR__ . '/../fixtures/locales/en.json', 'xx-ZA');
176+
}
146177
}

tests/PseudoLocale/Locale/AbstractLocaleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use FormatPHP\PseudoLocale\Locale\XxAc;
1212
use FormatPHP\PseudoLocale\Locale\XxHa;
1313
use FormatPHP\PseudoLocale\Locale\XxLs;
14+
use FormatPHP\PseudoLocale\Locale\XxZa;
1415
use FormatPHP\Test\TestCase;
1516

1617
class AbstractLocaleTest extends TestCase
@@ -36,6 +37,7 @@ public function provideLocales(): array
3637
'xx-AC' => ['locale' => new XxAc()],
3738
'xx-HA' => ['locale' => new XxHa()],
3839
'xx-LS' => ['locale' => new XxLs()],
40+
'xx-ZA' => ['locale' => new XxZa()],
3941
];
4042
}
4143
}

0 commit comments

Comments
 (0)