Skip to content

Commit 78a98af

Browse files
authored
Merge pull request #54 from Alloboissons/feature/i18n
I18N for Templates and more
2 parents 174e62f + 0f87f62 commit 78a98af

File tree

20 files changed

+614
-27
lines changed

20 files changed

+614
-27
lines changed

Classes/Controller/LoginController.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Neos\Error\Messages\Error;
55
use Neos\Error\Messages\Message;
6+
use Neos\Flow\I18n\Translator;
67
use Neos\Flow\Mvc\Controller\ControllerContext;
78
use Neos\Flow\Security\Exception\AuthenticationRequiredException;
89
use Sandstorm\UserManagement\Domain\Service\RedirectTargetServiceInterface;
@@ -37,18 +38,58 @@ class LoginController extends AbstractAuthenticationController
3738
*/
3839
protected $uriFactory;
3940

41+
/**
42+
* @Flow\Inject
43+
* @var Translator
44+
*/
45+
protected $translator;
46+
4047
/**
4148
* @var string
4249
* @Flow\InjectConfiguration(path="authFailedMessage.title")
4350
*/
4451
protected $loginFailedTitle;
4552

53+
/**
54+
* @return string
55+
*/
56+
protected function getLoginFailedTitle()
57+
{
58+
return $this->loginFailedTitle === 'i18n'
59+
? $this->translator->translateById(
60+
'authFailedMessage.title',
61+
[],
62+
null,
63+
null,
64+
'Main',
65+
'Sandstorm.UserManagement'
66+
)
67+
: $this->loginFailedTitle;
68+
}
69+
4670
/**
4771
* @var string
4872
* @Flow\InjectConfiguration(path="authFailedMessage.body")
4973
*/
5074
protected $loginFailedBody;
5175

76+
/**
77+
* @return string
78+
*/
79+
protected function getLoginFailedBody()
80+
{
81+
return $this->loginFailedBody === 'i18n'
82+
? $this->translator->translateById(
83+
'authFailedMessage.body',
84+
[],
85+
null,
86+
null,
87+
'Main',
88+
'Sandstorm.UserManagement'
89+
)
90+
: $this->loginFailedBody;
91+
}
92+
5293
/**
5394
* SkipCsrfProtection is needed here because we will have errors otherwise if we render multiple
5495
* plugins on the same page
@@ -101,7 +142,7 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null
101142
protected function onAuthenticationFailure(AuthenticationRequiredException $exception = null)
102143
{
103144
$this->emitAuthenticationFailure($this->controllerContext, $exception);
104-
$this->addFlashMessage($this->loginFailedBody, $this->loginFailedTitle,Message::SEVERITY_ERROR, [], ($exception === null ? 1347016771 : $exception->getCode()));
145+
$this->addFlashMessage($this->getLoginFailedBody(), $this->getLoginFailedTitle(),Message::SEVERITY_ERROR, [], ($exception === null ? 1347016771 : $exception->getCode()));
105146
}
106147

107148
/**

Classes/Controller/RegistrationController.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Sandstorm\UserManagement\Controller;
33

4+
use Neos\Flow\I18n\Translator;
45
use Sandstorm\TemplateMailer\Domain\Service\EmailService;
56
use Sandstorm\UserManagement\Domain\Model\RegistrationFlow;
67
use Sandstorm\UserManagement\Domain\Repository\RegistrationFlowRepository;
@@ -32,12 +33,35 @@ class RegistrationController extends ActionController
3233
*/
3334
protected $emailService;
3435

36+
/**
37+
* @Flow\Inject
38+
* @var Translator
39+
*/
40+
protected $translator;
41+
3542
/**
3643
* @var string
3744
* @Flow\InjectConfiguration(path="email.subjectActivation")
3845
*/
3946
protected $subjectActivation;
4047

48+
/**
49+
* @return string
50+
*/
51+
protected function getSubjectActivation()
52+
{
53+
return $this->subjectActivation === 'i18n'
54+
? $this->translator->translateById(
55+
'email.subjectActivation',
56+
[],
57+
null,
58+
null,
59+
'Main',
60+
'Sandstorm.UserManagement'
61+
)
62+
: $this->subjectActivation;
63+
}
64+
4165

4266
/**
4367
* @Flow\SkipCsrfProtection
@@ -69,7 +93,7 @@ public function registerAction(RegistrationFlow $registrationFlow)
6993

7094
$this->emailService->sendTemplateEmail(
7195
'ActivationToken',
72-
$this->subjectActivation,
96+
$this->getSubjectActivation(),
7397
[$registrationFlow->getEmail()],
7498
[
7599
'activationLink' => $activationLink,

Classes/Controller/ResetPasswordController.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Sandstorm\UserManagement\Controller;
33

4+
use Neos\Flow\I18n\Translator;
45
use Neos\Flow\Property\TypeConverter\PersistentObjectConverter;
56
use Sandstorm\UserManagement\Domain\Model\ResetPasswordFlow;
67
use Sandstorm\UserManagement\Domain\Repository\ResetPasswordFlowRepository;
@@ -39,12 +40,34 @@ class ResetPasswordController extends ActionController
3940
*/
4041
protected $emailService;
4142

43+
/**
44+
* @Flow\Inject
45+
* @var Translator
46+
*/
47+
protected $translator;
48+
4249
/**
4350
* @var string
4451
* @Flow\InjectConfiguration(path="email.subjectResetPassword")
4552
*/
4653
protected $subjectResetPassword;
4754

55+
/**
56+
* @return string
57+
*/
58+
protected function getSubjectResetPassword()
59+
{
60+
return $this->subjectResetPassword === 'i18n'
61+
? $this->translator->translateById(
62+
'email.subjectResetPassword',
63+
[],
64+
null,
65+
null,
66+
'Main',
67+
'Sandstorm.UserManagement'
68+
)
69+
: $this->subjectResetPassword;
70+
}
4871

4972
/**
5073
* @Flow\SkipCsrfProtection
@@ -88,7 +111,7 @@ public function requestTokenAction(ResetPasswordFlow $resetPasswordFlow)
88111

89112
$this->emailService->sendTemplateEmail(
90113
'ResetPasswordToken',
91-
$this->subjectResetPassword,
114+
$this->getSubjectResetPassword(),
92115
[$resetPasswordFlow->getEmail()],
93116
[
94117
'resetPasswordLink' => $resetPasswordLink,

Configuration/Settings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ Sandstorm:
55
# Validity timespan for the token used to reset passwords.
66
resetPasswordTokenTimeout: '4 hours'
77
# The message that appears if a user could not be logged in.
8+
# Set the value to 'i18n' to enable translations
9+
# using 'authFailedMessage.title and authFailedMessage.body as id.
810
authFailedMessage:
911
title: 'Login nicht möglich'
1012
body: 'Sie haben ungültige Zugangsdaten eingegeben. Bitte versuchen Sie es noch einmal.'
1113
# Email settings
14+
# Set the value to 'i18n' to enable translations
15+
# using 'email.subjectActivation' and 'email.subjectResetPassword' as id.
1216
email:
1317
subjectActivation: 'Please confirm your account'
1418
# Subject line for the password reset email

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ Sandstorm:
105105
rolesForNewUsers: []
106106
```
107107
108+
### I18N
109+
It is possible to use i18n for the messages configured in the settings. Simply by setting the values to 'i18n'.
110+
```
111+
Sandstorm:
112+
UserManagement:
113+
authFailedMessage:
114+
title: 'i18n'
115+
body: 'i18n'
116+
email:
117+
subjectActivation: 'i18n'
118+
subjectResetPassword: 'i18n'
119+
```
120+
108121
## Additional Settings for usage in Neos
109122
You should switch the implementation of the Redirect and User Creation Services to the Neos services. Add this to your `Objects.yaml`:
110123
```
@@ -366,7 +379,6 @@ Feel free to submit issues/PRs :)
366379

367380
# 6. TODOs
368381

369-
* I18N for Templates.
370382
* More Tests.
371383

372384
# 7. FAQ

Resources/Private/Partials/LogoutForm.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
lang="en">
66

77
<f:section name="Logout">
8-
<p>Sie sind eingeloggt als <strong>{account.accountIdentifier}</strong>.</p>
8+
<p><f:translate id="logout.loggedAs" arguments="{0: '{account.accountIdentifier}'}"></f:translate></p>
99
<f:form action="logout" method="post" additionalAttributes="{role:'form'}">
10-
<f:form.submit value="Ausloggen" class="button primary" />
10+
<f:form.submit value="{f:translate(id: 'logout')}" class="button primary" />
1111
</f:form>
1212
</f:section>
1313

Resources/Private/Templates/Login/Login.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
<f:else>
1818
<f:form action="authenticate" method="post">
1919
<fieldset>
20-
<input placeholder="test@example.com" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][username]" type="email" autofocus>
21-
<input placeholder="Passwort" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][password]" type="password" value="">
22-
<input type="submit" value="Login" class="button large primary" />
20+
<input placeholder="{f:translate(id: 'email')}" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][username]" type="email" autofocus>
21+
<input placeholder="{f:translate(id: 'password')}" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][password]" type="password" value="">
22+
<input type="submit" value="{f:translate(id: 'login')}" class="button large primary" />
2323
</fieldset>
2424
</f:form>
25-
<f:link.action action="index" controller="ResetPassword">Passwort vergessen?</f:link.action>
25+
<f:link.action action="index" controller="ResetPassword"><f:translate id="passwordForgotten"></f:translate></f:link.action>
2626
</f:else>
2727
</usermanagement:ifAuthenticated>
2828
</f:section>

Resources/Private/Templates/Registration/ActivateAccount.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@
1818

1919
<f:if condition="{tokenNotFound}">
2020
<div class="callout alert">
21-
<p>Der Aktivierungslink war nicht gültig.
22-
<f:link.action action="index" controller="Registration" package="Sandstorm.UserManagement">Bitte registrieren Sie sich erneut.</f:link.action>
21+
<p><f:translate id="activation.linkNotValid"></f:translate>
22+
<f:link.action action="index" controller="Registration" package="Sandstorm.UserManagement"><f:translate id="activation.registerAgain"></f:translate></f:link.action>
2323
</p>
2424
</div>
2525
</f:if>
2626

2727
<f:if condition="{tokenTimeout}">
2828
<div class="callout alert">
29-
<p>Der Aktivierungslink ist nicht mehr gültig.
30-
<f:link.action action="index" controller="Registration" package="Sandstorm.UserManagement">Bitte registrieren Sie sich erneut.</f:link.action>
29+
<p><f:translate id="activation.linkExpired"></f:translate>
30+
<f:link.action action="index" controller="Registration" package="Sandstorm.UserManagement"><f:translate id="activation.registerAgain"></f:translate></f:link.action>
3131
</p>
3232
</div>
3333
</f:if>
3434

3535
<f:if condition="{success}">
3636
<div class="callout success">
37-
<p>Sie sind nun aktiviert und können sich auf unserer Website anmelden.
37+
<p><f:translate id="activation.successMessage"></f:translate>
3838
</p>
3939
</div>
4040
<!-- This can cause issues in the Neos use case, as then the Login Form will be displayed in the registration plugin's subcontext, which might
4141
not make sense. Therefore, deactivated for the time being. Feel free to uncomment in your own template. -->
42-
<!--<f:link.action controller="Login" action="login" package="Sandstorm.UserManagement" class="button large primary">Zum Login</f:link.action>-->
42+
<!--<f:link.action controller="Login" action="login" package="Sandstorm.UserManagement" class="button large primary"><f:translate id="toTheLogin"></f:translate></f:link.action>-->
4343
</f:if>
4444

4545
</f:section>

Resources/Private/Templates/Registration/Index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,41 @@
1616
<f:form action="register" method="post" objectName="registrationFlow">
1717
<fieldset>
1818
<label>
19-
E-Mail-Adresse
19+
<f:translate id="emailAddress"></f:translate>
2020
<f:form.textfield property="email" placeholder="test@example.com" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][username]" type="email" required="true"/>
2121
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.email'}"/>
2222
</label>
2323

2424
<label>
25-
Passwort
26-
<f:form.password placeholder="Ihr Passwort" property="passwordDto.password" required="true"/>
25+
<f:translate id="password"></f:translate>
26+
<f:form.password placeholder="{f:translate(id: 'yourPassword')}" property="passwordDto.password" required="true"/>
2727
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.passwordDto.password'}"/>
2828
</label>
2929

3030
<label>
31-
Passwortbestätigung
32-
<f:form.password placeholder="Passwort wiederholen" property="passwordDto.passwordConfirmation" required="true"/>
31+
<f:translate id="registration.confirmPassword"></f:translate>
32+
<f:form.password placeholder="{f:translate(id: 'registration.repeatPassword')}" property="passwordDto.passwordConfirmation" required="true"/>
3333
</label>
3434

3535
<label>
36-
Anrede
37-
<f:form.select options="{'m': 'Herr', 'f': 'Frau'}" property="attributes.salutation" />
36+
<f:translate id="registration.salutation"></f:translate>
37+
<f:form.select options="{'m': 'Mr.', 'f': 'Ms.'}" translate="{by: 'id', prefix: 'registration.salutationOptions.'}" property="attributes.salutation" />
3838
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.attributes.salutation'}"/>
3939
</label>
4040

4141
<label>
42-
Vorname
42+
<f:translate id="firstName"></f:translate>
4343
<f:form.textfield placeholder="Manfred" property="attributes.firstName" required="true"/>
4444
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.attributes.firstName'}"/>
4545
</label>
4646

4747
<label>
48-
Nachname
48+
<f:translate id="lastName"></f:translate>
4949
<f:form.textfield placeholder="Mustermann" property="attributes.lastName"/>
5050
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.attributes.lastName'}"/>
5151
</label>
5252

53-
<input type="submit" value="Registrieren" class="button large primary"/>
53+
<input type="submit" value="{f:translate(id: 'registration.register')}" class="button large primary"/>
5454
</fieldset>
5555
</f:form>
5656
</f:else>

Resources/Private/Templates/Registration/Register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<f:section name="Content">
1111
<div class="callout success">
12-
<p>Wir haben eine E-Mail zur Bestätigung der Registrierung an <strong>{registrationFlow.email}</strong> gesendet. Bitte folgen Sie der Anleitung in der E-Mail, um die Registrierung zu bestätigen.</p>
12+
<p><f:translate id="registration.confirmationEmailSent" arguments="{registrationFlow.email}"></f:translate></p>
1313
</div>
1414
</f:section>
1515

0 commit comments

Comments
 (0)