Skip to content

Commit

Permalink
Merge pull request #38 from krzysztofrewak/3.x
Browse files Browse the repository at this point in the history
adding + testing missing data
  • Loading branch information
danharrin authored Oct 15, 2021
2 parents cba502d + 1803632 commit 4ac71aa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/countries-de/resources/data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ gu,1671,Hagatna,gu,gum,oc,usd,🇬🇺,Guam
gw,245,Bissau,gw,gnb,af,xof,🇬🇼,Guinea-Bissau
gy,592,Georgetown,gy,guy,sa,gyd,🇬🇾,Guyana
hk,852,Hong Kong,hk,hkg,as,hkd,🇭🇰,Sonderverwaltungsregion Hongkong
hm,672,,hm,hmd,oc,,🇦🇺,Heard und McDonaldinseln
hn,504,Tegucigalpa,hn,hnd,na,hnl,🇭🇳,Honduras
hr,385,Zagreb,hr,hrv,eu,hrk,🇭🇷,Kroatien
ht,509,Port-au-Prince,ht,hti,na,htg,🇭🇹,Haiti
Expand Down
1 change: 1 addition & 0 deletions packages/countries-es/resources/data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ gu,1671,Hagatna,gu,gum,oc,usd,🇬🇺,Guam
gw,245,Bissau,gw,gnb,af,xof,🇬🇼,Guinea-Bisáu
gy,592,Georgetown,gy,guy,sa,gyd,🇬🇾,Guyana
hk,852,Hong Kong,hk,hkg,as,hkd,🇭🇰,RAE de Hong Kong (China)
hm,672,,hm,hmd,oc,,🇦🇺,Islas Heard y McDonald
hn,504,Tegucigalpa,hn,hnd,na,hnl,🇭🇳,Honduras
hr,385,Zagreb,hr,hrv,eu,hrk,🇭🇷,Croacia
ht,509,Port-au-Prince,ht,hti,na,htg,🇭🇹,Haití
Expand Down
1 change: 1 addition & 0 deletions packages/countries-fr/resources/data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ gu,1671,Hagatna,gu,gum,oc,usd,🇬🇺,Guam
gw,245,Bissau,gw,gnb,af,xof,🇬🇼,Guinée-Bissau
gy,592,Georgetown,gy,guy,sa,gyd,🇬🇾,Guyana
hk,852,Hong Kong,hk,hkg,as,hkd,🇭🇰,R.A.S. chinoise de Hong Kong
hm,672,,hm,hmd,oc,,🇦🇺,Îles Heard-et-MacDonald
hn,504,Tegucigalpa,hn,hnd,na,hnl,🇭🇳,Honduras
hr,385,Zagreb,hr,hrv,eu,hrk,🇭🇷,Croatie
ht,509,Port-au-Prince,ht,hti,na,htg,🇭🇹,Haïti
Expand Down
49 changes: 49 additions & 0 deletions tests/TranslationsConsistencyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Squire\Tests;

use Illuminate\Support\Collection;

class TranslationsConsistencyTest extends TestCase
{
protected const PACKAGES_DIRECTORY = './packages/';

/** @test */
public function are_data_files_consistent(): void
{
collect(glob(static::PACKAGES_DIRECTORY . '*', GLOB_ONLYDIR))
->filter(fn (string $name): bool => $this->isTranslatedPackageDirectory($name))
->map(fn (string $name): string => str_replace(static::PACKAGES_DIRECTORY, '', $name))
->groupBy(function (string $name): string {
$parts = explode('-', $name);
unset($parts[count($parts) - 1]);

return implode('-', $parts);
})
->filter(fn (Collection $translations): bool => $translations->count() > 1)
->each(function (Collection $translations, string $package): void {
$previous = null;

$translations->each(function (string $translation) use ($package, &$previous) {
$lines = count(explode('\n', file_get_contents(static::PACKAGES_DIRECTORY . $translation . '/resources/data.csv')));

if ($previous !== null) {
$this->assertSame($lines, $previous, "Number of data entires in {$package} is not the same for translations ($translation).");
}

$previous = $lines;
});
});
}

protected function isTranslatedPackageDirectory(string $name): bool
{
$parts = explode('-', $name);

if (count($parts) <= 1) {
return false;
}

return strlen($parts[count($parts) - 1]) === 2;
}
}

0 comments on commit 4ac71aa

Please sign in to comment.