Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
install german language
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed Jul 8, 2024
1 parent 752996f commit ada9c37
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ ARG PLUGIN_VERSION=main

FROM bitnami/moodle:${MOODLE_VERSION}

# generate german language files
RUN sed -i 's/^# de_DE.UTF-8 UTF-8$/de_DE.UTF-8 UTF-8/' /etc/locale.gen && locale-gen

RUN apt update && apt install curl unzip nano -y
COPY opt/adler /opt/adler
COPY plugin-releases.json /opt/adler/moodle/adler_setup
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ When building the Docker image for this project, you can customize the following
These arguments allow you to control the versions of Moodle and the plugin that are used during the image build process. You can adjust these values according to your specific
requirements and preferences.

## Install additional languages
1) Install the required system locale by modifying the Dockerfile
2) Install the moodle language pack either via web interface or by modifying the setup.php script (add an additional
`install_language_pack` call for the desired language)

## Troubleshooting

**Moodle setup fails with "The configuration file config.php alreaady exists. ...":** \
Expand Down
35 changes: 35 additions & 0 deletions opt/adler/moodle/adler_setup/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use local_adler\plugin_interface;
use core\event\user_created;
use tool_langimport\controller as lang_controller;



/** Get Infos (incl download urls) of release to update to. Will return false if nothing to update
Expand Down Expand Up @@ -179,3 +181,36 @@ function create_default_course_category_for_user($username) {
// use local_adler cli script
plugin_interface::create_category_user_can_create_courses_in($username, 'adler_manager');
}


/**
* @param $language_code string language code. List of valid codes can be found at Site administration -> Language -> Language packs
* @return bool
*/
function is_language_pack_installed(string $language_code): bool {
$installed_langs = get_string_manager()->get_list_of_translations();
return str_contains($installed_langs, "($language_code)");
}

/**
* @param $language_code string language code. List of valid codes can be found at Site administration -> Language -> Language packs
* @return void
*/
function install_language_pack(string $language_code): void {
if (is_language_pack_installed($language_code)) {
cli_writeln("Language pack already installed");
return;
}

$lang_controller = new lang_controller();
try {
$result = $lang_controller->install_languagepacks($language_code);
if ($result == 1) {
cli_writeln("Language \"" . $language_code . "\" was installed");
} else {
cli_error("Language \"" . $language_code . "\" was not installed. The reason is unknown due to moodle limitations.");
}
} catch (Exception $e) {
cli_error("Failed to install language pack \"$language_code\". Reason: " . $e->getMessage());
}
}
3 changes: 3 additions & 0 deletions opt/adler/moodle/adler_setup/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@ function do_adler_roles_exist() {
cli_writeln("creating user(s)");
create_users($options);
}

// activate german language pack
install_language_pack('de');
}

0 comments on commit ada9c37

Please sign in to comment.