Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.

Commit f2e0996

Browse files
author
alexandresalome
committed
localization of blocks
1 parent d962135 commit f2e0996

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

Resources/translations/git.fr_FR.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"See more": "Voir plus"
2+
"Staging area": "Staging area"
3+
"Pending modifications": "Modifications en attente"
4+
"Gravatar of :user": "Gravatar de :user"
5+
"File mode changed from :old to :new": "Le mode de fichier a changé de :old pour :new"
6+
"Filename": "Nom de fichier"
7+
"Modification date": "Date de modification"
8+
"Last commit": "Dernier commit"

Resources/views/default_theme.html.twig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<thead>
2323
<tr>
2424
<th colspan="2">
25-
<a class="load-previous">Load previous</a>
25+
<a class="load-previous">{{ 'See more'|trans({}, 'git') }}</a>
2626
</th>
2727
</tr>
2828
</thead>
@@ -34,7 +34,7 @@
3434
<tfoot>
3535
<tr>
3636
<th colspan="2">
37-
<a class="load-next">Load next</a>
37+
<a class="load-next">{{ 'See more'|trans({}, 'git') }}</a>
3838
</th>
3939
</tr>
4040
</tfoot>
@@ -45,7 +45,7 @@
4545
{% spaceless %}
4646
{% set current_date = null %}
4747
{% for commit in log %}
48-
{% set date = commit.authorDate.format('Y-m-d') %}
48+
{% set date = commit.authorDate|git_date('day') %}
4949
{% if date != current_date %}
5050
<tr>
5151
<th colspan="2">
@@ -103,15 +103,15 @@
103103
{% block status %}
104104
{% spaceless %}
105105
{% if diff_staged.files|length %}
106-
<p>Staging area</p>
106+
<p>{{ 'Staging area'|trans({}, "git") }}</p>
107107
<ul>
108108
{% for file in diff_staged.files %}
109109
<li>{{ file.newName }}</li>
110110
{% endfor %}
111111
</ul>
112112
{% endif %}
113113
{% if diff_pending.files|length %}
114-
<p>Pending modifications</p>
114+
<p>{{ 'Pending modifications'|trans({}, "git") }}</p>
115115
<ul>
116116
{% for file in diff_pending.files %}
117117
<li>{{ file.name }}</li>
@@ -127,7 +127,7 @@
127127
{% spaceless %}
128128
<span class="git-author">
129129
{# Gravatar #}
130-
<img alt="Avatar of {{ name }}" width="{{ size }}" height="{{ size }}" src="http://www.gravatar.com/avatar/{{ email_md5 }}?s={{ size }}" />
130+
<img alt="{{ 'Gravatar of :user'|trans({':user': name}, 'git') }}" width="{{ size }}" height="{{ size }}" src="http://www.gravatar.com/avatar/{{ email_md5 }}?s={{ size }}" />
131131
{{- name -}}
132132
</span>
133133
{% endspaceless %}
@@ -187,7 +187,7 @@
187187
{% elseif file.newName == null %}
188188
<span class="file deleted">{{ file.oldName }} ({{ file.oldMode }})</span>
189189
{% elseif file.oldMode != file.newMode %}
190-
<span class="changemod">{{ 'diff.label.file_mode_changed'|trans({'%old%': file.oldMode, '%new%': file.newMode}) }}</span>
190+
<span class="changemod">{{ 'File mode changed from :old to :new'|trans({':old': file.oldMode, ':new': file.newMode}) }}</span>
191191
{% else %}
192192
<ul>
193193
<li>{{ file.oldName }} ({{ file.oldMode }}) -&gt; {{ file.newName }} ({{ file.newMode }})</li>
@@ -321,10 +321,10 @@
321321
<thead>
322322
<tr>
323323
<th width="20"></td>
324-
<th>{{ 'table.filename'|trans }}</th>
324+
<th>{{ 'Filename'|trans({}, 'git') }}</th>
325325
{% if revision %}
326-
<th>{{ 'table.date'|trans }}</th>
327-
<th>{{ 'table.last_commit'|trans }}</th>
326+
<th>{{ 'Modification date'|trans({}, 'git') }}</th>
327+
<th>{{ 'Last commit'|trans({}, 'git') }}</th>
328328
{% endif %}
329329
</tr>
330330
</thead>
@@ -343,7 +343,7 @@
343343
{% if revision %}
344344
{% set last = revision.log(path ? path~'/'~name : name).commits[0] %}
345345
<td>
346-
{{ last.getCommitterDate.format('Y-m-d H:i:s') }}
346+
{{ last.getCommitterDate|git_date }}
347347
</td>
348348
<td>
349349
<a href="{{ git_url(last) }}">
@@ -376,12 +376,12 @@
376376

377377
{% block blob_image %}
378378
{% spaceless %}
379-
<pre><code>IMAGE</code></pre>
379+
<img src="data:{{ mimetype }};base64,{{ base64 }}" />
380380
{% endspaceless %}
381381
{% endblock %}
382382

383383
{% block blob_binary %}
384384
{% spaceless %}
385-
<pre><code>BINARY</code></pre>
385+
<p><em>This file is a binary.</em></p>
386386
{% endspaceless %}
387387
{% endblock %}

Twig/GitExtension.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@ public function getTests()
108108
);
109109
}
110110

111+
/**
112+
* @inheritdoc
113+
*/
114+
public function getFilters()
115+
{
116+
return array(
117+
new \Twig_SimpleFilter('git_date', array($this, 'formatDate')),
118+
);
119+
}
120+
121+
public function formatDate(\DateTime $date, $format = 'long')
122+
{
123+
if ($format === 'long') {
124+
$formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
125+
} elseif ($format === 'day') {
126+
$formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE);
127+
} else {
128+
throw new \InvalidArgumentException(sprintf('Format "%s" not supported. Supported are: long'));
129+
}
130+
131+
return $formatter->format($date);
132+
}
133+
111134
public function renderCommit(\Twig_Environment $env, Commit $commit)
112135
{
113136
return $this->renderBlock($env, 'commit_header', array(
@@ -197,18 +220,24 @@ public function renderPathcrumb(\Twig_Environment $env, Revision $revision, $pat
197220

198221
public function renderBlob($env, Blob $blob)
199222
{
223+
$block = null;
224+
$args = array('blob' => $blob);
225+
200226
if ($blob->isText()) {
201227
$block = 'blob_text';
202228
} else {
203-
$mime = $blob->getMimetype();
204-
if (preg_match("#^image/(png|jpe?g|gif)#", $mime)) {
229+
$mimetype = $blob->getMimetype();
230+
$args['mimetype'] = $mimetype;
231+
232+
if (preg_match("#^image/(png|jpe?g|gif)#", $mimetype)) {
233+
$args['base64'] = base64_encode($blob->getContent());
205234
$block = 'blob_image';
206235
} else {
207236
$block = 'blob_binary';
208237
}
209238
}
210239

211-
return $this->renderBlock($env, $block, array('blob' => $blob));
240+
return $this->renderBlock($env, $block, $args);
212241
}
213242

214243
public function renderLabel(\Twig_Environment $env, Revision $revision)

0 commit comments

Comments
 (0)