From f5a5df05aef5a08896b85c78fee05a24118600f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnau=20V=C3=A0zquez=20Palma?= Date: Tue, 18 Oct 2022 10:51:01 +0200 Subject: [PATCH 1/5] Force registering new strings in Controller --- README.md | 8 +++++ lib/Controller/EmailRecoveryController.php | 8 +++++ translationfiles/templates/email-recovery.pot | 33 ++++++++++--------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index cb3f8f9..fda5b9f 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,11 @@ ![Recovery Email Setting Image](recovery-email-setting.png) - For API endpoint authentication to work, you will have to set the environment variable `NEXTCLOUD_EMAIL_RECOVERY_APP_SECRET` on your server to some string(Recommended to set a strong password here) + +## Localization + +1. Download [translationtool](https://github.com/nextcloud/docker-ci/blob/master/translations/translationtool/translationtool.phar) from github. +2. Place it in your `$PATH` with executable permissions +3. Run it from the root of the project: `translationtool.phar create-pot-files email-recovery` +4. Commit the updated `translationfiles/templates/email-recovery.pot` +5. Translate in [Weblate](https://i18n.e.foundation/projects/ecloud/email-recovery/) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 4aafec3..8d8a318 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -28,6 +28,7 @@ use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\IConfig; use OCP\ILogger; +use \OCP\IL10N; use OCP\IUserSession; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\JSONResponse; @@ -43,6 +44,9 @@ class EmailRecoveryController extends Controller /** @var ILogger */ private $logger; + /** @var IL10N */ + private $l; + private $userSession; private $recoveryEmailService; @@ -52,12 +56,14 @@ class EmailRecoveryController extends Controller IRequest $request, IConfig $config, ILogger $logger, + IL10N $l, IUserSession $userSession, RecoveryEmailService $recoveryEmailService ) { parent::__construct($appName, $request); $this->config = $config; $this->logger = $logger; + $this->l = $l; $this->userSession = $userSession; $this->recoveryEmailService = $recoveryEmailService; } @@ -92,10 +98,12 @@ class EmailRecoveryController extends Controller $response->setStatus(500); if ($e instanceof InvalidRecoveryEmailException) { $response->setStatus(400); + $this->l->t('Invalid Recovery Email'); $response->setData(['message' => 'Invalid Recovery Email']); } if ($e instanceof SameRecoveryEmailAsEmailException) { $response->setStatus(400); + $this->l->t('Error! User email address cannot be saved as recovery email address!'); $response->setData(['message' => 'Error! User email address cannot be saved as recovery email address!']); } diff --git a/translationfiles/templates/email-recovery.pot b/translationfiles/templates/email-recovery.pot index 760164b..3315604 100644 --- a/translationfiles/templates/email-recovery.pot +++ b/translationfiles/templates/email-recovery.pot @@ -1,14 +1,14 @@ -# BASE TRANSLATION FILE. -# Copyright (C) 2022 MURENA +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the Nextcloud package. -# dev@murena.io +# FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2022-05-06 19:52+0530\n" +"POT-Creation-Date: 2022-10-18 10:39+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,26 +17,27 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: /home/nivesh/Desktop/repos/email-recovery/specialAppInfoFakeDummyForL10nScript.php:2 -msgid "Email Recovery" +#: /Users/arnau/Code/email-recovery/lib/Controller/EmailRecoveryController.php:101 +msgid "Invalid Recovery Email" msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/specialAppInfoFakeDummyForL10nScript.php:3 -msgid "Email Recovery App" +#: /Users/arnau/Code/email-recovery/lib/Controller/EmailRecoveryController.php:106 +msgid "Error! User email address cannot be saved as recovery email address!" msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:3 -msgid "Recovery Email" +#: /Users/arnau/Code/email-recovery/specialAppInfoFakeDummyForL10nScript.php:2 +msgid "Email Recovery" msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:7 -msgid "Recovery Email " +#: /Users/arnau/Code/email-recovery/specialAppInfoFakeDummyForL10nScript.php:3 +msgid "Email Recovery App" msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:22 -msgid "Changes saved" +#: /Users/arnau/Code/email-recovery/src/main.html:3 +#: /Users/arnau/Code/email-recovery/src/main.html:7 +msgid "Recovery Email" msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:26 -msgid "ErrorRecoveryEmailSameAsUserEmail" +#: /Users/arnau/Code/email-recovery/src/main.html:22 +msgid "Changes saved" msgstr "" -- GitLab From c9d197b8fdacafd14fefee953980eedd260f7abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnau=20V=C3=A0zquez=20Palma?= Date: Tue, 18 Oct 2022 10:53:40 +0200 Subject: [PATCH 2/5] Auto formatting --- lib/Controller/EmailRecoveryController.php | 124 +++++++++++---------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 8d8a318..7b7f6db 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -38,77 +38,79 @@ use OCA\EmailRecovery\Exception\SameRecoveryEmailAsEmailException; class EmailRecoveryController extends Controller { - /** @var IConfig */ - private $config; + /** @var IConfig */ + private $config; - /** @var ILogger */ - private $logger; + /** @var ILogger */ + private $logger; - /** @var IL10N */ - private $l; + /** @var IL10N */ + private $l; - private $userSession; + private $userSession; - private $recoveryEmailService; + private $recoveryEmailService; - public function __construct( - string $appName, - IRequest $request, - IConfig $config, - ILogger $logger, - IL10N $l, - IUserSession $userSession, - RecoveryEmailService $recoveryEmailService - ) { - parent::__construct($appName, $request); - $this->config = $config; - $this->logger = $logger; + public function __construct( + string $appName, + IRequest $request, + IConfig $config, + ILogger $logger, + IL10N $l, + IUserSession $userSession, + RecoveryEmailService $recoveryEmailService + ) + { + parent::__construct($appName, $request); + $this->config = $config; + $this->logger = $logger; $this->l = $l; - $this->userSession = $userSession; - $this->recoveryEmailService = $recoveryEmailService; - } + $this->userSession = $userSession; + $this->recoveryEmailService = $recoveryEmailService; + } - /** - * @NoAdminRequired - */ + /** + * @NoAdminRequired + */ - public function getRecoveryEmail() - { - $response = new JSONResponse(); - $userId = $this->userSession->getUser()->getUID(); - $data = array("recoveryEmail" => $this->config->getUserValue($userId, $this->appName, 'recovery-email')); - $response->setData($data); - return $response; - } - /** - * @NoAdminRequired - */ + public function getRecoveryEmail() + { + $response = new JSONResponse(); + $userId = $this->userSession->getUser()->getUID(); + $data = array("recoveryEmail" => $this->config->getUserValue($userId, $this->appName, 'recovery-email')); + $response->setData($data); + return $response; + } - public function setRecoveryEmail(string $recoveryEmail) - { - $userId = $this->userSession->getUser()->getUID(); - $response = new Response(); - try { - if ($this->recoveryEmailService->validateRecoveryEmail($userId, $recoveryEmail)) { - $this->recoveryEmailService->updateRecoveryEmail($userId, $recoveryEmail); - $response->setStatus(200); - return $response; - } - } catch (Exception $e) { - $response->setStatus(500); - if ($e instanceof InvalidRecoveryEmailException) { - $response->setStatus(400); + /** + * @NoAdminRequired + */ + + public function setRecoveryEmail(string $recoveryEmail) + { + $userId = $this->userSession->getUser()->getUID(); + $response = new Response(); + try { + if ($this->recoveryEmailService->validateRecoveryEmail($userId, $recoveryEmail)) { + $this->recoveryEmailService->updateRecoveryEmail($userId, $recoveryEmail); + $response->setStatus(200); + return $response; + } + } catch (Exception $e) { + $response->setStatus(500); + if ($e instanceof InvalidRecoveryEmailException) { + $response->setStatus(400); $this->l->t('Invalid Recovery Email'); - $response->setData(['message' => 'Invalid Recovery Email']); - } - if ($e instanceof SameRecoveryEmailAsEmailException) { - $response->setStatus(400); + $response->setData(['message' => 'Invalid Recovery Email']); + } + if ($e instanceof SameRecoveryEmailAsEmailException) { + $response->setStatus(400); $this->l->t('Error! User email address cannot be saved as recovery email address!'); - $response->setData(['message' => 'Error! User email address cannot be saved as recovery email address!']); - } + $response->setData(['message' => 'Error! User email address cannot be saved as recovery email address!']); + } - $this->logger->error("Error setting recovery email for user $userId" . $e->getMessage()); - return $response; - } - } + $this->logger->error("Error setting recovery email for user $userId" . $e->getMessage()); + return $response; + } + } } -- GitLab From 5c5ab176aaee411be0d20394e3a10229b2f88613 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Wed, 19 Oct 2022 00:57:42 +0530 Subject: [PATCH 3/5] use variables in html --- src/main.html | 7 +++--- translationfiles/templates/email-recovery.pot | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main.html b/src/main.html index bc796e5..b94db88 100644 --- a/src/main.html +++ b/src/main.html @@ -6,17 +6,18 @@ + {{ const placeholder = t('email-recovery', 'Recovery Email') }} - + {{ const value = t('email-recovery', 'Change Recovery Email') }}

