mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-22 17:11:07 +00:00
Use lang attribute
This commit is contained in:
parent
7937ed0c20
commit
416d44d0ae
5 changed files with 51 additions and 9 deletions
|
@ -787,6 +787,19 @@ class Entry
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<!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">
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{% 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">
|
||||
|
@ -96,7 +96,7 @@
|
|||
</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>
|
||||
|
|
|
@ -223,7 +223,7 @@
|
|||
{% 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">
|
||||
|
@ -276,7 +276,7 @@
|
|||
</div>
|
||||
|
||||
</aside>
|
||||
<article>
|
||||
<article{% if entry.language is defined and entry.language is not null %} lang="{{ entry.getHTMLLanguage() }}"{% endif %}>
|
||||
{{ entry.content | raw }}
|
||||
</article>
|
||||
|
||||
|
|
28
tests/Wallabag/CoreBundle/Entity/EntryTest.php
Normal file
28
tests/Wallabag/CoreBundle/Entity/EntryTest.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue