Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translation] Fix default value for locales in translation push|pull commands #41504

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

welcoMattic
Copy link
Member

Q A
Branch? 5.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #41501
License MIT
Doc PR

This PR ensures that $locales are always defined either framework.translator.enabled_locales or framework.translator.providers.(loco|lokalise|crowdin).locales is defined. Until now, the code expected framework.translator.enabled_locales to be defined, now if it's not, we merge all framework.translator.providers.(loco|lokalise|crowdin).locales values and pass them to console.command.translation_pull and console.command.translation_push definitions.

throw new LogicException(sprintf('You must specify one of "framework.translator.enabled_locales" or "framework.translator.providers.%s.locales" in order to use translation providers.', $name));
}

$locales = array_merge($locales, $provider['locales']);
Copy link

Choose a reason for hiding this comment

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

Is array_merge really the intended way here? Shouldn't the locale options for the provider be what controls what locales get sent to the provider, even if we have more locales enabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually we want to pass to the commands all locales supported by all configured providers, in order to read local translations. That's why the locales property of the TranslationPushCommand has enabledLocales as default value (https://github.com/symfony/symfony/pull/41504/files#diff-a00f86baf85c337ee61148e5fff8d189edf224ef40382518307359f579f40e6aR66).

Then, the FilteringProvider class is a decorator for each actual provider, and in its read method, we intersect domains and locales : the ones come from the provider configurations, the others come from the read call from the command class.

But I'm ok, we need to review this part, to make it more explicit and more logical. One of the solution might be to use only locales of providers configuration, make this parameter mandatory? WDYT @nicolas-grekas, in terms of design?

Copy link
Member

Choose a reason for hiding this comment

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

I've no strong opinion. I'm fine with the current design.
But if someone disagrees, I'd be happy to know why.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are @OskarStark or @Nyholm has an opinion on it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicolas-grekas nicolas-grekas changed the base branch from 5.4 to 5.3 June 2, 2021 09:38
@nicolas-grekas nicolas-grekas added this to the 5.3 milestone Jun 2, 2021
@welcoMattic
Copy link
Member Author

I just figured out there no relevant reason that enabled_locales was related to the locales passed to the push and pull commands. In fact, someone could need to pull/push translation for a locales which is not (yet) enabled.

WDTY about not set locales for Providers from enabled_locales?

@nicolas-grekas
Copy link
Member

It's true that this line might be strange:
https://github.com/welcoMattic/symfony/blob/94a451dcd1dd44a20a1b8038d1a12b80255460f6/src/Symfony/Component/Translation/Command/TranslationPushCommand.php#L100

I don't see how the 2nd DI parameter that ismentionned in the message relates to the command.
Maybe the command should default to the list of locales of each provider? Is that doable?

@welcoMattic
Copy link
Member Author

welcoMattic commented Jun 14, 2021

It's pretty much what I thought to do, and make the following behaviour:

A provider will treat all locales (framework.translator.enabled_locales) by default, unless we pass explicit locales via CLI options.

Are we agree on it?

@welcoMattic welcoMattic force-pushed the fix/translation-providers-locales-config branch from 94a451d to 375b058 Compare July 25, 2021 09:40
@welcoMattic
Copy link
Member Author

I've just pushed an update to use enabled_locales by default, and append all framework.translator.providers.(loco|lokalise|crowdin).locales values, then array_unique the result. It will allow users to defined a common list of locales for push/pull commands, and specify additional locales (for instance, a not yet enabled locale) for one or more provider.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2021

Thank you @welcoMattic.

@fabpot fabpot merged commit 88c5349 into symfony:5.3 Jul 25, 2021
@fabpot fabpot mentioned this pull request Jul 26, 2021
@welcoMattic welcoMattic deleted the fix/translation-providers-locales-config branch November 10, 2021 08:34
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.

[Translation] Push command error
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.