Skip to content

[FrameworkBundle] Add completion to debug:translation command #43644

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

Merged

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Oct 22, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Part of #43594
License MIT
Doc PR NA

@carsonbot carsonbot added this to the 5.4 milestone Oct 22, 2021
@alexandre-daubois alexandre-daubois force-pushed the feat/debug-translation-autocomplete branch 3 times, most recently from 2d1f985 to b0a55a4 Compare October 22, 2021 07:01
@GromNaN
Copy link
Member

GromNaN commented Oct 22, 2021

Completion don't have to be exhaustive. Bundle names can be completed getting the name of each bundle provided by $kernel->getBundles(). That would be useful.

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('locale')) {
$suggestions->suggestValues(Locales::getLocales());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very long list. Since this command describes the state of the application, I think it would be more useful if only the used locales were listed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, taking a look at it!

Copy link
Contributor

@stephenkhoo stephenkhoo Oct 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on another translation related command that require to autocomplete for locale too.
I'm thinking if we're going to have only used locales, maybe we will need to add getUsedLocals() into ExtractorInterface and TranslationReaderInterface

So far I only know the we need to do as below if we're adding into the interface.
TranslationReader need to put the logic for getting the Locales
ChainExtractor and PhpExtractor also need to add the logic to get used Locales.

Quick global search within the repo also gave me one more class that needs update:
Symfony\Bridge\Twig\Translation\TwigExtractor

But not quite sure if it will affect other third party package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Translation/Loader/LoaderInterface.php

Also might need to consider third party translation loader included as the autocomplete suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FrameworkBundle has a concept of enabled locales. I suggest using those for the completion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really make sense to limit locales completion to the "enabled" ones in the project, aside that it seems tricky to get these enabled locales? Symfony already bundles a lot of messages in dozens of locales. Restricting completion could kind of prevent displaying messages defined by Symfony in domains like the validators one.

Copy link
Member

@fabpot fabpot Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it's only about completion, I'm fine with auto-completing only the enabled locales. If you want another one, just type it explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'm on it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenkhoo to access the enabled locales, use DI, i.e. inject them in the command constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks

@alexandre-daubois alexandre-daubois force-pushed the feat/debug-translation-autocomplete branch from b0a55a4 to a1c32b4 Compare October 22, 2021 07:28
@alexandre-daubois
Copy link
Member Author

Completion don't have to be exhaustive. Bundle names can be completed getting the name of each bundle provided by $kernel->getBundles(). That would be useful.

Suits me fine. Added!

@alexandre-daubois alexandre-daubois force-pushed the feat/debug-translation-autocomplete branch from a1c32b4 to 1388391 Compare October 22, 2021 07:29
@carsonbot carsonbot changed the title [Console] Add completion to debug:translation command [FrameworkBundle] Add completion to debug:translation command Oct 24, 2021
@alexandre-daubois alexandre-daubois force-pushed the feat/debug-translation-autocomplete branch 3 times, most recently from 1529f97 to 454d1b5 Compare October 25, 2021 16:32
@alexandre-daubois alexandre-daubois force-pushed the feat/debug-translation-autocomplete branch from 621d83c to 086a8b4 Compare October 26, 2021 14:21
fabpot added a commit that referenced this pull request Oct 29, 2021
…n:update command (stephenkhoo)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[FrameworkBundle] Add completion feature on translation:update command

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Part of #43594
| License       | MIT
| Doc PR        | -

Adding completion for translation:update.
- [x] locale
- [X] bundle
- [X] --format
- [X] --domain
- [X] --sort

Test for
- [x] locale
- [x] bundle
- [X] --format
- [X] --domain
- [X] --sort

Locale completion still under discussion in #43644 (review)

Locale and bundle test still not complete

Commits
-------

2f301ae [FrameworkBundle] Add completion feature on translation:update command
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Oct 29, 2021
…n:update command (stephenkhoo)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[FrameworkBundle] Add completion feature on translation:update command

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Part of #43594
| License       | MIT
| Doc PR        | -

Adding completion for translation:update.
- [x] locale
- [X] bundle
- [X] --format
- [X] --domain
- [X] --sort

Test for
- [x] locale
- [x] bundle
- [X] --format
- [X] --domain
- [X] --sort

Locale completion still under discussion in symfony/symfony#43644 (review)

Locale and bundle test still not complete

Commits
-------

2f301ae9e1 [FrameworkBundle] Add completion feature on translation:update command
@fabpot
Copy link
Member

fabpot commented Oct 29, 2021

Thank you @alexandre-daubois.


yield 'bundle' => [
['fr', '--domain', 'messages', ''],
['ExtensionWithoutConfigTestBundle', 'extension_without_config_test'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an exception when I use the bundle_name in snake case. Does it work for you? (It's ok with BundleName)

$ bin/console debug:translation en framework 

                                                                          
  "framework/translations" is neither an enabled bundle nor a directory.  
                                                                          

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look ASAP 👍

This was referenced Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants