Skip to content

Commit

Permalink
New make:language command
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Feb 26, 2024
1 parent f480d13 commit cd3999e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions commands/make/language.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);

use Kirby\CLI\CLI;
use Kirby\Cms\Language;

return [
'description' => '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');
}
];

0 comments on commit cd3999e

Please sign in to comment.