Skip to content

Commit

Permalink
0.16.0: Begun work on translation mechanisms
Browse files Browse the repository at this point in the history
  • Loading branch information
classaxe committed Feb 9, 2019
1 parent f0650f7 commit fc6f51b
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 31 deletions.
10 changes: 1 addition & 9 deletions src/Controller/Web/Admin/Logon.php
Expand Up @@ -56,22 +56,14 @@ public function logonController(
} else {
$this->session->set('lastError', '');
}
$text = ($this->session->get('isAdmin', 0) ?
"<p id='success'>You are now logged on as an Administrator and may perform administrative functions.</p>\n"
."<p>To log off, select <strong>Log Off</strong> from the main menu.</p>\n"
:
"<p>You must logon in order to perform administrative functions.</p>\n"
);

$parameters = [
'args' => $args,
'form' => $form->createView(),
'form_class' => 'logon',
'mode' => 'Logon',
'system' => $system,
'text' => $text
];
$parameters = array_merge($parameters, $this->parameters);
// return $this->rxx::debug($this->parameters);
return $this->render('logon/index.html.twig', $parameters);
}

Expand Down
29 changes: 27 additions & 2 deletions src/Controller/Web/Base.php
Expand Up @@ -7,8 +7,8 @@
use App\Utils\Rxx;
use Symfony\Component\HttpKernel\KernelInterface as Kernel;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Class Base
Expand Down Expand Up @@ -47,6 +47,11 @@ class Base extends AbstractController
*/
protected $systemRepository;

/**
* @var TranslatorInterface
*/
protected $translator;

/**
* Base constructor.
* @param ModeRepository $modeRepository
Expand All @@ -60,12 +65,14 @@ public function __construct(
Rxx $rxx,
SystemRepository $systemRepository,
SessionInterface $session,
EntityManagerInterface $em
EntityManagerInterface $em,
TranslatorInterface $translator
) {
$this->kernel = $kernel;
$this->modeRepository = $modeRepository;
$this->rxx = $rxx;
$this->systemRepository = $systemRepository;
$this->translator = $translator;
$this->session = $session;
$this->parameters = [
'isAdmin' => $this->session->get('isAdmin', 0),
Expand Down Expand Up @@ -133,10 +140,28 @@ public function __construct(
}
}

/**
* @param array $parameters
* @return array
*/
public function getMergedParameters($parameters = [])
{
$this->session->set('lastError', '');
$this->session->set('lastMessage', '');
return array_merge($parameters, $this->parameters);
}

/**
* @param string $id The message id (may also be an object that can be cast to string)
* @param array $parameters An array of parameters for the message
* @param string|null $domain The domain for the message or null to use the default
* @param string|null $locale The locale or null to use the default
*
* @return string The translated string
*
* @throws \InvalidArgumentException If the locale contains invalid characters
*/
public function i18n($id, array $parameters = array(), $domain = null, $locale = null) {
return $this->translator->trans($id, $parameters, $domain, $locale);
}
}
16 changes: 6 additions & 10 deletions src/Form/Logon.php
Expand Up @@ -18,7 +18,7 @@
* Class Logon
* @package App\Form
*/
class Logon extends AbstractType
class Logon extends \App\Controller\Web\Base
{
/**
* @param FormBuilderInterface $formBuilder
Expand All @@ -27,19 +27,16 @@ class Logon extends AbstractType
*/
public function buildForm(FormBuilderInterface $formBuilder, array $options)
{
$system = $options['system'];

$formBuilder
->add(
'user',
TextType::class,
[
'attr' => [
'onchange' => "try{setCustomValidity('')}catch(e){}",
'oninvalid' => "setCustomValidity('Please provide a valid Username')",
'onchange' => "try{setCustomValidity('')}catch(e){}",
'oninvalid' => "setCustomValidity('".$this->i18n('Please provide a valid Username')."')",
],
'help' => '&nbsp;',
'label' => 'Username',
'label' => $this->i18n('Username'),
]
)
->add(
Expand All @@ -48,9 +45,8 @@ public function buildForm(FormBuilderInterface $formBuilder, array $options)
[
'attr' => [
'onchange' => "try{setCustomValidity('')}catch(e){}",
'oninvalid' => "setCustomValidity('Please provide a valid Password')",
'oninvalid' => "setCustomValidity('".$this->i18n('Please provide a valid Password')."')",
],
'help' => '&nbsp;',
'label' => 'Password',
]
)
Expand All @@ -61,7 +57,7 @@ public function buildForm(FormBuilderInterface $formBuilder, array $options)
'attr' => [
'class' => 'button small'
],
'label' => 'Logon',
'label' => $this->i18n('Logon'),
]
);

