Skip to content

Commit

Permalink
Merge pull request #497 from chesslablab/bugfix/locale
Browse files Browse the repository at this point in the history
Bugfix/locale
  • Loading branch information
programarivm authored Sep 25, 2024
2 parents 05d20c8 + f11a45c commit c0e3f0c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 31 deletions.
7 changes: 0 additions & 7 deletions assets/js/pages/settings/SettingsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export class SettingsForm extends AbstractComponent {
this.el.querySelector('select[name="ws"]').append(option);
});

if (localStorage.getItem('locale')) {
this.el.querySelector('select[name="locale"]').value = localStorage.getItem('locale');
} else {
this.el.querySelector('select[name="locale"]').value = 'en';
}

if (localStorage.getItem('theme') === 'light') {
this.el.querySelector('select[name="theme"]').value = 'light';
} else {
Expand Down Expand Up @@ -47,7 +41,6 @@ export class SettingsForm extends AbstractComponent {
this.el.addEventListener('submit', event => {
event.preventDefault();
const formData = new FormData(this.el);
localStorage.setItem('locale', formData.get('locale'));
localStorage.setItem('theme', formData.get('theme'));
localStorage.setItem('format', formData.get('format'));
localStorage.setItem('notation', formData.get('notation'));
Expand Down
10 changes: 0 additions & 10 deletions assets/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ footer a:hover {
text-decoration: underline;
}`;

const locale = () => {
const url = window.location.pathname.split('/');
if (localStorage.getItem('locale')) {
if (localStorage.getItem('locale') !== url[1]) {
window.location.href = window.location.href.replace(`/${url[1]}/`, `/${localStorage.getItem('locale')}/`);
}
}
}

const theme = () => {
const el = document.createElement('style');
el.setAttribute('id', 'theme');
Expand All @@ -94,5 +85,4 @@ const theme = () => {
document.head.appendChild(el);
}

locale();
theme();
2 changes: 1 addition & 1 deletion config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ locale:
path: /
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
defaults:
path: /en/
path: /%set_locale%/
permanent: true

sitemap:
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
set_locale: '%env(SET_LOCALE)%'

services:
# default configuration for services in *this* file
Expand Down
13 changes: 0 additions & 13 deletions templates/pages/settings/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@
<hr class="hr">
<form id="settingsForm">
<div>
<div class="mb-3">
<label class="form-label">{{ 'Language'|trans }}</label>
<select name="locale" class="form-select" required>
<option value="en">English</option>
<option value="es">Español</option>
<option value="fr">Français</option>
<option value="ru">Русский</option>
<option value="tr">Türkçe</option>
<option value="de">Deutsch</option>
<option value="hi">हिंदी</option>
<option value="zh_CN">简体中文</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">{{ 'Theme'|trans }}</label>
<select name="theme" class="form-select" required>
Expand Down
47 changes: 47 additions & 0 deletions templates/partial/nav.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,53 @@
</li>
</ul>
<ul class="navbar-nav me-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="mainNavLanguageLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{% include 'svg/bi-globe.svg' %} {{ 'Language'|trans }}
</a>
<ul class="dropdown-menu" aria-labelledby="mainNavLanguageLink">
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'de'}) }}">
Deutsch
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'en'}) }}">
English
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'es'}) }}">
Español
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'fr'}) }}">
Français
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'ru'}) }}">
Русский
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'tr'}) }}">
Türkçe
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'hi'}) }}">
हिंदी
</a>
</li>
<li>
<a class="dropdown-item" href="{{ path(app.request.attributes.get('_route'), {_locale: 'zh_CN'}) }}">
简体中文
</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="{{app.request.get('_route') starts with 'pages_settings' ? 'active' : ''}} nav-link" href="{{ path('pages_settings') }}" id="mainNavSettingsLink" role="button" aria-expanded="false">
{% include 'svg/gear-fill.svg' %} {{ 'Settings'|trans }}
Expand Down
3 changes: 3 additions & 0 deletions templates/svg/bi-globe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c0e3f0c

Please sign in to comment.