mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 11:26:37 +00:00
build/generate-known-translation-apis: make the ref to TranslationContainer statically analysable
this ensures that it will follow refactors automatically with no additional changes.
This commit is contained in:
parent
177eecf9ee
commit
5bdcc0339f
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\build\generate_known_translation_apis;
|
namespace pocketmine\build\generate_known_translation_apis;
|
||||||
|
|
||||||
|
use pocketmine\lang\TranslationContainer;
|
||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
use function array_map;
|
use function array_map;
|
||||||
use function count;
|
use function count;
|
||||||
@ -130,6 +131,8 @@ HEADER;
|
|||||||
ksort($languageDefinitions, SORT_STRING);
|
ksort($languageDefinitions, SORT_STRING);
|
||||||
|
|
||||||
$parameterRegex = '/{%(.+?)}/';
|
$parameterRegex = '/{%(.+?)}/';
|
||||||
|
|
||||||
|
$translationContainerClass = (new \ReflectionClass(TranslationContainer::class))->getShortName();
|
||||||
foreach($languageDefinitions as $key => $value){
|
foreach($languageDefinitions as $key => $value){
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
if(preg_match_all($parameterRegex, $value, $matches) > 0){
|
if(preg_match_all($parameterRegex, $value, $matches) > 0){
|
||||||
@ -143,8 +146,8 @@ HEADER;
|
|||||||
}
|
}
|
||||||
echo "\tpublic static function " .
|
echo "\tpublic static function " .
|
||||||
functionify($key) .
|
functionify($key) .
|
||||||
"(" . implode(", ", array_map(fn(string $paramName) => "TranslationContainer|string \$$paramName", $parameters)) . ") : TranslationContainer{\n";
|
"(" . implode(", ", array_map(fn(string $paramName) => "$translationContainerClass|string \$$paramName", $parameters)) . ") : $translationContainerClass{\n";
|
||||||
echo "\t\treturn new TranslationContainer(KnownTranslationKeys::" . constantify($key) . ", [";
|
echo "\t\treturn new $translationContainerClass(KnownTranslationKeys::" . constantify($key) . ", [";
|
||||||
foreach($parameters as $parameterKey => $parameterName){
|
foreach($parameters as $parameterKey => $parameterName){
|
||||||
echo "\n\t\t\t";
|
echo "\n\t\t\t";
|
||||||
if(!is_numeric($parameterKey)){
|
if(!is_numeric($parameterKey)){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user