diff options
author | Mario <mario@mariovavti.com> | 2024-07-29 09:59:04 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-07-29 09:59:04 +0000 |
commit | 52f7b508af7bd6eb00eb76b4e170b44a55be869f (patch) | |
tree | d72d94366a985be578cc4729fb9ac2078cbc267e /Zotlabs | |
parent | 15f6bc93cf53cf05162d1314852f567ab2af2bc6 (diff) | |
parent | d3093dce1bfd4685d5e11f828689630862f77bda (diff) | |
download | volse-hubzilla-52f7b508af7bd6eb00eb76b4e170b44a55be869f.tar.gz volse-hubzilla-52f7b508af7bd6eb00eb76b4e170b44a55be869f.tar.bz2 volse-hubzilla-52f7b508af7bd6eb00eb76b4e170b44a55be869f.zip |
Merge branch 'improve-help-locale-handling' into 'dev'
Improve handling of locale in Help module
See merge request hubzilla/core!2140
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Lib/Traits/HelpHelperTrait.php | 47 | ||||
-rw-r--r-- | Zotlabs/Module/Help.php | 13 | ||||
-rw-r--r-- | Zotlabs/Widget/Helpindex.php | 4 |
3 files changed, 45 insertions, 19 deletions
diff --git a/Zotlabs/Lib/Traits/HelpHelperTrait.php b/Zotlabs/Lib/Traits/HelpHelperTrait.php index b7711bbd5..63b0eb22e 100644 --- a/Zotlabs/Lib/Traits/HelpHelperTrait.php +++ b/Zotlabs/Lib/Traits/HelpHelperTrait.php @@ -15,6 +15,15 @@ trait HelpHelperTrait { 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 + 'missing' => false, //! true if topic not found in detected language + ]; + + /** * Determines help language. * * If the language was specified in the URL, override the language preference @@ -28,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); } /** @@ -53,10 +60,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 +71,25 @@ trait HelpHelperTrait { break; } } + + 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 { + $prefered_language_name = get_language_name( + $this->lang['language'], + $this->lang['language'] + ); + + return bbcode( + 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.") + ); } } diff --git a/Zotlabs/Module/Help.php b/Zotlabs/Module/Help.php index fd5cacee6..851776591 100644 --- a/Zotlabs/Module/Help.php +++ b/Zotlabs/Module/Help.php @@ -6,6 +6,7 @@ use Michelf\MarkdownExtra; /** * You can create local site resources in doc/Site.md and either link to doc/Home.md for the standard resources * or use our include mechanism to include it on your local page. + * *@code * #include doc/Home.md; *@endcode @@ -19,14 +20,6 @@ class Help extends \Zotlabs\Web\Controller { private string $heading_slug = ''; /** - * Associative array containing the detected language. - */ - public array $lang = [ - 'language' => 'en', //! Detected language, 2-letter ISO 639-1 code ("en") - 'from_url' => false, //! true if language from URL overrides browser default - ]; - - /** * Pre-check before processing request. * * Determine language requested, and ensure that a topic was requested. @@ -160,6 +153,10 @@ class Help extends \Zotlabs\Web\Controller { array_shift($args); } + if (empty($args)) { + goaway("/help/{$this->lang['language']}/about/about"); + } + // Keep the first remaining arg as the heading slug $this->heading_slug = $args[0]; diff --git a/Zotlabs/Widget/Helpindex.php b/Zotlabs/Widget/Helpindex.php index 5264e1947..fd9204c9e 100644 --- a/Zotlabs/Widget/Helpindex.php +++ b/Zotlabs/Widget/Helpindex.php @@ -22,7 +22,9 @@ class Helpindex { $this->find_help_file('toc', $this->lang['language']); if (! empty($this->file_name)) { - $this->contents = file_get_contents($this->file_name); + $this->contents = translate_projectname( + file_get_contents($this->file_name) + ); } $tpl = get_markup_template('widget.tpl'); |