Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide all translations #1705

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions core/ajax/translations.ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/* This file is part of NextDom Software.
*
* NextDom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NextDom Software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NextDom Software. If not, see <http://www.gnu.org/licenses/>.
*
* @Support <https://www.nextdom.org>
* @Email <[email protected]>
* @Authors/Contributors: Sylvaner, Byackee, cyrilphoenix71, ColonelMoutarde, edgd1er, slobberbone, Astral0, DanoneKiD
*/

use NextDom\Ajax\TranslationsAjax;

require_once(__DIR__ . '/../../src/core.php');

try {
echo (new TranslationsAjax())->allTranslations();
} catch (Exception $e) {
echo $e->getMessage();
}

57 changes: 57 additions & 0 deletions src/Ajax/TranslationsAjax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/* This file is part of NextDom Software.
*
* NextDom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NextDom Software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NextDom Software. If not, see <http://www.gnu.org/licenses/>.
*
* @Support <https://www.nextdom.org>
* @Email <[email protected]>
* @Authors/Contributors: Sylvaner, Byackee, cyrilphoenix71, ColonelMoutarde, edgd1er, slobberbone, Astral0, DanoneKiD
*/

namespace NextDom\Ajax;

use NextDom\Helpers\TranslateHelper;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Translation\Translator;

/**
* Class TranslationsController
* @package NextDom\Controller\Pages
*/
class TranslationsAjax extends BaseAjax
{
/**
* @var Translator Translate tool
*/
private static $translator = null;

/**
* @return false|string
* @throws \Exception
*/
public function allTranslations()
{
$language = TranslateHelper::getLanguage();
$filename = TranslateHelper::getPathTranslationFile($language);

self::$translator = new Translator($language, null, NEXTDOM_DATA . '/cache/i18n');
self::$translator->addLoader('yaml', new YamlFileLoader());
self::$translator->addResource('yaml', $filename, $language);

$arrayOfTranslations = self::$translator->getCatalogue()->all();

return \json_encode($arrayOfTranslations);
}
}
36 changes: 36 additions & 0 deletions tests/phpunit_tests/Ajax/TranslationsAjaxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/* This file is part of NextDom Software.
*
* NextDom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NextDom Software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NextDom Software. If not, see <http://www.gnu.org/licenses/>.
*
* @Support <https://www.nextdom.org>
* @Email <[email protected]>
* @Authors/Contributors: Sylvaner, Byackee, cyrilphoenix71, ColonelMoutarde, edgd1er, slobberbone, Astral0, DanoneKiD
*/

use NextDom\Ajax\CronAjax;
use NextDom\Ajax\TranslationsAjax;

require_once('BaseAjaxTest.php');

class TranslationsAjaxTest extends BaseAjaxTest
{

public function testTranslationsIsJsonValid()
{
$this->assertJson((new TranslationsAjax())->allTranslations(), 'available translations');
}

}
6 changes: 3 additions & 3 deletions translations/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ core:
error-404: 404 - Page not found
error-ajax: Unknown Ajax request
error-bad-action: Misuse of a feature
incorrect-sys-date: The system date is incorrect (before or after %s %s):
incorrect-sys-date: 'The system date is incorrect (before or after %s %s):'
dashboard:
all-categories: All
grid-config: Configure the size of the grid
Expand All @@ -196,7 +196,7 @@ firstuse:
market-content: By adding or connecting a Market Jeedom account for installing plugins ...
market-noaccount: I have no Market account
market-password-placeholder: Password...
market-productname-placeholder: ?
market-productname-placeholder: '?'
market-title: Connect your market has Jeedom to NextDom!
market-username-placeholder: Username...
market-wantaccount: I want to create one!
Expand Down Expand Up @@ -943,7 +943,7 @@ welcome:
"Arrêt de ": "Arrêt de"
"De nouvelles mises à jour sont disponibles : ": "New updates are available :"
"Système à jour": "System up to date"
"OK": "OK"
OK: "OK"
"Cron actif": "Cron active"
"Scénario actif": "Scenario active"
"Démarré": "Started"
Expand Down
2 changes: 1 addition & 1 deletion translations/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ firstuse:
market-content: En ajoutant ou connectant un compte Market Jeedom pour l'installation de plugins...
market-noaccount: Je n'ai pas de compte Market
market-password-placeholder: Mot de passe...
market-productname-placeholder: ?
market-productname-placeholder: '?'
market-title: Connectez votre market Jeedom à NextDom !
market-username-placeholder: Nom d'utilisateur...
market-wantaccount: Je veux en créer un !
Expand Down