diff options
-rw-r--r-- | Zotlabs/Module/Help.php | 5 | ||||
-rw-r--r-- | include/help.php | 25 | ||||
-rw-r--r-- | view/js/mod_help.js | 50 | ||||
-rw-r--r-- | view/tpl/help.tpl | 15 |
4 files changed, 93 insertions, 2 deletions
diff --git a/Zotlabs/Module/Help.php b/Zotlabs/Module/Help.php index e98cb9d4d..f3cc3aa5f 100644 --- a/Zotlabs/Module/Help.php +++ b/Zotlabs/Module/Help.php @@ -88,12 +88,15 @@ class Help extends \Zotlabs\Web\Controller { $heading = $headings[argv(1)]; $content = get_help_content(); + + $language = determine_help_language()['language']; return replace_macros(get_markup_template('help.tpl'), array( '$title' => t('$Projectname Documentation'), '$tocHeading' => t('Contents'), '$content' => $content, - '$heading' => $heading + '$heading' => $heading, + '$language' => $language )); } diff --git a/include/help.php b/include/help.php index f38f77854..ef6b77e12 100644 --- a/include/help.php +++ b/include/help.php @@ -32,6 +32,13 @@ function get_help_content($tocpath = false) { if(! $tocpath) \App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('-',' ',notags($title))); + if($tocpath !== false && + load_doc_file('doc/' . $path . '.md') === '' && + load_doc_file('doc/' . $path . '.bb') === '' && + load_doc_file('doc/' . $path . '.html') === '' + ) { + $path = 'toc'; + } $text = load_doc_file('doc/' . $path . '.md'); if(! $text) { @@ -110,7 +117,10 @@ function preg_callback_help_include($matches) { function determine_help_language() { require_once('Text/LanguageDetect.php'); $lang_detect = new Text_LanguageDetect(); + // Set this mode to recognize language by the short code like "en", "ru", etc. $lang_detect->setNameMode(2); + // If the language was specified in the URL, override the language preference + // of the browser. Default to English if both of these are absent. if($lang_detect->languageExists(argv(1))) { $lang = argv(1); $from_url = true; @@ -125,13 +135,16 @@ function determine_help_language() { function load_doc_file($s) { $path = 'doc'; + // Determine the language and modify the path accordingly $x = determine_help_language(); $lang = $x['language']; $url_idx = ($x['from_url'] ? 1 : 0); + // The English translation is at the root of /doc/. Other languages are in + // subfolders named by the language code such as "de", "es", etc. if($lang !== 'en') { $path .= '/' . $lang; } - + $b = basename($s); for($i=1+$url_idx; $i<argc()-1; $i++) { @@ -140,6 +153,16 @@ function load_doc_file($s) { $c = find_doc_file($path . '/' . $b); if($c) return $c; + // Possibly a translation was requested that has not been translated, so fall + // back to the English version + $path = 'doc'; + for($i=1+$url_idx; $i<argc()-1; $i++) { + $path .= '/' . argv($i); + } + $c = find_doc_file($path . '/' . $b); + if($c) + return $c; + // Try one last time to find the file at the explicit path input to the function $c = find_doc_file($s); if($c) return $c; diff --git a/view/js/mod_help.js b/view/js/mod_help.js index 0f85af462..257be67e6 100644 --- a/view/js/mod_help.js +++ b/view/js/mod_help.js @@ -71,4 +71,54 @@ $(document).ready(function () { var newref = p.protocol + '//' + p.hostname + portstr + p.pathname + p.hash.split('?').shift(); location.replace(newref) } + + + // Determine language translations available from the language selector menu itself + var langChoices = []; + $('.lang-selector').find('.lang-choice').each(function (idx, a) { + langChoices.push($(a).html()); + }); + // Parse the URL and insert the language code for the loaded language, based + // on the variable "help_language" that is declared in the help.tpl page template + var path = window.location.pathname.split('/'); + var pathParts = []; + var pick_me = true; + for (var i = 0; i < path.length; i++) { + if(i === 2 && pick_me ) { + if(path[i].length > 0) { + pathParts.push(help_language); + pick_me = false; + if($.inArray(path[i], langChoices) < 0) { + i--; + } + } + } else { + if(path[i].length > 0) { + pathParts.push(path[i]); + } + } + + } + // Update the address bar to reflect the loaded language + window.history.pushState({}, '', '/' + pathParts.join('/')); + + // Highlight the language in the language selector that is currently viewed + $('.lang-selector').find('.lang-choice:contains("' + help_language + '")').css('font-weight','bold').css('background-color','lightgray'); + + // Construct the links to the available translations based and populate the selector menu + $('.lang-selector').find('.lang-choice').each(function (idx, a) { + var langLink = []; + + for (var i = 0; i < pathParts.length; i++) { + + if(i === 1) { + langLink.push($(a).html()); + } else { + langLink.push(pathParts[i]); + } + + } + $(a).attr('href', '/' + langLink.join('/')); + }); + }); diff --git a/view/tpl/help.tpl b/view/tpl/help.tpl index 31e5b9794..bdb25edf1 100644 --- a/view/tpl/help.tpl +++ b/view/tpl/help.tpl @@ -1,5 +1,17 @@ <div id="help-content" class="generic-content-wrapper"> <div class="section-title-wrapper"> + <div class="pull-right"> + <div class="btn-group"> + <button type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle" data-toggle="dropdown"> + <i class="fa fa-language" style="font-size: 1.4em;"></i><span class="caret"></span> + </button> + <div class="dropdown-menu dropdown-menu-right flex-column lang-selector"> + <a class="dropdown-item lang-choice" href="/help">de</a> + <a class="dropdown-item lang-choice" href="/help">en</a> + <a class="dropdown-item lang-choice" href="/help">es</a> + </div> + </div> + </div> <h2>{{$title}}: {{$heading}}</h2> </div> <div class="section-content-wrapper" id="doco-content"> @@ -13,3 +25,6 @@ {{$content}} </div> </div> +<script> + var help_language = '{{$language}}' +</script> |