Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 4, 2024
1 parent 54ecb28 commit 82d1ba5
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 105 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Translation Editor
==================

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/translation_editor/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/translation_editor/v/stable.svg)](https://packagist.org/packages/coldtrick/translation_editor)
[![License](https://poser.pugx.org/coldtrick/translation_editor/license.svg)](https://packagist.org/packages/coldtrick/translation_editor)
Expand Down
2 changes: 1 addition & 1 deletion actions/translation_editor/admin/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
// merge translations
translation_editor_merge_translations($lang);

return elgg_ok_response('', elgg_echo('translation_editor:action:delete:success'), "translation_editor/{$lang}");
return elgg_ok_response('', elgg_echo('translation_editor:action:delete:success'), elgg_generate_url('default:translation_editor', ['current_language' => $lang]));
7 changes: 4 additions & 3 deletions actions/translation_editor/admin/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* Exports the custom translations for the selected plugins
*/

use Symfony\Component\HttpFoundation\File\UploadedFile;

$language = get_input('language');

$files = elgg_get_uploaded_files('import');
$import = array_shift($files);
if (!$import || !$import->isValid()) {
$import = elgg_get_uploaded_file('import');
if (!$import instanceof UploadedFile) {
return elgg_error_response(elgg_echo('error:missing_data'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$user_guid = (int) get_input('user');

$user = get_user($user_guid);
if (empty($user)) {
if (!$user instanceof \ElggUser) {
return elgg_error_response(elgg_echo('error:missing_data'));
}

Expand Down
2 changes: 1 addition & 1 deletion actions/translation_editor/merge.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Download the custom trnslations for the provided plugin
* Download the custom translations for the provided plugin
*/

$current_language = get_input('current_language');
Expand Down
4 changes: 2 additions & 2 deletions classes/ColdTrick/TranslationEditor/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
class Bootstrap extends DefaultPluginBootstrap {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function boot() {
$this->loadCustomTranslations();
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function upgrade() {
Upgrade::cleanupCustomTranslations();
Expand Down
5 changes: 3 additions & 2 deletions classes/ColdTrick/TranslationEditor/EditorGatekeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Elgg\Request;
use Elgg\Exceptions\HttpException;
use Elgg\Router\Middleware\Gatekeeper;

/**
* Gatekeeper to only allow translation editors view a page
*/
class EditorGatekeeper {
class EditorGatekeeper extends Gatekeeper {

/**
* Editor gatekeeper
Expand All @@ -19,7 +20,7 @@ class EditorGatekeeper {
* @throws HttpException
*/
public function __invoke(Request $request) {
$request->elgg()->gatekeeper->assertAuthenticatedUser();
parent::__invoke($request);

$user_guid = $request->elgg()->session_manager->getLoggedInUserGuid();
if (translation_editor_is_translation_editor($user_guid)) {
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/TranslationEditor/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Languages {

/**
* Add languages to the languagelist
* Add languages to the language list
*
* @param \Elgg\Event $event 'languages', 'translations'
*
Expand Down
6 changes: 3 additions & 3 deletions classes/ColdTrick/TranslationEditor/PluginTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ protected function getFilename(): string {
*
* @return false|int
*/
public function saveTranslations($translations = []) {
public function saveTranslations(array $translations = []): false|int {
$this->createFolderStructure();

$contents = json_encode($translations);

$bytes = file_put_contents($this->getFilename(), $contents);
if (empty($bytes)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issues": "https://github.com/ColdTrick/translation_editor/issues"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* All helper function for this plugin are bundled here
*/

use ColdTrick\TranslationEditor\PluginTranslation;
use Elgg\Project\Paths;
use Elgg\Includer;
use Elgg\Exceptions\InvalidArgumentException;
Expand Down Expand Up @@ -318,7 +319,7 @@ function translation_editor_clean_line_breaks(string $string): string {
*
* @return false|int
*/
function translation_editor_write_translation(string $current_language, string $plugin, array $translations) {
function translation_editor_write_translation(string $current_language, string $plugin, array $translations): false|int {
try {
$translation = new \ColdTrick\TranslationEditor\PluginTranslation($plugin, $current_language);
return $translation->saveTranslations($translations);
Expand All @@ -339,7 +340,7 @@ function translation_editor_write_translation(string $current_language, string $
*/
function translation_editor_read_translation(string $current_language, string $plugin): array {
try {
$translation = new \ColdTrick\TranslationEditor\PluginTranslation($plugin, $current_language);
$translation = new PluginTranslation($plugin, $current_language);
return $translation->readTranslations() ?: [];
} catch (InvalidArgumentException $e) {
elgg_log($e);
Expand Down Expand Up @@ -387,7 +388,7 @@ function translation_editor_load_translations(string $current_language = ''): vo
*/
function translation_editor_delete_translation(string $current_language, string $plugin): bool {
try {
$translation = new \ColdTrick\TranslationEditor\PluginTranslation($plugin, $current_language);
$translation = new PluginTranslation($plugin, $current_language);
return $translation->removeTranslations();
} catch (InvalidArgumentException $e) {
elgg_log($e);
Expand Down Expand Up @@ -520,7 +521,7 @@ function translation_editor_search_translation(string $query, string $language =
*
* @param string $language the language to merge
*
* @return false|array
* @return null|array
*/
function translation_editor_merge_translations(string $language = ''): ?array {
if (empty($language)) {
Expand Down Expand Up @@ -571,9 +572,9 @@ function translation_editor_merge_translations(string $language = ''): ?array {
* @param string $string the string to search parameters for
* @param bool $count return the count of the parameters (default = true)
*
* @return array
* @return int|array
*/
function translation_editor_get_string_parameters(string $string, bool $count = true): array {
function translation_editor_get_string_parameters(string $string, bool $count = true): int|array {
$valid = '/%(?:\d+\$)?[-+]?(?:[ 0]|\'.)?a?\d*(?:\.\d*)?[%bcdeEufFgGosxX]/';

$result = [];
Expand Down
12 changes: 0 additions & 12 deletions views/default/forms/translation_editor/admin/remote.js

This file was deleted.

13 changes: 13 additions & 0 deletions views/default/forms/translation_editor/admin/remote.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'jquery';

$(document).on('click', '#translation-editor-import-filter', function() {
$('.translation-editor-import-plugin-selection input[type="checkbox"]:checked').prop('checked', false);
$('.translation-editor-import-plugin-selection').removeClass('hidden');
$('#translation-editor-import-filter, #translation-editor-import-all').closest('.elgg-field').toggleClass('hidden');
});

$(document).on('click', '#translation-editor-import-all', function() {
$('.translation-editor-import-plugin-selection').addClass('hidden');
$('#translation-editor-import-filter, #translation-editor-import-all').closest('.elgg-field').toggleClass('hidden');
$('.translation-editor-import-plugin-selection input[type="checkbox"]:not(:checked)').prop('checked', true);
});
2 changes: 1 addition & 1 deletion views/default/forms/translation_editor/admin/remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
return;
}

elgg_require_js('forms/translation_editor/admin/remote');
elgg_import_esm('forms/translation_editor/admin/remote');

echo elgg_view_field([
'#type' => 'hidden',
Expand Down
42 changes: 0 additions & 42 deletions views/default/translation_editor/key_edit.js

This file was deleted.

43 changes: 43 additions & 0 deletions views/default/translation_editor/key_edit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'jquery';
import Ajax from 'elgg/Ajax';

var locked = false;
var data = new FormData();

function submit_data() {
if (locked) {
return;
}

locked = true;

var sending = data;
data = new FormData();

var ajax = new Ajax();
ajax.action('translation_editor/translate', {
data: sending,
complete: function() {
locked = false;

if (data_count()) {
submit_data();
}
}
});
}

function data_count() {
var i = 0;
for (var entry of data.entries()) {
i++;
}

return i;
}

$(document).on('change', '.translation-editor-input', function() {
data.set($(this).prop('name'), $(this).val());

submit_data();
});
4 changes: 2 additions & 2 deletions views/default/translation_editor/key_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* @uses $vars['plugin'] plugin id
*/

elgg_require_js('elgg/toggle');
elgg_require_js('translation_editor/key_edit');
elgg_import_esm('elgg/toggle');
elgg_import_esm('translation_editor/key_edit');

$current_language = elgg_extract('language', $vars);
$english = elgg_extract('english', $vars);
Expand Down
23 changes: 0 additions & 23 deletions views/default/translation_editor/plugin_edit.js

This file was deleted.

22 changes: 22 additions & 0 deletions views/default/translation_editor/plugin_edit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'jquery';

$(document).on('click', '.elgg-menu-translation-editor-plugin-edit a', function() {
var $container = $(this).closest('.elgg-menu-container');
$container.find('.elgg-state-selected').removeClass('elgg-state-selected');
$(this).closest('li').addClass('elgg-state-selected');

var rel = $(this).prop('rel');
if (!typeof rel === 'string' || rel.length === 0) {
return;
}

$('.translation-editor-translation-table tbody tr.translation-editor-original').hide();

var $tr = $('.translation-editor-translation-table tbody tr:not(.translation-editor-original)');
if (rel === 'all') {
$tr.show();
} else {
$tr.hide();
$tr.filter('[rel="' + rel + '"]').show();
}
});
2 changes: 1 addition & 1 deletion views/default/translation_editor/plugin_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}

// toggle between different filters
elgg_require_js('translation_editor/plugin_edit');
elgg_import_esm('translation_editor/plugin_edit');

$menu_items = [];

Expand Down

0 comments on commit 82d1ba5

Please sign in to comment.