Expand Down
2 changes: 1 addition & 1 deletion templates/base.html.twig
Expand Up @@ -3,7 +3,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{{ system|upper }} &gt; {{ mode|raw }}{% endblock %}</title>
<title>{% block title %}{{ system|upper }} &gt; {{ mode|raw|trans }}{% endblock %}</title>
<link rel="stylesheet prefetch" href="{{ asset('css/foundation.min.css') }}" />
<link rel="stylesheet" href="{{ asset('css/style' ~ minified ~ '.css') }}" />
{% block stylesheets %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion templates/forms/form.html.twig
@@ -1,7 +1,7 @@
{# Include our twig widget customisations #}
{% form_theme form 'forms/custom_form_div_layout.html.twig' %}
<div class="controlPanel {{ form_class }}">
<div class="header">{{ form_title }}</div>
<div class="header">{{ form_title|trans }}</div>
<div class="content clearfix">
{{ form_start(form) }}
{{ form_widget(form) }}
Expand Down
2 changes: 1 addition & 1 deletion templates/listeners/grid.html.twig
Expand Up @@ -28,5 +28,5 @@
</table>
{% include 'listeners/actions.html.twig' %}
{% else %}
<p class="no-results">(No listeners found matching your criteria)</p>
<p class="no-results">{% trans %}(No listeners found matching your criteria){% endtrans %}</p>
{% endif %}
14 changes: 7 additions & 7 deletions templates/logon/index.html.twig
@@ -1,16 +1,16 @@
{% extends 'main.html.twig' %}
{% set form_title = 'Administrator Logon'|trans %}

{% block body %}
<div class="main">
<h1>{{ mode }}</h1>
<div>
{{ text|raw }}
{% include 'status.html.twig' %}
</div>
<div>{% include 'status.html.twig' %}</div>
<h1>{% trans %}Logon{% endtrans %}</h1>
{% if not isAdmin %}
{% set form_title='Administrator Logon' %}
{% set form_class='logon' %}
<p>{% trans %}You must logon in order to perform administrative functions.{% endtrans %}</p>
{% include 'forms/form.html.twig' %}
{% else %}
<p id='success'>{% trans %}You are now logged on as an Administrator and may perform administrative functions.{% endtrans %}</p>
<p>{% trans %}To log off, select <strong>Log Off</strong> from the main menu.{% endtrans %}</p>
{% endif %}
</div>

Expand Down
34 changes: 34 additions & 0 deletions translations/messages.en.xlf
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="IdQ52y8" resname="Administrator Logon">
<source>Administrator Logon</source>
<target>Administrator Logon</target>
</trans-unit>
<trans-unit id="MKWJ9eo" resname="Logon">
<source>Logon</source>
<target>Logon</target>
</trans-unit>
<trans-unit id="bBPgzeD" resname="You must logon in order to perform administrative functions.">
<source>You must logon in order to perform administrative functions.</source>
<target>You must logon in order to perform administrative functions.</target>
</trans-unit>
<trans-unit id="Vq6hsgL" resname="You are now logged on as an Administrator and may perform administrative functions.">
<source>You are now logged on as an Administrator and may perform administrative functions.</source>
<target>You are now logged on as an Administrator and may perform administrative functions.</target>
</trans-unit>
<trans-unit id="Wycz4V0" resname="To log off, select &lt;strong&gt;Log Off&lt;/strong&gt; from the main menu.">
<source>To log off, select &lt;strong&gt;Log Off&lt;/strong&gt; from the main menu.</source>
<target><![CDATA[To log off, select <strong>Log Off</strong> from the main menu.]]></target>
</trans-unit>
<trans-unit id="DZo50ZN" resname="(No listeners found matching your criteria)">
<source>(No listeners found matching your criteria)</source>
<target>(No listeners found matching your criteria)</target>
</trans-unit>
</body>
</file>
</xliff>
34 changes: 34 additions & 0 deletions translations/messages.fr.xlf
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="bBPgzeD" resname="You must logon in order to perform administrative functions.">
<source>You must logon in order to perform administrative functions.</source>
<target>__You must logon in order to perform administrative functions.</target>
</trans-unit>
<trans-unit id="Vq6hsgL" resname="You are now logged on as an Administrator and may perform administrative functions.">
<source>You are now logged on as an Administrator and may perform administrative functions.</source>
<target>__You are now logged on as an Administrator and may perform administrative functions.</target>
</trans-unit>
<trans-unit id="Wycz4V0" resname="To log off, select &lt;strong&gt;Log Off&lt;/strong&gt; from the main menu.">
<source>To log off, select &lt;strong&gt;Log Off&lt;/strong&gt; from the main menu.</source>
<target><![CDATA[__To log off, select <strong>Log Off</strong> from the main menu.]]></target>
</trans-unit>
<trans-unit id="DZo50ZN" resname="(No listeners found matching your criteria)">
<source>(No listeners found matching your criteria)</source>
<target>(Aucun auditeur correspondant à vos critères n'a été trouvé)</target>
</trans-unit>
<trans-unit id="MKWJ9eo" resname="Logon">
<source>Logon</source>
<target>Se connecter</target>
</trans-unit>
<trans-unit id="IdQ52y8" resname="Administrator Logon">
<source>Administrator Logon</source>
<target>Connexion administrateur</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit fc6f51b

Please sign in to comment.