return $this->language;
}
+ /**
+ * Format the entry language to a valid html lang attribute.
+ */
+ public function getHTMLLanguage()
+ {
+ $parsedLocale = \Locale::parseLocale($this->getLanguage());
+ $lang = '';
+ $lang .= $parsedLocale['language'] ?? '';
+ $lang .= isset($parsedLocale['region']) ? '-' . $parsedLocale['region'] : '';
+
+ return $lang;
+ }
+
/**
* @return string|null
*/
<!DOCTYPE html>
-<!--[if lte IE 6]><html class="no-js ie6 ie67 ie678" lang="en"><![endif]-->
-<!--[if lte IE 7]><html class="no-js ie7 ie67 ie678" lang="en"><![endif]-->
-<!--[if IE 8]><html class="no-js ie8 ie678" lang="en"><![endif]-->
-<!--[if gt IE 8]><html class="no-js" lang="en"><![endif]-->
-<html>
+{% set lang = app.request.locale|default('') -%}
+<!--[if lte IE 6]><html class="no-js ie6 ie67 ie678"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]-->
+<!--[if lte IE 7]><html class="no-js ie7 ie67 ie678"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]-->
+<!--[if IE 8]><html class="no-js ie8 ie678"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]-->
+<!--[if gt IE 8]><html class="no-js"{% if lang is not empty %} lang="{{ lang }}"{% endif %}><![endif]-->
+<html{% if lang is not empty %} lang="{{ lang }}"{% endif %}>
<head>
{% block head %}
<meta name="viewport" content="initial-scale=1.0">
{% block content %}
<div id="article">
<header class="mbm">
- <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>
+ <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>
</header>
<div id="article_toolbar">
</div>
</aside>
</div>
- <article>
+ <article{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}>
{{ entry.content | raw }}
</article>
</div>
{% block content %}
<div id="article">
<header class="mbm">
- <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>
+ <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>
</header>
<aside>
<div class="tools">
</div>
</aside>
- <article>
+ <article{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}>
{{ entry.content | raw }}
</article>
--- /dev/null
+<?php
+
+namespace Tests\Wallabag\CoreBundle\Entity;
+
+use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
+use Wallabag\CoreBundle\Entity\Entry;
+
+class EntryTest extends WallabagCoreTestCase
+{
+ public function testGetLanguage()
+ {
+ $this->logInAs('admin');
+ $entry = new Entry($this->getLoggedInUser());
+ $languages = [
+ 'en_GB' => 'en-GB',
+ 'en_US' => 'en-US',
+ 'en-gb' => 'en-GB',
+ 'en-US' => 'en-US',
+ 'fr' => 'fr',
+ 'fr_FR' => 'fr-FR',
+ 'ja' => 'ja',
+ ];
+ foreach ($languages as $entryLang => $lang) {
+ $entry->setLanguage($entryLang);
+ $this->assertSame($lang, $entry->getHTMLLanguage());
+ }
+ }
+}