diff --git a/README.md b/README.md index 370d8ff..0b525f3 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ This should print the Kirby CLI version and a list of available commands - kirby make:command - kirby make:config - kirby make:controller +- kirby make:language - kirby make:model - kirby make:plugin - kirby make:snippet diff --git a/commands/make/language.php b/commands/make/language.php new file mode 100644 index 0000000..42dbc05 --- /dev/null +++ b/commands/make/language.php @@ -0,0 +1,44 @@ + 'Creates a new language', + 'args' => [ + 'code' => [ + 'description' => 'The code of the language' + ], + 'name' => [ + 'description' => 'The name of the language' + ], + 'locale' => [ + 'description' => 'The locale of the language' + ], + 'direction' => [ + 'description' => 'The direction of the language' + ] + ], + 'command' => static function (CLI $cli): void { + $kirby = $cli->kirby(); + $code = $cli->argOrPrompt('code', 'Enter a language code:'); + $name = $cli->argOrPrompt('name', 'Enter a language name (optional):', false); + $locale = $cli->argOrPrompt('locale', 'Enter a language locale (optional):', false); + $direction = $cli->radio('Select language direction:', ['ltr', 'rtl'])->prompt(); + + // authenticate as almighty + $kirby->impersonate('kirby'); + + Language::create([ + 'code' => $code, + 'name' => empty($name) === false ? $name : $code, + 'locale' => $locale, + 'direction' => $direction, + 'default' => $kirby->languages()->count() === 0, + ]); + + $cli->success('The language has been created'); + } +];