Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[FrameworkBundle][Translation] addLocaleSwitcher service#45793

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.1fromkbond:locale-switcher
Mar 26, 2022

Conversation

kbond
Copy link
Member

@kbondkbond commentedMar 19, 2022
edited by fabpot
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#35925
LicenseMIT
Doc PRtodo

This adds aLocaleSwitcher object/service. When setting it's locale, it sets it for allkernel.locale_aware services,\Locale, and, if applicable, the_locale parameter for theRequestContext. AswitchLocale() convenience method exists to do set the locale, execute a callback, and set the locale back to the original.

Usage:

/** @var Symfony\Component\Translation\LocaleSwitcher $switcher */$swicher->getLocale();// kernel.defaul_locale$switcher->setLocale('fr');$switcher->getLocale();// "fr"$switcher->runWithLocale('de',function()use ($switcher) {$switcher->getLocale();// "de"});$switcher->getLocale();// "fr"

Todo:

  • tests

welcoMattic, ro0NL, dmaicher, alexander-schranz, Hanmac, Tetragramat, cristoforocervino, AirBair, mdoutreluingne, and SebLours reacted with thumbs up emojiLustmored, cristoforocervino, and althaus reacted with heart emojiKocal reacted with rocket emoji
@carsonbotcarsonbot added this to the6.1 milestoneMar 19, 2022
@carsonbotcarsonbot changed the title[Translation][FrameworkBundle] addLocaleSwitcher service[FrameworkBundle][Translation] addLocaleSwitcher serviceMar 19, 2022
@kbondkbondforce-pushed thelocale-switcher branch 2 times, most recently from8b9e60e toacf8082CompareMarch 19, 2022 14:07
Copy link
Contributor

@ro0NLro0NL left a comment

Choose a reason for hiding this comment

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

:shipit:

@kbondkbondforce-pushed thelocale-switcher branch 3 times, most recently fromd09e0d3 to83379b8CompareMarch 22, 2022 13:45
@kbond
Copy link
MemberAuthor

Tests added, fabbot failure is unrelated to this PR.

@fabpot
Copy link
Member

Thank you@kbond.

@nicolas-grekas
Copy link
Member

I'm proposing#46045 on top of this PR.

fabpot added a commit that referenced this pull requestApr 14, 2022
…ekas)This PR was merged into the 6.1 branch.Discussion----------[Translation] Improve LocaleSwitcher a bit| Q             | A| ------------- | ---| Branch?       | 6.1| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -Today's blog post made me review#45793. Here are changes I think would be nice doing.This is an edgy feature btw to me because it builds on mutable services. An idea that I did not submit here would be to rename LocaleSwitcher to LocaleProvider and tell ppl that need the locale to use this instead of storing the locale as a string in a property. Dunno if that'd make sense to others.Commits-------a71f328 [Translation] Improve LocaleSwitcher a bit
@fabpotfabpot mentioned this pull requestApr 15, 2022
nicolas-grekas added a commit that referenced this pull requestMar 7, 2023
…leSwitcher in a class_exists call (larowlan)This PR was merged into the 6.2 branch.Discussion----------[Translation] Wrap call to \Locale::setDefault from LocaleSwitcher in a class_exists call| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       | N/a - see below| License       | MIT| Doc PR        | n/aIn#45793 a new LocaleSwitcher was added which uses the \Locale class from ext-intl.On upgrading an English only project from 5.4 to 6.2, I received the following error as we don't have the ext-intl extension```Error: Class "Locale" not found```I searched for previous PRs to add a dependency on `ext-intl` and [came across one](#49280) for the string component directing the user to install a polyfill.Should symfony/translation therefore depend on the polyfill - otherwise updating is broken without manually installing the polyfill?If so, here's a PR for that.Keep up the good work folks ❤️Commits-------c043e93 Wrap use of \Locale in a class_exists test
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@ro0NLro0NLro0NL left review comments

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
6.1
Development

Successfully merging this pull request may close these issues.

[Translator] Add LocaleSwitcher Service
6 participants
@kbond@fabpot@nicolas-grekas@javiereguiluz@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp