diff options
| author | 2025-09-10 01:04:17 -0400 | |
|---|---|---|
| committer | 2025-09-10 07:04:17 +0200 | |
| commit | a1411c7f2c10ab7c0e3cd49b8ffff38009ade35b (patch) | |
| tree | 418e27e35ebf8f31e21e1f17be5c46a054c45991 /p | |
| parent | 087df1e5d990cb9464bf1ac7f36f136c64d9dd2e (diff) | |
Translate the API information page (#7922)
Closes #6222
Translate the `api/index.php` page
* Update app/i18n/pl/api.php
Co-authored-by: Inverle <inverle@proton.me>
* Update app/i18n/de/api.php
Co-authored-by: maTh <1645099+math-GH@users.noreply.github.com>
* i18n: fr
* <kbd>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
---------
Co-authored-by: Inverle <inverle@proton.me>
Co-authored-by: maTh <1645099+math-GH@users.noreply.github.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'p')
| -rw-r--r-- | p/api/index.php | 58 | ||||
| -rw-r--r-- | p/scripts/api.js | 114 |
2 files changed, 104 insertions, 68 deletions
diff --git a/p/api/index.php b/p/api/index.php index 1db1273dc..279826aa5 100644 --- a/p/api/index.php +++ b/p/api/index.php @@ -1,52 +1,58 @@ <?php declare(strict_types=1); + require dirname(__DIR__, 2) . '/constants.php'; + require LIB_PATH . '/lib_rss.php'; //Includes class autoloader header("Content-Security-Policy: default-src 'self'; frame-ancestors 'none'"); header('X-Content-Type-Options: nosniff'); + + FreshRSS_Context::initSystem(); + Minz_Translate::init(Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), null)); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB"> <head> <meta charset="UTF-8" /> -<title>FreshRSS API endpoints</title> +<title><?= _t('api.information.title') ?></title> <meta name="robots" content="noindex" /> <link rel="start" href="../i/" /> <script src="../scripts/api.js" defer="defer"></script> -<script id="jsonVars" type="application/json"> -<?php -require dirname(__DIR__, 2) . '/constants.php'; -require LIB_PATH . '/lib_rss.php'; //Includes class autoloader -FreshRSS_Context::initSystem(); -echo json_encode([ - 'greader' => Minz_Url::display('/api/greader.php', 'php', true), - 'fever' => Minz_Url::display('/api/fever.php', 'php', true), -]); -?> -</script> </head> <body> -<h1>FreshRSS API endpoints</h1> +<h1><?= _t('api.information.title') ?></h1> -<h2>Google Reader compatible API</h2> +<h2><?= _t('api.information.title.greader') ?></h2> <dl> -<dt>Your API address:</dt> -<dd><?= Minz_Url::display('/api/greader.php', 'html', true) ?></dd> -<dt>Google Reader API configuration test:</dt> -<dd id="greaderOutput">?</dd> +<dt><?= _t('api.information.address') ?> +</dt> +<dd><kbd><?= Minz_Url::display('/api/greader.php', 'html', true) ?></kbd></dd> +<dt><?= _t('api.information.test.greader') ?></dt> +<dd id="greaderOutput" + data-api-url="<?= Minz_Url::display('/api/greader.php', 'php', true) ?>" + data-i18n-pass="<?= _t('api.information.output.pass') ?>" + data-i18n-encoding-support="<?= _t('api.information.output.encoding-support') ?>" + data-i18n-invalid-configuration="<?= _t('api.information.output.invalid-configuration') ?>" + data-i18n-unknown-error="<?= _t('api.information.output.unknown-error') ?>" +>?</dd> </dl> -<h2>Fever compatible API</h2> +<h2><?= _t('api.information.title.fever') ?></h2> <dl> -<dt>Your API address:</dt> -<dd><?= Minz_Url::display('/api/fever.php', 'html', true) ?></dd> -<dt>Fever API configuration test:</dt> -<dd id="feverOutput">?</dd> +<dt><?= _t('api.information.address') ?></dt> +<dd><kbd><?= Minz_Url::display('/api/fever.php', 'html', true) ?></kbd></dd> +<dt><?= _t('api.information.test.fever') ?></dt> +<dd id="feverOutput" + data-api-url="<?= Minz_Url::display('/api/fever.php', 'php', true) ?>" + data-i18n-pass="<?= _t('api.information.output.pass') ?>" + data-i18n-invalid-configuration="<?= _t('api.information.output.invalid-configuration') ?>" + data-i18n-unknown-error="<?= _t('api.information.output.unknown-error') ?>" +>?</dd> </dl> -<h2>API for extensions</h2> +<h2><?= _t('api.information.title.extension') ?></h2> <dl> -<dt>Your API address:</dt> -<dd><?= Minz_Url::display('/api/misc.php/Extension%20name/', 'html', true) ?></dd> +<dt><?= _t('api.information.address') ?></dt> +<dd><kbd><?= Minz_Url::display('/api/misc.php/Extension%20name/', 'html', true) ?></kbd></dd> </dl> </body> diff --git a/p/scripts/api.js b/p/scripts/api.js index ce52c50ad..62ce386f8 100644 --- a/p/scripts/api.js +++ b/p/scripts/api.js @@ -1,7 +1,7 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 'use strict'; -function check(url, next) { +const check = function (url, next) { if (!url || !next) { return; } @@ -19,45 +19,75 @@ function check(url, next) { } }; req.send(); -} - -const jsonVars = JSON.parse(document.getElementById('jsonVars').innerHTML); - -check(jsonVars.greader + '/check/compatibility', function next(result1) { - const greaderOutput = document.getElementById('greaderOutput'); - if (result1 === 'PASS') { - greaderOutput.innerHTML = '✔️ ' + result1; - } else { - check(jsonVars.greader + '/check%2Fcompatibility', function next(result2) { - if (result2 === 'PASS') { - greaderOutput.innerHTML = '⚠️ WARN: no <code>%2F</code> support, so some clients will not work!'; - } else { - check('./greader.php/check/compatibility', function next(result3) { - if (result3 === 'PASS') { - greaderOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; - } else { - greaderOutput.innerHTML = '❌ ' + result1; - } - }); - } - }); - } -}); - -check(jsonVars.fever + '?api', function next(result1) { - const feverOutput = document.getElementById('feverOutput'); - try { - JSON.parse(result1); - feverOutput.innerHTML = '✔️ PASS'; - } catch (ex) { - check('./fever.php?api', function next(result2) { - try { - JSON.parse(result2); - feverOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; - } catch (ex) { - feverOutput.innerHTML = '❌ ' + result1; - } - }); - } -}); +}; + +const pass = function (output) { + output.innerHTML = output.dataset.i18nPass; +}; + +const encodingSupport = function (output) { + output.innerHTML = output.dataset.i18nEncodingSupport; +}; + +const invalidConfiguration = function (output) { + output.innerHTML = output.dataset.i18nInvalidConfiguration; +}; + +const unknownError = function (output, message) { + output.innerHTML = output.dataset.i18nUnknownError + message; +}; + +const checkGReaderAPI = function () { + const output = document.getElementById('greaderOutput'); + const apiUrl = output.dataset.apiUrl; + + check(apiUrl + '/check/compatibility', function next(result1) { + if (result1 === 'PASS') { + pass(output); + } else { + check(apiUrl + '/check%2Fcompatibility', function next(result2) { + if (result2 === 'PASS') { + encodingSupport(output); + } else { + check('./greader.php/check/compatibility', function next(result3) { + if (result3 === 'PASS') { + invalidConfiguration(output); + } else { + unknownError(output, result1); + } + }); + } + }); + } + }); +}; + +const checkFeverAPI = function () { + const output = document.getElementById('feverOutput'); + const apiUrl = output.dataset.apiUrl; + + check(apiUrl + '?api', function next(result1) { + try { + JSON.parse(result1); + pass(output); + } catch (ex) { + check('./fever.php?api', function next(result2) { + try { + JSON.parse(result2); + invalidConfiguration(output); + } catch (ex) { + unknownError(output, result1); + } + }); + } + }); +}; + +/** + * The API tests are done this way to simulate in a more accurate manner + * outside requests. Since the APIs are used by third-party tools, they + * cannot interact at the server level. + */ +checkGReaderAPI(); +checkFeverAPI(); // @license-end |
