diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2020-01-28 10:06:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-28 10:06:30 +0100 |
commit | 8afcb3a6478325959c872fccf206bf8dc80d164c (patch) | |
tree | e2d97a8b979ac0eac67a200600cdd9ece2113a61 | |
parent | 97c6561d5ce3c963ab77a0afd7a9164b2af56c20 (diff) | |
parent | 416d44d0aef68b04aec90d207e33feb68706e1c3 (diff) | |
download | wallabag-8afcb3a6478325959c872fccf206bf8dc80d164c.tar.gz wallabag-8afcb3a6478325959c872fccf206bf8dc80d164c.tar.zst wallabag-8afcb3a6478325959c872fccf206bf8dc80d164c.zip |
Merge pull request #4257 from Simounet/feat/lang-attribute
Use lang attribute
5 files changed, 51 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index beda581a..19045798 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -788,6 +788,19 @@ class Entry | |||
788 | } | 788 | } |
789 | 789 | ||
790 | /** | 790 | /** |
791 | * Format the entry language to a valid html lang attribute. | ||
792 | */ | ||
793 | public function getHTMLLanguage() | ||
794 | { | ||
795 | $parsedLocale = \Locale::parseLocale($this->getLanguage()); | ||
796 | $lang = ''; | ||
797 | $lang .= $parsedLocale['language'] ?? ''; | ||
798 | $lang .= isset($parsedLocale['region']) ? '-' . $parsedLocale['region'] : ''; | ||
799 | |||
800 | return $lang; | ||
801 | } | ||
802 | |||
803 | /** | ||
791 | * @return string|null | 804 | * @return string|null |
792 | */ | 805 | */ |
793 | public function getUid() | 806 | public function getUid() |
diff --git a/src/Wallabag/CoreBundle/Resources/views/base.html.twig b/src/Wallabag/CoreBundle/Resources/views/base.html.twig index befe2ef2..496b3fb6 100644 --- a/src/Wallabag/CoreBundle/Resources/views/base.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/base.html.twig | |||
@@ -1,9 +1,10 @@ | |||
1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
2 | <!--[if lte IE 6]><html class="no-js ie6 ie67 ie678" lang="en"><![endif]--> | 2 | {% set lang = app.request.locale|default('') -%} |
3 | <!--[if lte IE 7]><html class="no-js ie7 ie67 ie678" lang="en"><![endif]--> | 3 | <!--[if lte IE 6]><html class="no-js ie6 ie67 ie678"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]--> |
4 | <!--[if IE 8]><html class="no-js ie8 ie678" lang="en"><![endif]--> | 4 | <!--[if lte IE 7]><html class="no-js ie7 ie67 ie678"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]--> |
5 | <!--[if gt IE 8]><html class="no-js" lang="en"><![endif]--> | 5 | <!--[if IE 8]><html class="no-js ie8 ie678"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]--> |
6 | <html> | 6 | <!--[if gt IE 8]><html class="no-js"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]--> |
7 | <html{% if lang is not empty %} lang="{{ lang }}"{% endif %}> | ||
7 | <head> | 8 | <head> |
8 | {% block head %} | 9 | {% block head %} |
9 | <meta name="viewport" content="initial-scale=1.0"> | 10 | <meta name="viewport" content="initial-scale=1.0"> |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig index 4c0f85cc..c2e69a27 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig | |||
@@ -5,7 +5,7 @@ | |||
5 | {% block content %} | 5 | {% block content %} |
6 | <div id="article"> | 6 | <div id="article"> |
7 | <header class="mbm"> | 7 | <header class="mbm"> |
8 | <h1>{{ entry.title|e|default('entry.default_title'|trans)|raw }} <a href="{{ path('edit', { 'id': entry.id }) }}" class="nostyle" title="{{ 'entry.view.edit_title'|trans }}">✎</a></h1> | 8 | <h1><span{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}>{{ entry.title|e|default('entry.default_title'|trans)|raw }}</span> <a href="{{ path('edit', { 'id': entry.id }) }}" class="nostyle" title="{{ 'entry.view.edit_title'|trans }}">✎</a></h1> |
9 | </header> | 9 | </header> |
10 | 10 | ||
11 | <div id="article_toolbar"> | 11 | <div id="article_toolbar"> |
@@ -96,7 +96,7 @@ | |||
96 | </div> | 96 | </div> |
97 | </aside> | 97 | </aside> |
98 | </div> | 98 | </div> |
99 | <article> | 99 | <article{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}> |
100 | {{ entry.content | raw }} | 100 | {{ entry.content | raw }} |
101 | </article> | 101 | </article> |
102 | </div> | 102 | </div> |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 70932f21..e23fa0e1 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig | |||
@@ -223,7 +223,7 @@ | |||
223 | {% block content %} | 223 | {% block content %} |
224 | <div id="article"> | 224 | <div id="article"> |
225 | <header class="mbm"> | 225 | <header class="mbm"> |
226 | <h1>{{ entry.title|striptags|default('entry.default_title'|trans)|raw }} <a href="{{ path('edit', { 'id': entry.id }) }}" title="{{ 'entry.view.edit_title'|trans }}">✎</a></h1> | 226 | <h1><span{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}>{{ entry.title|striptags|default('entry.default_title'|trans)|raw }}</span> <a href="{{ path('edit', { 'id': entry.id }) }}" title="{{ 'entry.view.edit_title'|trans }}">✎</a></h1> |
227 | </header> | 227 | </header> |
228 | <aside> | 228 | <aside> |
229 | <div class="tools"> | 229 | <div class="tools"> |
@@ -276,7 +276,7 @@ | |||
276 | </div> | 276 | </div> |
277 | 277 | ||
278 | </aside> | 278 | </aside> |
279 | <article> | 279 | <article{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}> |
280 | {{ entry.content | raw }} | 280 | {{ entry.content | raw }} |
281 | </article> | 281 | </article> |
282 | 282 | ||
diff --git a/tests/Wallabag/CoreBundle/Entity/EntryTest.php b/tests/Wallabag/CoreBundle/Entity/EntryTest.php new file mode 100644 index 00000000..d400636e --- /dev/null +++ b/tests/Wallabag/CoreBundle/Entity/EntryTest.php | |||
@@ -0,0 +1,28 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | |||
8 | class EntryTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testGetLanguage() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | $entry = new Entry($this->getLoggedInUser()); | ||
14 | $languages = [ | ||
15 | 'en_GB' => 'en-GB', | ||
16 | 'en_US' => 'en-US', | ||
17 | 'en-gb' => 'en-GB', | ||
18 | 'en-US' => 'en-US', | ||
19 | 'fr' => 'fr', | ||
20 | 'fr_FR' => 'fr-FR', | ||
21 | 'ja' => 'ja', | ||
22 | ]; | ||
23 | foreach ($languages as $entryLang => $lang) { | ||
24 | $entry->setLanguage($entryLang); | ||
25 | $this->assertSame($lang, $entry->getHTMLLanguage()); | ||
26 | } | ||
27 | } | ||
28 | } | ||