diff --git a/lang/en/local_staticpage.php b/lang/en/local_staticpage.php index a08b51c..cdaa340 100644 --- a/lang/en/local_staticpage.php +++ b/lang/en/local_staticpage.php @@ -64,6 +64,7 @@ $string['processfiltersyes'] = 'Yes, process filters'; $string['settingspagelist'] = 'List of static pages'; $string['settingspagelistentryfilename'] = 'The following document file was found:
{$a}'; +$string['settingspagelistentrypagelanguages'] = 'Translations found:
{$a}'; $string['settingspagelistentrypagename'] = 'From the document file\'s filename, Moodle derived the following pagename:
{$a}'; $string['settingspagelistentryrewritedisabled'] = 'The static page should be available at the following clean URL, but is not verified because checking availability is disabled:
{$a}'; $string['settingspagelistentryrewriteerror'] = 'The static page should be available at the following clean URL, but actually a browser won\'t be able to download and view it either because of connection error or responding slower than checkavailabilitytimeout config (perhaps there is something wrong with your webserver or mod_rewrite configuration):
{$a}'; diff --git a/settings_pagelist.php b/settings_pagelist.php index 20e5e03..0ae5021 100644 --- a/settings_pagelist.php +++ b/settings_pagelist.php @@ -83,6 +83,30 @@ // Get plugin config. $localstaticpageconfig = get_config('local_staticpage'); + // Initialize page and language variables. + $pagelanguages = []; + $pagename = ''; + + // Preprocess $pages array to remove translations from the list. + foreach ($pages as $key => $page) { + + // Collect information about the page. + $filename = $page->get_filename(); + $pagename = pathinfo($filename, PATHINFO_FILENAME); + + // Check if the page is a translation. + if (preg_match('/--[a-zA-Z]{2}$/', $pagename, $matches)) { + // Get the language code. + $language = substr($matches[0], 2); + // Get the default page name. + $defaultpagename = substr($pagename, 0, -4); + // Add the language to the list. + $pagelanguages[$defaultpagename][] = $language; + // Remove the translation from the list. + unset($pages[$key]); + } + } + // Output each page as a page list entry. foreach ($pages as $page) { @@ -103,6 +127,11 @@ $html .= html_writer::tag('p', get_string('settingspagelistentryfilename', 'local_staticpage', $pagefilename)); $html .= html_writer::tag('p', get_string('settingspagelistentrypagename', 'local_staticpage', $pagepagename)); + if (array_key_exists($pagepagename, $pagelanguages)) { + $html .= html_writer::tag('p', get_string('settingspagelistentrypagelanguages', 'local_staticpage', + implode(', ', $pagelanguages[$pagepagename]))); + } + // Print normal static page URL - Do only if apache rewrite isn't forced. if (!$localstaticpageconfig->apacherewrite) { // Check availability. diff --git a/view.php b/view.php index 1d78b8a..af75671 100644 --- a/view.php +++ b/view.php @@ -66,6 +66,18 @@ // Get filearea. $fs = get_file_storage(); +// Get current language. +$lang = current_language(); + +// Get translated file. +$filenametranslated = "$page--$lang.html"; +$file = $fs->get_file($context->id, 'local_staticpage', 'documents', 0, '/', $filenametranslated); + +// If translated file exists replace default filename. +if ($file) { + $filename = $filenametranslated; +} + // Get document from filearea. $file = $fs->get_file($context->id, 'local_staticpage', 'documents', 0, '/', $filename);