From 1bd52867fb463a4b34cd2c4a9b9ace8b570e18b4 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 23 Jul 2024 18:52:12 +0200 Subject: Fallback to english help topic if localized topic is not found. --- Zotlabs/Lib/Traits/HelpHelperTrait.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Traits/HelpHelperTrait.php b/Zotlabs/Lib/Traits/HelpHelperTrait.php index b7711bbd5..9e4fefa4b 100644 --- a/Zotlabs/Lib/Traits/HelpHelperTrait.php +++ b/Zotlabs/Lib/Traits/HelpHelperTrait.php @@ -53,10 +53,10 @@ trait HelpHelperTrait { // Use local variable until we can use trait constants. $valid_file_ext = ['md', 'bb', 'html']; - $base_path = "doc/{$lang}/${base_path}"; + $base_path_with_lang = "doc/{$lang}/${base_path}"; foreach ($valid_file_ext as $ext) { - $path = "{$base_path}.{$ext}"; + $path = "{$base_path_with_lang}.{$ext}"; if (file_exists($path)) { $this->file_name = $path; $this->file_type = $ext; @@ -64,5 +64,9 @@ trait HelpHelperTrait { break; } } + + if (empty($this->file_name) && $lang !== 'en') { + $this->find_help_file($base_path, 'en'); + } } } -- cgit v1.2.3 From 7067a0adc2e37168401e761c29e78392229ec168 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 24 Jul 2024 10:59:03 +0200 Subject: Move language member to HelpHelperTrait. Should have been there from the start, was just a miss. --- Zotlabs/Lib/Traits/HelpHelperTrait.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Traits/HelpHelperTrait.php b/Zotlabs/Lib/Traits/HelpHelperTrait.php index 9e4fefa4b..2a54e2db2 100644 --- a/Zotlabs/Lib/Traits/HelpHelperTrait.php +++ b/Zotlabs/Lib/Traits/HelpHelperTrait.php @@ -14,6 +14,14 @@ trait HelpHelperTrait { private string $file_name = ''; private string $file_type = ''; + /** + * Associative array containing the detected language. + */ + private array $lang = [ + 'language' => 'en', //! Detected language, 2-letter ISO 639-1 code ("en") + 'from_url' => false, //! true if language from URL overrides browser default + ]; + /** * Determines help language. * -- cgit v1.2.3 From 61f9ad8274d662a056aff05407771fb450a2ab35 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 24 Jul 2024 11:46:18 +0200 Subject: Add a notice to help pages when defaulting to english. --- Zotlabs/Lib/Traits/HelpHelperTrait.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Traits/HelpHelperTrait.php b/Zotlabs/Lib/Traits/HelpHelperTrait.php index 2a54e2db2..0ce586d08 100644 --- a/Zotlabs/Lib/Traits/HelpHelperTrait.php +++ b/Zotlabs/Lib/Traits/HelpHelperTrait.php @@ -20,6 +20,7 @@ trait HelpHelperTrait { private array $lang = [ 'language' => 'en', //! Detected language, 2-letter ISO 639-1 code ("en") 'from_url' => false, //! true if language from URL overrides browser default + 'missing' => false, //! true if topic not found in detected language ]; /** @@ -36,17 +37,15 @@ trait HelpHelperTrait { $languages = $language_repository->getList(); if(array_key_exists(argv(1), $languages)) { - $lang = argv(1); - $from_url = true; + $this->lang['language'] = argv(1); + $this->lang['from_url'] = true; } else { - $lang = \App::$language; - if(! isset($lang)) - $lang = 'en'; + if(isset(\App::$language)) { + $this->lang['language'] = \App::$language; + } - $from_url = false; + $this->lang['from_url'] = false; } - - $this->lang = array('language' => $lang, 'from_url' => $from_url); } /** @@ -74,7 +73,18 @@ trait HelpHelperTrait { } if (empty($this->file_name) && $lang !== 'en') { + $this->lang['missing'] = true; $this->find_help_file($base_path, 'en'); } } + + public function missing_translation(): bool { + return !!$this->lang['missing']; + } + + public function missing_translation_message(): string { + return bbcode( + t("This page is not yet available in your preferred language. See [observer.baseurl]/help/developer/developer_guide#Translations for information about how to help.") + ); + } } -- cgit v1.2.3 From d3093dce1bfd4685d5e11f828689630862f77bda Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 24 Jul 2024 11:57:41 +0200 Subject: Improve translation message for help pages. Display the target language instead of "your preferred language". Makes it a bit more explicit. --- Zotlabs/Lib/Traits/HelpHelperTrait.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Traits/HelpHelperTrait.php b/Zotlabs/Lib/Traits/HelpHelperTrait.php index 0ce586d08..63b0eb22e 100644 --- a/Zotlabs/Lib/Traits/HelpHelperTrait.php +++ b/Zotlabs/Lib/Traits/HelpHelperTrait.php @@ -83,8 +83,13 @@ trait HelpHelperTrait { } public function missing_translation_message(): string { + $prefered_language_name = get_language_name( + $this->lang['language'], + $this->lang['language'] + ); + return bbcode( - t("This page is not yet available in your preferred language. See [observer.baseurl]/help/developer/developer_guide#Translations for information about how to help.") + t("This page is not yet available in {$prefered_language_name}. See [observer.baseurl]/help/developer/developer_guide#Translations for information about how to help.") ); } } -- cgit v1.2.3