generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a6c9f
commit c809521
Showing
5 changed files
with
103 additions
and
21 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,77 @@ | ||
<?php | ||
|
||
namespace Elegantly\Translator\Commands; | ||
|
||
use Elegantly\Translator\Facades\Translator; | ||
use Elegantly\Translator\Services\Grammar\GrammarServiceInterface; | ||
use Elegantly\Translator\Services\Translate\TranslateServiceInterface; | ||
use Elegantly\Translator\TranslatorServiceProvider; | ||
|
||
use function Laravel\Prompts\multiselect; | ||
use function Laravel\Prompts\select; | ||
|
||
trait TranslatorCommandTrait | ||
{ | ||
public function getLocales( | ||
mixed $option, | ||
?string $label = null | ||
): array { | ||
$availableLocales = Translator::getLanguages(); | ||
|
||
if ($option) { | ||
if (is_array($option)) { | ||
return array_intersect($availableLocales, $option); | ||
} | ||
if (is_string($option)) { | ||
return array_intersect($availableLocales, explode(',', $option)); | ||
} | ||
|
||
return $availableLocales; | ||
} | ||
|
||
return multiselect( | ||
label: $label ?? 'In what locales?', | ||
options: $availableLocales, | ||
default: $availableLocales, | ||
required: true, | ||
); | ||
} | ||
|
||
public function getTranslateService( | ||
mixed $option, | ||
?string $label = null, | ||
): TranslateServiceInterface { | ||
|
||
if ($option && is_string($option)) { | ||
return TranslatorServiceProvider::getTranslateServiceFromConfig($option); | ||
} | ||
|
||
$serviceName = select( | ||
label: $label ?? 'What service would you like to use?', | ||
options: array_keys(config('translator.translate.services')), | ||
default: config('translator.translate.service'), | ||
required: true, | ||
); | ||
|
||
return TranslatorServiceProvider::getTranslateServiceFromConfig($serviceName); | ||
} | ||
|
||
public function getGrammarService( | ||
mixed $option, | ||
?string $label = null, | ||
): GrammarServiceInterface { | ||
|
||
if ($option && is_string($option)) { | ||
return TranslatorServiceProvider::getGrammarServiceFromConfig($option); | ||
} | ||
|
||
$serviceName = select( | ||
label: $label ?? 'What service would you like to use?', | ||
options: array_keys(config('translator.grammar.services')), | ||
default: config('translator.grammar.service'), | ||
required: true, | ||
); | ||
|
||
return TranslatorServiceProvider::getGrammarServiceFromConfig($serviceName); | ||
} | ||
} |
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