forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-69582 tool_customlang: add export langstring feature
- Loading branch information
1 parent
757f832
commit 1f4a5e4
Showing
10 changed files
with
249 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Creates Formular for customlang file export | ||
* | ||
* @package tool_customlang | ||
* @copyright 2020 Thomas Wedekind <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace tool_customlang\form; | ||
|
||
use tool_customlang_utils; | ||
|
||
/** | ||
* Formular for customlang file export | ||
* | ||
* @copyright 2020 Thomas Wedekind <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class export extends \moodleform { | ||
|
||
/** | ||
* Add elements to form | ||
*/ | ||
public function definition() { | ||
$lng = $this->_customdata['lng']; | ||
$mform = $this->_form; | ||
|
||
$langdir = tool_customlang_utils::get_localpack_location($lng); | ||
|
||
// The export button only appears if a local lang is present. | ||
if (!check_dir_exists($langdir) || !count(glob("$langdir/*"))) { | ||
print_error('nolocallang', 'tool_customlang'); | ||
} | ||
|
||
$langfiles = scandir($langdir); | ||
$fileoptions = []; | ||
foreach ($langfiles as $file) { | ||
if (substr($file, 0, 1) != '.') { | ||
$fileoptions[$file] = $file; | ||
} | ||
} | ||
|
||
$mform->addElement('hidden', 'lng', $lng); | ||
$mform->setType('lng', PARAM_LANG); | ||
|
||
$select = $mform->addElement('select', 'files', get_string('exportfilter', 'tool_customlang'), $fileoptions); | ||
$select->setMultiple(true); | ||
$mform->addRule('files', get_string('required'), 'required', null, 'client'); | ||
$mform->setDefault('files', $fileoptions); | ||
|
||
$this->add_action_buttons(true, get_string('export', 'tool_customlang')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Performs the custom lang export. | ||
* | ||
* @package tool_customlang | ||
* @subpackage customlang | ||
* @copyright 2020 Thomas Wedekind <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require(__DIR__ . '/../../../config.php'); | ||
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php'); | ||
require_once($CFG->libdir.'/adminlib.php'); | ||
|
||
global $PAGE, $CFG; | ||
|
||
require_login(SITEID, false); | ||
require_capability('tool/customlang:export', context_system::instance()); | ||
|
||
$lng = required_param('lng', PARAM_LANG); | ||
|
||
admin_externalpage_setup('toolcustomlang', '', null, | ||
new moodle_url('/admin/tool/customlang/import.php', ['lng' => $lng])); | ||
|
||
$form = new \tool_customlang\form\export(null, ['lng' => $lng]); | ||
|
||
if ($form->is_cancelled()) { | ||
redirect('index.php'); | ||
die(); | ||
} else if ($formdata = $form->get_data()) { | ||
$tempzip = tempnam($CFG->tempdir . '/', 'tool_customlang_export'); | ||
$filelist = []; | ||
foreach ($formdata->files as $file) { | ||
$filepath = tool_customlang_utils::get_localpack_location($lng). '/' . $file; | ||
if (file_exists($filepath)) { | ||
$filelist[$file] = $filepath; | ||
} | ||
} | ||
$zipper = new zip_packer(); | ||
|
||
if (!empty($filelist) && $zipper->archive_to_pathname($filelist, $tempzip)) { | ||
// Filename include the lang name so the file can be imported with automatic language detection. | ||
send_temp_file($tempzip, "customlang_$lng.zip"); | ||
die(); | ||
} | ||
} | ||
|
||
$output = $PAGE->get_renderer('tool_customlang'); | ||
|
||
echo $output->header(); | ||
echo $output->heading(get_string('pluginname', 'tool_customlang')); | ||
$form->display(); | ||
echo $OUTPUT->footer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
admin/tool/customlang/tests/behat/customisation_create.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@tool @tool_customlang | ||
Feature: Within a moodle instance, an administrator should be able to modify langstrings for the entire Moodle installation. | ||
In order to change langstrings in the adminsettings of the instance, | ||
As an admin | ||
I need to be able to access and change values in the the language customisation of the language pack. | ||
|
||
Background: | ||
Given I log in as "admin" | ||
And I navigate to "Language > Language customisation" in site administration | ||
And I set the field "lng" to "en" | ||
And I press "Open language pack for editing" | ||
And I press "Continue" | ||
And I set the field "Show strings of these components" to "moodle.php" | ||
And I set the field "String identifier" to "administrationsite" | ||
And I press "Show strings" | ||
And I set the field "core/administrationsite" to "Custom string example" | ||
|
||
@javascript | ||
Scenario: Edit an string but don't save it to lang pack. | ||
When I press "Apply changes and continue editing" | ||
Then I should see "Site administration" in the "page-header" "region" | ||
And I should not see "Custom string example" in the "page-header" "region" | ||
|
||
@javascript | ||
Scenario: Customize an string as admin and save it to lang pack. | ||
Given I press "Save changes to the language pack" | ||
And I should see "There are 1 modified strings." | ||
When I click on "Continue" "button" | ||
Then I should see "Custom string example" in the "page-header" "region" | ||
And I should not see "Site administration" in the "page-header" "region" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@tool @tool_customlang | ||
Feature: Within a moodle instance, an administrator should be able to export modified langstrings. | ||
In order to export modified langstrings in the adminsettings of the instance, | ||
As an admin | ||
I need to be able to export the php-files of the language customisation of a language. | ||
|
||
@javascript | ||
Scenario: Export button should not appear if no customization is made | ||
Given I log in as "admin" | ||
And I navigate to "Language > Language customisation" in site administration | ||
And I set the field "lng" to "en" | ||
Then I should see "Open language pack for editing" | ||
And I should not see "Export custom strings" | ||
|
||
@javascript | ||
Scenario: Export button should not appear if no customization is saved into langpack | ||
Given I log in as "admin" | ||
And I navigate to "Language > Language customisation" in site administration | ||
And I set the field "lng" to "en" | ||
And I press "Open language pack for editing" | ||
And I press "Continue" | ||
And I set the field "Show strings of these components" to "moodle.php" | ||
And I set the field "String identifier" to "accept" | ||
And I press "Show strings" | ||
And I set the field "core/accept" to "Accept-custom_export" | ||
When I press "Apply changes and continue editing" | ||
And I navigate to "Language > Language customisation" in site administration | ||
And I set the field "lng" to "en" | ||
Then I should see "Open language pack for editing" | ||
And I should see "There are 1 modified strings." | ||
And I should not see "Export custom strings" | ||
|
||
@javascript | ||
Scenario: Export the php-file including a customised langstring. | ||
Given I log in as "admin" | ||
And I navigate to "Language > Language customisation" in site administration | ||
And I set the field "lng" to "en" | ||
And I press "Open language pack for editing" | ||
And I press "Continue" | ||
And I set the field "Show strings of these components" to "moodle.php" | ||
And I set the field "String identifier" to "accept" | ||
And I press "Show strings" | ||
And I set the field "core/accept" to "Accept-custom_export" | ||
When I press "Save changes to the language pack" | ||
And I should see "There are 1 modified strings." | ||
And I click on "Continue" "button" | ||
Then I set the field "lng" to "en" | ||
And I click on "Export custom strings" "button" | ||
And I set the field "Select component(s) to export" to "moodle.php" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters