-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensive alpha3 languages from ISO639-3 (#71)
- Loading branch information
1 parent
7bde634
commit f6a4bbd
Showing
6 changed files
with
8,028 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Daily Scripts spec update | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '55 17 * * *' | ||
|
||
jobs: | ||
update-specs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Install dependencies | ||
run: composer install | ||
- name: Run standard update command | ||
run: composer update-spec-language-extensive | ||
- name: Run CSFixer | ||
run: composer cs:fix | ||
- name: Create Pull Request | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
commit-message: Automatic Language Extensive spec update from upstream changes | ||
delete-branch: true | ||
title: 'Automatic Language Extensive spec update' | ||
branch: update-spec/language-extensive | ||
body: | | ||
This PR makes sure the content of this package is updated with upstream changes in the specs. | ||
labels: | | ||
spec-update | ||
automated pr | ||
reviewers: prinsfrank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Standards\Dev\DataSource\Mapping; | ||
|
||
use PrinsFrank\Standards\Dev\DataSource\Sorting\SortingInterface; | ||
use PrinsFrank\Standards\Dev\DataSource\Sorting\ValueWithDeprecatedTagsSeparateSorting; | ||
use PrinsFrank\Standards\Dev\DataTarget\EnumCase; | ||
use PrinsFrank\Standards\Dev\DataTarget\EnumFile; | ||
use PrinsFrank\Standards\Language\LanguageAlpha3Extensive; | ||
use Symfony\Component\Panther\Client; | ||
use Symfony\Component\Panther\DomCrawler\Crawler; | ||
|
||
/** | ||
* @template TDataSet of object{Id: string, Part2B: string, Part2T: string, Part1: string, Scope: string, LanguageType: string, RefName: string, Comment: string} | ||
* @implements Mapping<TDataSet> | ||
*/ | ||
class LanguageExtensiveMapping implements Mapping | ||
{ | ||
public static function url(): string | ||
{ | ||
return 'https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3_Latin1.tab'; | ||
} | ||
|
||
public static function toDataSet(Client $client, Crawler $crawler): array | ||
{ | ||
$dataSet = []; | ||
foreach (explode("\n", $client->getPageSource()) as $lineNumber => $line) { | ||
if ($lineNumber === 0) { | ||
continue; | ||
} | ||
|
||
$columns = explode("\t", $line); | ||
|
||
$record = (object) []; | ||
$record->Id = $columns[0]; | ||
$record->Part2B = $columns[1]; | ||
$record->Part2T = $columns[2]; | ||
$record->Part1 = $columns[3]; | ||
$record->Scope = $columns[4]; | ||
$record->LanguageType = $columns[5]; | ||
$record->RefName = $columns[6]; | ||
$record->Comment = $columns[7]; | ||
|
||
/** @var TDataSet $record */ | ||
$dataSet[] = $record; | ||
} | ||
|
||
return $dataSet; | ||
} | ||
|
||
public static function toEnumMapping(array $dataSet): array | ||
{ | ||
$languageExtensive = new EnumFile(LanguageAlpha3Extensive::class); | ||
foreach ($dataSet as $dataItem) { | ||
if (in_array($dataItem->RefName, ['Fa D\'ambu', 'C\'lela'], true)) { | ||
continue; | ||
} | ||
|
||
$languageExtensive->addCase(new EnumCase($dataItem->RefName, $dataItem->Id)); | ||
} | ||
|
||
return [$languageExtensive]; | ||
} | ||
|
||
public static function getSorting(): SortingInterface | ||
{ | ||
return new ValueWithDeprecatedTagsSeparateSorting(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@PrinsFrank Does
str_replace
here replace double underscore with single twice?