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/Lib | |
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/Lib')
-rw-r--r-- | Zotlabs/Lib/Traits/HelpHelperTrait.php | 47 |
1 files changed, 37 insertions, 10 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.") + ); } } |