diff --git a/include/shared-manual.inc b/include/shared-manual.inc index d14d6c4565..f104d1549d 100644 --- a/include/shared-manual.inc +++ b/include/shared-manual.inc @@ -30,7 +30,9 @@ use phpweb\UserNotes\UserNote; * * @param array $notes */ -function manual_notes($notes, $repo = 'en'):void { +function manual_notes($notes):void { + global $LANG; + // Get needed values list($filename) = $GLOBALS['PGI']['this']; @@ -42,6 +44,7 @@ function manual_notes($notes, $repo = 'en'):void { $sorter = new Sorter(); $sorter->sort($notes); + $addNote = autogen('add_a_note', $LANG); // Link target to add a note to the current manual page, // and it's extended form with a [+] image $addnotelink = '/manual/add-note.php?sect=' . $filename . @@ -49,7 +52,7 @@ function manual_notes($notes, $repo = 'en'):void { '&redirect=' . $_SERVER['BASE_HREF']; $addnotesnippet = make_link( $addnotelink, - "+add a note", + "+$addNote", ); $num_notes = count($notes); @@ -58,17 +61,19 @@ function manual_notes($notes, $repo = 'en'):void { $noteCountHtml = "$num_notes note" . ($num_notes == 1 ? '' : 's') . ""; } + $userContributedNotes = autogen('user_contributed_notes', $LANG); echo <<
{$addnotesnippet} -

User Contributed Notes {$noteCountHtml}

+

$userContributedNotes {$noteCountHtml}

END_USERNOTE_HEADER; // If we have no notes, then inform the user if ($num_notes === 0) { - echo "\n
There are no user contributed notes for this page.
"; + $noUserContributedNotes = autogen('no_user_notes', $LANG); + echo "\n
$noUserContributedNotes
"; } else { // If we have notes, print them out echo '
'; @@ -334,7 +339,7 @@ PAGE_TOOLS; } function manual_language_chooser($currentlang, $currentpage) { - global $ACTIVE_ONLINE_LANGUAGES; + global $ACTIVE_ONLINE_LANGUAGES, $LANG; // Prepare the form with all the options $othersel = ' selected="selected"'; @@ -350,10 +355,11 @@ function manual_language_chooser($currentlang, $currentpage) { $out[] = ""; $format_options = implode("\n" . str_repeat(' ', 6), $out); + $changeLanguage = autogen('change_language', $LANG); $r = <<
- + @@ -364,7 +370,7 @@ CHANGE_LANG; } function manual_footer($setup): void { - global $USERNOTES, $__RELATED; + global $USERNOTES, $__RELATED, $LANG; $id = substr($setup['this'][0], 0, -4); $repo = strtolower($setup["head"][1]); // pt_BR etc. @@ -393,18 +399,23 @@ function manual_footer($setup): void { $contributors = 'All contributors.'; } + $improveThisPage = autogen('improve_this_page', $LANG); + $howToImproveThisPage = autogen('how_to_improve_this_page', $LANG); + $contributionGuidlinesOnGithub = autogen('contribution_guidlines_on_github', $LANG); + $submitPullRequest = autogen('submit_a_pull_request', $LANG); + $reportBug = autogen('report_a_bug', $LANG); echo << -

Improve This Page

+

$improveThisPage

$lastUpdate $contributors
CONTRIBUTE; @@ -459,3 +470,35 @@ CONTRIBUTORS; manual_footer($setup); exit; } + +function autogen(string $text, string $lang) { + static $translations = []; + + $lang = ($lang === "") ? "en" : $lang; + if (isset($translations[$lang])) { + if (isset($translations[$lang][$text]) && $translations[$lang][$text] !== "") { + return $translations[$lang][$text]; + } + if ($lang !== "en") { + // fall back to English if text is not defined for the given language + return autogen($text, "en"); + } + // we didn't find the English text either + throw new \InvalidArgumentException("Cannot autogenerate text for '$text'"); + } + + $translationFile = __DIR__ . \DIRECTORY_SEPARATOR . "ui_translation" . \DIRECTORY_SEPARATOR . $lang . ".ini"; + + if (!\file_exists($translationFile)) { + if ($lang !== "en") { + // fall back to English if translation file is not found + return autogen($text, "en"); + } + // we didn't find the English file either + throw new \Exception("Cannot find translation files"); + } + + $translations[$lang] = \parse_ini_file($translationFile); + + return autogen($text, $lang); +} diff --git a/include/ui_translation/de.ini b/include/ui_translation/de.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/de.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/en.ini b/include/ui_translation/en.ini new file mode 100644 index 0000000000..32ae383609 --- /dev/null +++ b/include/ui_translation/en.ini @@ -0,0 +1,9 @@ +change_language = "Change language" +improve_this_page = "Improve This Page" +how_to_improve_this_page = "Learn How To Improve This Page" +contribution_guidlines_on_github = "This will take you to our contribution guidelines on GitHub" +submit_a_pull_request = "Submit a Pull Request" +report_a_bug = "Report a Bug" +add_a_note = "add a note" +user_contributed_notes = "User Contributed Notes" +no_user_notes = "There are no user contributed notes for this page." diff --git a/include/ui_translation/es.ini b/include/ui_translation/es.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/es.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/fr.ini b/include/ui_translation/fr.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/fr.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/it.ini b/include/ui_translation/it.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/it.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/ja.ini b/include/ui_translation/ja.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/ja.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/pt_br.ini b/include/ui_translation/pt_br.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/pt_br.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/ru.ini b/include/ui_translation/ru.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/ru.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/tr.ini b/include/ui_translation/tr.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/tr.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = "" diff --git a/include/ui_translation/zh.ini b/include/ui_translation/zh.ini new file mode 100644 index 0000000000..e24fe76b9e --- /dev/null +++ b/include/ui_translation/zh.ini @@ -0,0 +1,9 @@ +change_language = "" +improve_this_page = "" +how_to_improve_this_page = "" +contribution_guidlines_on_github = "" +submit_a_pull_request = "" +report_a_bug = "" +add_a_note = "" +user_contributed_notes = "" +no_user_notes = ""