Skip to content
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

[Twig] Add app.locale documentation #18190

Merged
merged 1 commit into from
Apr 14, 2023
Merged

[Twig] Add app.locale documentation #18190

merged 1 commit into from
Apr 14, 2023

Conversation

SVillette
Copy link
Contributor

The PR add documentation of symfony/symfony#49913

@carsonbot carsonbot added this to the 6.3 milestone Apr 11, 2023
@javiereguiluz javiereguiluz added the Waiting Code Merge Docs for features pending to be merged label Apr 11, 2023
@carsonbot carsonbot modified the milestones: 6.3, next Apr 11, 2023
fabpot added a commit to symfony/symfony that referenced this pull request Apr 11, 2023
…iable` (SVillette)

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

Discussion
----------

[TwigBridge][TwigBundle] Add current locale to `AppVariable`

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #49870
| License       | MIT
| Doc PR        | symfony/symfony-docs#18190

As stated in #49870, they were no way to get the current locale without passing it through a variable when rendering a template within `LocaleSwitcher::runWithLocale()`.

```php
#[AsController]
final class HomeController
{
    #[Route('/', name: 'app_home')]
    public function __invoke(LocaleSwitcher $localeSwitcher, Environment $twig): Response
    {
        $localeSwitcher->setLocale('en');

        return $localeSwitcher->runWithLocale('fr', function () use ($twig) {
            return new Response($twig->render('index.html.twig'));
        });
    }
}
```

```twig
{{ app.locale }} // fr
```

A doc PR will be submitted if this change is accepted.

Commits
-------

2371216 [TwigBridge][TwigBundle] Add current locale to `AppVariable`
symfony-splitter pushed a commit to symfony/twig-bridge that referenced this pull request Apr 11, 2023
…iable` (SVillette)

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

Discussion
----------

[TwigBridge][TwigBundle] Add current locale to `AppVariable`

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #49870
| License       | MIT
| Doc PR        | symfony/symfony-docs#18190

As stated in #49870, they were no way to get the current locale without passing it through a variable when rendering a template within `LocaleSwitcher::runWithLocale()`.

```php
#[AsController]
final class HomeController
{
    #[Route('/', name: 'app_home')]
    public function __invoke(LocaleSwitcher $localeSwitcher, Environment $twig): Response
    {
        $localeSwitcher->setLocale('en');

        return $localeSwitcher->runWithLocale('fr', function () use ($twig) {
            return new Response($twig->render('index.html.twig'));
        });
    }
}
```

```twig
{{ app.locale }} // fr
```

A doc PR will be submitted if this change is accepted.

Commits
-------

2371216d93 [TwigBridge][TwigBundle] Add current locale to `AppVariable`
@SVillette SVillette changed the title [WCM] Add Twig app.locale documentation Add Twig app.locale documentation Apr 11, 2023
@SVillette
Copy link
Contributor Author

Hi @OskarStark @javiereguiluz,

Just a friendly ping to inform you that the feature PR is merged now. I think the label Waiting Code Merge can be removed now.

@OskarStark OskarStark removed the Waiting Code Merge Docs for features pending to be merged label Apr 14, 2023
@OskarStark OskarStark modified the milestones: next, 6.3 Apr 14, 2023
@carsonbot carsonbot changed the title Add Twig app.locale documentation [Twig] Add Twig app.locale documentation Apr 14, 2023
@OskarStark OskarStark changed the title [Twig] Add Twig app.locale documentation [Twig] Add app.locale documentation Apr 14, 2023
@OskarStark
Copy link
Contributor

Thanks Samaël for working on this feature, this is much appreciated.

@OskarStark OskarStark merged commit 70e861f into symfony:6.3 Apr 14, 2023
2 of 3 checks passed
@SVillette SVillette deleted the twig-app-variable-locale branch April 14, 2023 08:28
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.

None yet

4 participants