mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This update will make the help method fall back to the English content, if it is available.
This commit is contained in:
parent
4e3e015912
commit
ed33a054ad
@ -14,7 +14,9 @@ namespace FireflyIII\Helpers\Help;
|
|||||||
|
|
||||||
use Cache;
|
use Cache;
|
||||||
use League\CommonMark\CommonMarkConverter;
|
use League\CommonMark\CommonMarkConverter;
|
||||||
|
use Log;
|
||||||
use Requests;
|
use Requests;
|
||||||
|
use Requests_Exception;
|
||||||
use Route;
|
use Route;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,20 +47,28 @@ class Help implements HelpInterface
|
|||||||
public function getFromGithub(string $language, string $route): string
|
public function getFromGithub(string $language, string $route): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
|
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
|
||||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
Log::debug(sprintf('Trying to get %s...', $uri));
|
||||||
$result = Requests::get($uri);
|
$content = '';
|
||||||
|
try {
|
||||||
|
$result = Requests::get($uri);
|
||||||
|
} catch (Requests_Exception $e) {
|
||||||
|
Log::error($e);
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log::debug(sprintf('Status code is %d', $result->status_code));
|
||||||
|
|
||||||
if ($result->status_code === 200) {
|
if ($result->status_code === 200) {
|
||||||
$content = $result->body;
|
$content = trim($result->body);
|
||||||
}
|
}
|
||||||
|
if (strlen($content) > 0) {
|
||||||
|
Log::debug('Content is longer than zero. Expect something.');
|
||||||
if (strlen(trim($content)) == 0) {
|
$converter = new CommonMarkConverter();
|
||||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
$content = $converter->convertToHtml($content);
|
||||||
}
|
}
|
||||||
$converter = new CommonMarkConverter();
|
|
||||||
$content = $converter->convertToHtml($content);
|
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
|
|
||||||
@ -83,7 +93,16 @@ class Help implements HelpInterface
|
|||||||
*/
|
*/
|
||||||
public function inCache(string $route, string $language):bool
|
public function inCache(string $route, string $language):bool
|
||||||
{
|
{
|
||||||
return Cache::has('help.' . $route . '.' . $language);
|
$result = Cache::has('help.' . $route . '.' . $language);
|
||||||
|
if ($result) {
|
||||||
|
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
|
||||||
|
}
|
||||||
|
if (!$result) {
|
||||||
|
Log::debug(sprintf('Cache does not have this entry: %s', 'help.' . $route . '.' . $language));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +115,8 @@ class Help implements HelpInterface
|
|||||||
*/
|
*/
|
||||||
public function putInCache(string $route, string $language, string $content)
|
public function putInCache(string $route, string $language, string $content)
|
||||||
{
|
{
|
||||||
Cache::put('help.' . $route . '.' . $language, $content, 10080); // a week.
|
$key = 'help.' . $route . '.' . $language;
|
||||||
|
Log::debug(sprintf('Will store entry in cache: %s', $key));
|
||||||
|
Cache::put($key, $content, 10080); // a week.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,9 @@ class HelpController extends Controller
|
|||||||
public function show(HelpInterface $help, string $route)
|
public function show(HelpInterface $help, string $route)
|
||||||
{
|
{
|
||||||
|
|
||||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||||
|
$alternative = false;
|
||||||
|
|
||||||
if (!$help->hasRoute($route)) {
|
if (!$help->hasRoute($route)) {
|
||||||
Log::error('No such route: ' . $route);
|
Log::error('No such route: ' . $route);
|
||||||
@ -60,6 +61,21 @@ class HelpController extends Controller
|
|||||||
|
|
||||||
$content = $help->getFromGithub($language, $route);
|
$content = $help->getFromGithub($language, $route);
|
||||||
|
|
||||||
|
// get backup language content (try English):
|
||||||
|
if (strlen($content) === 0) {
|
||||||
|
$language = 'en_US';
|
||||||
|
$content = $help->getFromGithub($language, $route);
|
||||||
|
$alternative = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($alternative && strlen($content) > 0) {
|
||||||
|
$content = '<p><em>' . strval(trans('firefly.help_may_not_be_your_language')) . '</em></p>' . $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($content) === 0) {
|
||||||
|
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
$help->putInCache($route, $language, $content);
|
$help->putInCache($route, $language, $content);
|
||||||
|
|
||||||
return Response::json($content);
|
return Response::json($content);
|
||||||
|
@ -51,7 +51,8 @@ return [
|
|||||||
'flash_info_multiple' => 'There is one message|There are :count messages',
|
'flash_info_multiple' => 'There is one message|There are :count messages',
|
||||||
'flash_error_multiple' => 'There is one error|There are :count errors',
|
'flash_error_multiple' => 'There is one error|There are :count errors',
|
||||||
'net_worth' => 'Net worth',
|
'net_worth' => 'Net worth',
|
||||||
'route_has_no_help' => 'There is no help for this route, or there is no help available in your language.',
|
'route_has_no_help' => 'There is no help for this route.',
|
||||||
|
'help_may_not_be_your_language' => 'This help text is in English. It is not yet available in your language',
|
||||||
'two_factor_welcome' => 'Hello, :user!',
|
'two_factor_welcome' => 'Hello, :user!',
|
||||||
'two_factor_enter_code' => 'To continue, please enter your two factor authentication code. Your application can generate it for you.',
|
'two_factor_enter_code' => 'To continue, please enter your two factor authentication code. Your application can generate it for you.',
|
||||||
'two_factor_code_here' => 'Enter code here',
|
'two_factor_code_here' => 'Enter code here',
|
||||||
|
Loading…
Reference in New Issue
Block a user