10000 [Translation] Introduce a way to configure the enabled locales by javiereguiluz · Pull Request #32433 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translation] Introduce a way to configure the enabled locales #32433

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
merged 1 commit into from
Feb 4, 2020

Conversation

javiereguiluz
Copy link
Member
Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #31563
License MIT
Doc PR -

This implements the idea #31563 so we can decide if we want to add this or not. I tested it in the "Symfony Demo" app. Before: 107 catalogs created in cache/dev/translations/. After: 43 catalogs. But that's because the app is translated into lots of languages. In most cases, only 2 catalog files will be generated (vs 107 before).

If this idea is approved, I'll add tests and docs. Thanks.

@fabpot
Copy link
Member
fabpot commented Dec 3, 2019

@javiereguiluz Can you rebase on current master? I'm wondering it we could use this new settings to automatically restrict _locale in URLs if no explicit requirement is set? Would that make sense?

@javiereguiluz
Copy link
Member Author

I've rebased and added a test, but please tell me any other test that you think it may be necessary. Thanks!

@javiereguiluz javiereguiluz changed the base branch from 4.4 to master December 3, 2019 16:43
@javiereguiluz
Copy link
Member Author

I tweaked a bit the behavior of this option. It now works as follows:

# config/packages/translation.yaml
framework:
    translator:
        # if you don't define this option or set it to null or [], all
        # catalogs are generated (same behavior as current versions)
        enabled_locales: null
        enabled_locales: []

        # if you define some values in this option, only those catalogs are generated
        enabled_locales: ['es', 'en']

@fabpot
Copy link
Member
fabpot commented Feb 4, 2020

Thank you @javiereguiluz.

fabpot added a commit that referenced this pull request Feb 4, 2020
… locales (javiereguiluz)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Translation] Introduce a way to configure the enabled locales

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31563
| License       | MIT
| Doc PR        | -

This implements the idea #31563 so we can decide if we want to add this or not. I tested it in the "Symfony Demo" app. Before: 107 catalogs created in cache/dev/translations/. After: 43 catalogs. But that's because the app is translated into lots of languages. In most cases, only 2 catalog files will be generated (vs 107 before).

If this idea is approved, I'll add tests and docs. Thanks.

Commits
-------

7658434 [Translation] Introduce a way to configure the enabled locales
@fabpot fabpot merged commit 7658434 into symfony:master Feb 4, 2020
fabpot added a commit that referenced this pull request Feb 4, 2020
…ales to build routes' default "_locale" requirement (nicolas-grekas)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[FrameworkBundle] use framework.translator.enabled_locales to build routes' default "_locale" requirement

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

No need to configure the same requirements for `_locale` in all routes any more thanks to the `framework.translator.enabled_locales` config option introduced in #32433.

Commits
-------

5eebd37 [FrameworkBundle] use framework.translator.enabled_locales to build routes' default "_locale" requirement
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
fabpot added a commit that referenced this pull request Jun 1, 2020
This PR was merged into the 5.1 branch.

Discussion
----------

[FrameworkBundle] Fix enabled_locales behavior

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

I was experimenting with enabled_locales on my application and I noticed the cache didn't actually change. It seems the generated service definition was invalid: the file `var/cache/dev/ContainerFEQLy1x/App_KernelDevDebugContainer.php` defined `getTranslator_DefaultService` by calling `new Translator` with 7 arguments instead of 6.

It seems to be due to the fact that the DI extension does not replace the right argument. With the following fix applied the behavior works as expected.

However, reading the comment of Javier in #32433, it seems he tested it against Demo and it worked with the previous code. I'm not sure why, @javiereguiluz I'd be interested in knowing if I'm missing something here :) .

Commits
-------

e2ce7f5 Fix enabled_locales behavior
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.

6 participants
0