Skip to content

Commit a185a2a

Browse files
committed
feature #1562 Use app global variable for locale (seb-jean)
This PR was merged into the main branch. Discussion ---------- Use app global variable for locale I updated the code to use the new global app variable; `app.locale`. URL: https://symfony.com/blog/new-in-symfony-6-3-dx-improvements-part-1#add-current-locale-to-the-app-variable Commits ------- fbb93e7 refactor: Use app.locale
2 parents 41dbf2d + fbb93e7 commit a185a2a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

templates/base.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See https://symfony.com/doc/current/templates.html#template-inheritance-and-layouts
55
#}
66
<!DOCTYPE html>
7-
<html lang="{{ app.request.locale }}">
7+
<html lang="{{ app.locale }}">
88
<head>
99
<meta charset="UTF-8" />
1010
<meta name="viewport" content="width=device-width, initial-scale=1"/>
@@ -102,7 +102,7 @@
102102
{{ render_esi(controller('Symfony\\Bundle\\FrameworkBundle\\Controller\\TemplateController::templateAction', {
103103
'template': 'blog/about.html.twig',
104104
'sharedAge': 600,
105-
'_locale': app.request.locale
105+
'_locale': app.locale
106106
})) }}
107107
{% endblock %}
108108
</div>

templates/blog/index.xml.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<pubDate>{{ 'now'|date('r', timezone='GMT') }}</pubDate>
77
<lastBuildDate>{{ (paginator.results|last).publishedAt|default('now')|date('r', timezone='GMT') }}</lastBuildDate>
88
<link>{{ url('blog_index') }}</link>
9-
<language>{{ app.request.locale }}</language>
9+
<language>{{ app.locale }}</language>
1010

1111
{% for post in paginator.results %}
1212
<item>

templates/default/_language_selector.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<a href="#" class="nav-link dropdown-toggle language-selector-dropdown-button" data-toggle="modal" data-target="#locale-selector-modal" role="button" id="locales">
33
<twig:ux:icon name="tabler:world"/>
44
{% if display_current_language %}
5-
<span class="current-language">{{ app.request.locale|locale_name }}</span>
5+
<span class="current-language">{{ app.locale|locale_name }}</span>
66
{% endif %}
77
<span class="caret"></span>
88
<span class="sr-only">{{ 'menu.choose_language'|trans }}</span>
@@ -24,7 +24,7 @@
2424
<div class="modal-body">
2525
<ul class="locales">
2626
{% for locale in locales() %}
27-
{% set is_active = app.request.locale == locale.code %}
27+
{% set is_active = app.locale == locale.code %}
2828
{% set is_rtl = locale.code in ['ar', 'fa', 'he'] %}
2929
<li class="{{ is_active ? 'active' }} {{ is_rtl ? 'rtl' }}" translate="no">
3030
<a class="stretched-link" lang="{{ locale.code }}" hreflang="{{ locale.code }}" href="{{ path(app.current_route ?? 'blog_index', app.current_route_parameters|merge({_locale: locale.code})) }}">

0 commit comments

Comments
 (0)