Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New make:language command #69

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
];
Loading