-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start to generate some code from CLDR
- Loading branch information
Showing
20 changed files
with
4,608 additions
and
427 deletions.
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
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,5 @@ | ||
[*] | ||
indent_style = space | ||
|
||
[*.json] | ||
indent_size = 2 |
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 @@ | ||
composer.lock |
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,28 @@ | ||
ARG PHP_VERSION=8.1 | ||
FROM php:${PHP_VERSION}-cli-buster | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y autoconf pkg-config && \ | ||
pecl channel-update pecl.php.net && \ | ||
pecl install xdebug && \ | ||
docker-php-ext-enable opcache xdebug | ||
|
||
RUN echo '\ | ||
xdebug.client_host=host.docker.internal\n\ | ||
xdebug.mode=develop\n\ | ||
xdebug.start_with_request=yes\n\ | ||
' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini | ||
|
||
RUN echo '\ | ||
display_errors=On\n\ | ||
error_reporting=E_ALL\n\ | ||
date.timezone=UTC\n\ | ||
' >> /usr/local/etc/php/conf.d/php.ini | ||
|
||
ENV COMPOSER_ALLOW_SUPERUSER 1 | ||
|
||
RUN apt-get update && \ | ||
apt-get install unzip && \ | ||
curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet && \ | ||
mv composer.phar /usr/local/bin/composer && \ | ||
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"\n' >> /root/.bashrc |
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,31 @@ | ||
{ | ||
"name": "icanboogie/cldr-generator", | ||
"description": "Generates CLDR classes", | ||
"type": "project", | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Olivier Laviale", | ||
"email": "[email protected]", | ||
"homepage": "https://olvlvl.com/", | ||
"role": "Developer" | ||
} | ||
], | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=8.1", | ||
"icanboogie/accessor": "^6.0", | ||
"symfony/console": "^6.3", | ||
"symfony/dependency-injection": "^6.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"ICanBoogie\\CLDR\\": "../lib", | ||
"ICanBoogie\\CLDR\\Generator\\": "src" | ||
} | ||
} | ||
} |
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,15 @@ | ||
--- | ||
version: "3.2" | ||
services: | ||
app81: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PHP_VERSION: '8.1' | ||
environment: | ||
PHP_IDE_CONFIG: 'serverName=icanboogie-cldr-generator' | ||
volumes: | ||
- .:/app:delegated | ||
- ~/.composer:/root/.composer:delegated | ||
working_dir: /app |
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,23 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
namespace ICanBoogie\CLDR\Generator; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; | ||
|
||
chdir(__DIR__); | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
const CACHE = __DIR__ . "/cache"; | ||
|
||
$container = ContainerProvider::provide_container(); | ||
|
||
/** @var ContainerCommandLoader $command_loader */ | ||
|
||
$command_loader = $container->get('console.command_loader'); | ||
|
||
$console = new Application(); | ||
$console->setCommandLoader($command_loader); | ||
$console->run(); |
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,53 @@ | ||
<?php | ||
|
||
namespace ICanBoogie\CLDR\Generator\Command; | ||
|
||
use ICanBoogie\CLDR\Repository; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand('locale-id', "Generates LocaleId.php")] | ||
final class LocaleIdCommand extends Command | ||
{ | ||
private const TEMPLATE = <<<PHP | ||
<?php | ||
/** DO NOT EDIT - THE FILE HAS BEEN GENERATED WITH locale-id */ | ||
namespace ICanBoogie\CLDR; | ||
enum LocaleId: string | ||
{ | ||
#CASES# | ||
} | ||
PHP; | ||
|
||
public function __construct( | ||
private readonly Repository $repository | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$available_locales = $this->repository->available_locales; | ||
$cases = []; | ||
|
||
foreach ($available_locales as $locale) { | ||
$case = strtr($locale, [ '-' => '_' ]); | ||
|
||
$cases[] = <<<PHP | ||
case $case = "$locale"; | ||
PHP; | ||
} | ||
|
||
$cases = implode("\n", $cases); | ||
|
||
echo strtr(self::TEMPLATE, [ '#CASES#' => $cases ]); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
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,73 @@ | ||
<?php | ||
|
||
namespace ICanBoogie\CLDR\Generator\Command; | ||
|
||
use ICanBoogie\CLDR\Repository; | ||
use ICanBoogie\CLDR\Units\NumberWithUnit; | ||
use ICanBoogie\CLDR\Units\Unit; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand('sequence-companion', "Generates Units/SequenceCompanion.php")] | ||
final class SequenceCompanionCommand extends Command | ||
{ | ||
private const TEMPLATE = <<<PHP | ||
<?php | ||
/** DO NOT EDIT - THE FILE HAS BEEN GENERATED WITH sequence-companion */ | ||
namespace ICanBoogie\CLDR\Units; | ||
/** | ||
* @internal | ||
*/ | ||
trait SequenceCompanion | ||
{ | ||
#METHODS# | ||
} | ||
PHP; | ||
|
||
public function __construct( | ||
private readonly Repository $repository | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$units = $this->repository->locales['en-001']['units']['long']; | ||
$methods = []; | ||
|
||
foreach ($units as $name => $unit) { | ||
if (empty($unit['unitPattern-count-one'])) { | ||
continue; | ||
} | ||
|
||
$normalized = strtr($name, [ '-' => '_' ]); | ||
|
||
$methods[] = <<<PHP | ||
/** | ||
* @param float|int|numeric-string \$number | ||
* | ||
* @return \$this | ||
*/ | ||
public function $normalized(float|int|string \$number): self | ||
{ | ||
\$this->sequence["$name"] = \$number; | ||
return \$this; | ||
} | ||
PHP; | ||
} | ||
|
||
echo strtr(self::TEMPLATE, [ | ||
'#METHODS#' => implode("\n", $methods), | ||
]); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
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,78 @@ | ||
<?php | ||
|
||
namespace ICanBoogie\CLDR\Generator\Command; | ||
|
||
use ICanBoogie\CLDR\Repository; | ||
use ICanBoogie\CLDR\Units\NumberWithUnit; | ||
use ICanBoogie\CLDR\Units\Unit; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand('units-companion', "Generates Units/UnitsCompanion.php")] | ||
final class UnitsCompanionCommand extends Command | ||
{ | ||
private const TEMPLATE = <<<PHP | ||
<?php | ||
/** DO NOT EDIT - THE FILE HAS BEEN GENERATED WITH units-companion */ | ||
namespace ICanBoogie\CLDR\Units; | ||
/** | ||
* @internal | ||
* | ||
#PROPERTIES# | ||
* | ||
*/ | ||
trait UnitsCompanion | ||
{ | ||
#METHODS# | ||
} | ||
PHP; | ||
|
||
public function __construct( | ||
private readonly Repository $repository | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$units = $this->repository->locales['en-001']['units']['long']; | ||
$properties = []; | ||
$methods = []; | ||
|
||
foreach ($units as $name => $unit) { | ||
if (empty($unit['unitPattern-count-one'])) { | ||
continue; | ||
} | ||
|
||
$normalized = strtr($name, [ '-' => '_' ]); | ||
|
||
$properties[] = <<<TXT | ||
* @property-read Unit \$$normalized | ||
TXT; | ||
|
||
$methods[] = <<<PHP | ||
/** | ||
* @param float|int|numeric-string \$number | ||
*/ | ||
public function $normalized(float|int|string \$number): NumberWithUnit | ||
{ | ||
return new NumberWithUnit(\$number, "$name", \$this); | ||
} | ||
PHP; | ||
} | ||
|
||
echo strtr(self::TEMPLATE, [ | ||
'#PROPERTIES#' => implode("\n", $properties), | ||
'#METHODS#' => implode("\n", $methods), | ||
]); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
Oops, something went wrong.