{{ t("email-recovery","Changes saved") }} diff --git a/translationfiles/templates/email-recovery.pot b/translationfiles/templates/email-recovery.pot index 3315604..23393a6 100644 --- a/translationfiles/templates/email-recovery.pot +++ b/translationfiles/templates/email-recovery.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2022-10-18 10:39+0200\n" +"POT-Creation-Date: 2022-10-19 00:53+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,27 +17,35 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: /Users/arnau/Code/email-recovery/lib/Controller/EmailRecoveryController.php:101 +#: /home/nivesh/Desktop/repos/email-recovery/lib/Controller/EmailRecoveryController.php:103 msgid "Invalid Recovery Email" msgstr "" -#: /Users/arnau/Code/email-recovery/lib/Controller/EmailRecoveryController.php:106 +#: /home/nivesh/Desktop/repos/email-recovery/lib/Controller/EmailRecoveryController.php:108 msgid "Error! User email address cannot be saved as recovery email address!" msgstr "" -#: /Users/arnau/Code/email-recovery/specialAppInfoFakeDummyForL10nScript.php:2 +#: /home/nivesh/Desktop/repos/email-recovery/specialAppInfoFakeDummyForL10nScript.php:2 msgid "Email Recovery" msgstr "" -#: /Users/arnau/Code/email-recovery/specialAppInfoFakeDummyForL10nScript.php:3 +#: /home/nivesh/Desktop/repos/email-recovery/specialAppInfoFakeDummyForL10nScript.php:3 msgid "Email Recovery App" msgstr "" -#: /Users/arnau/Code/email-recovery/src/main.html:3 -#: /Users/arnau/Code/email-recovery/src/main.html:7 +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:3 +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:13 msgid "Recovery Email" msgstr "" -#: /Users/arnau/Code/email-recovery/src/main.html:22 +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:7 +msgid "Recovery Email " +msgstr "" + +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:19 +msgid "Change Recovery Email" +msgstr "" + +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:22 msgid "Changes saved" msgstr "" -- GitLab From 13a1f7ce3ae52e754281286ed16bb11347f3da5c Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Wed, 19 Oct 2022 01:07:30 +0530 Subject: [PATCH 4/5] update Readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fda5b9f..b6fe6bf 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,6 @@ 1. Download [translationtool](https://github.com/nextcloud/docker-ci/blob/master/translations/translationtool/translationtool.phar) from github. 2. Place it in your `$PATH` with executable permissions 3. Run it from the root of the project: `translationtool.phar create-pot-files email-recovery` +4. For html files, make sure that traslation strings are not directly assigned to an attribute. Use a tmp variable to call `t()` and then assign this variable to the attribute. 4. Commit the updated `translationfiles/templates/email-recovery.pot` 5. Translate in [Weblate](https://i18n.e.foundation/projects/ecloud/email-recovery/) -- GitLab From 1667877847418846b5d8ae3315f7d8b78cdad58b Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Wed, 19 Oct 2022 01:58:33 +0530 Subject: [PATCH 5/5] fix syntax --- src/main.html | 8 ++++---- translationfiles/templates/email-recovery.pot | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.html b/src/main.html index b94db88..7d013cf 100644 --- a/src/main.html +++ b/src/main.html @@ -6,18 +6,18 @@ - {{ const placeholder = t('email-recovery', 'Recovery Email') }} + {% const placeholder = t('email-recovery', 'Recovery Email') %} - {{ const value = t('email-recovery', 'Change Recovery Email') }} + {% const value = t('email-recovery', 'Change Recovery Email') %}

{{ t("email-recovery","Changes saved") }} diff --git a/translationfiles/templates/email-recovery.pot b/translationfiles/templates/email-recovery.pot index 23393a6..3761d0c 100644 --- a/translationfiles/templates/email-recovery.pot +++ b/translationfiles/templates/email-recovery.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2022-10-19 00:53+0530\n" +"POT-Creation-Date: 2022-10-19 01:57+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -34,7 +34,7 @@ msgid "Email Recovery App" msgstr "" #: /home/nivesh/Desktop/repos/email-recovery/src/main.html:3 -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:13 +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:9 msgid "Recovery Email" msgstr "" @@ -42,10 +42,10 @@ msgstr "" msgid "Recovery Email " msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:19 +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:16 msgid "Change Recovery Email" msgstr "" -#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:22 +#: /home/nivesh/Desktop/repos/email-recovery/src/main.html:23 msgid "Changes saved" msgstr "" -- GitLab