commit 7f8aa5be4a93ce1088df7e019a3e9220a4dfdfa0 Author: Lukas Winkler Date: Fri Oct 26 21:26:24 2018 +0200 initial version diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8546318 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## Changelog + +Here goes the changelog text. diff --git a/CustomiseTranslations.php b/CustomiseTranslations.php new file mode 100644 index 0000000..bef2bf1 --- /dev/null +++ b/CustomiseTranslations.php @@ -0,0 +1,22 @@ + 'getStylesheetFiles', + ); + } + + public function getStylesheetFiles(&$files) { + $files[] = "plugins/CustomiseTranslations/stylesheets/styles.less"; + } +} diff --git a/MyCustomLoader.php b/MyCustomLoader.php new file mode 100644 index 0000000..cc102ba --- /dev/null +++ b/MyCustomLoader.php @@ -0,0 +1,26 @@ +tranlations->getValue(); + foreach ($trans as $translation) { + if ($translation["translationKey"] == "") { + continue; + } + $split = explode("_", $translation["translationKey"]); + + $translations[$split[0]][$split[1]] = $translation["translationText"]; + } + + return $translations; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..46c449b --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Matomo Customise Translations + +## Description + +This plugin allows you to quickly replace translatable texts in Matomo. diff --git a/SystemSettings.php b/SystemSettings.php new file mode 100644 index 0000000..777fa7a --- /dev/null +++ b/SystemSettings.php @@ -0,0 +1,58 @@ +title = "Customize Translation"; // this can't be translated as it would create a loop + + $this->tranlations = $this->createTranslationsSetting(); + } + + private function createTranslationsSetting() { + return $this->makeSetting('translations', array(), FieldConfig::TYPE_ARRAY, function (FieldConfig $field) { + $plugins = Manager::getAllPluginsNames(); + $field->description = Piwik::translate('CustomiseTranslations_Description'); + $field->uiControl = FieldConfig::UI_CONTROL_MULTI_TUPLE; + $field1 = new FieldConfig\MultiPair(Piwik::translate('CustomiseTranslations_TranslationKey'), 'translationKey', FieldConfig::UI_CONTROL_TEXT); + $field2 = new FieldConfig\MultiPair(Piwik::translate('CustomiseTranslations_Replacement'), 'translationText', FieldConfig::UI_CONTROL_TEXTAREA); + $field->uiControlAttributes['field1'] = $field1->toArray(); + $field->uiControlAttributes['field2'] = $field2->toArray(); + $field->validate = function ($value, Setting $setting) use ($plugins) { + foreach ($value as $translation) { + $key = $translation["translationKey"]; + if ($key == "") { + continue; + } + $split = explode("_", $key); + if (count($split) !== 2) { + throw new \Exception(Piwik::translate("CustomiseTranslations_MisingUnderscore")); + } + + if (!in_array($split[0], $plugins)) { + throw new \Exception(Piwik::translate("CustomiseTranslations_InvalidPlugin", $split[0])); + } + if ($key === Piwik::translate($key)) { + throw new \Exception(Piwik::translate("CustomiseTranslations_InvalidKey", $key)); + } + } + + }; + }); + } +} diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..8fb4e5a --- /dev/null +++ b/config/config.php @@ -0,0 +1,5 @@ + DI\object('Piwik\Plugins\CustomiseTranslations\MyCustomLoader'), +); diff --git a/lang/de.json b/lang/de.json new file mode 100644 index 0000000..fd1aea4 --- /dev/null +++ b/lang/de.json @@ -0,0 +1,10 @@ +{ + "CustomiseTranslations": { + "MisingUnderscore": "Bitte formatieren sie den Key so: 'PluginName_TranslationKey'.", + "InvalidPlugin": "Das Plugin '%s' exisistiert nicht.", + "InvalidKey": "Der Übersetzungs-Key '%s' exisistiert nicht.", + "Description": "Sie können existierende Übersetzungen bearbeiten, indem sie den Key (e.g. 'PrivacyManager_TermsAndConditions') in die erste Spalte und den neuen Text in die zweite Spalte schreiben.", + "TranslationKey": "Übersetzungs-Key", + "Replacement": "Ersatztext" + } +} diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..ad16600 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,10 @@ +{ + "CustomiseTranslations": { + "MisingUnderscore": "Please format the Key like this: 'PluginName_TranslationKey'.", + "InvalidPlugin": "The plugin '%s' doesn't exist.", + "InvalidKey": "The tranlation key '%s' doesn't exist.", + "Description": "You can modify translations by entering the key (e.g. 'PrivacyManager_TermsAndConditions') into the first column and writing your replacement into the textbox.", + "TranslationKey": "Tranlation Key", + "Replacement": "Replacement" + } +} diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..f624ec8 --- /dev/null +++ b/plugin.json @@ -0,0 +1,28 @@ +{ + "name": "CustomiseTranslations", + "description": "This plugin allows you to modify all translateable strings in Matomo", + "version": "0.1.0", + "theme": false, + "require": { + "piwik": ">=3.6.0,<4.0.0-b1" + }, + "authors": [ + { + "name": "Lukas Winkler", + "email": "lukas@matomo.org", + "homepage": "https://lw1.at" + } + ], + "support": { + "email": "lukas@matomo.org", + "issues": "https://github.com/Findus23/plugin-LanguageToogle/issues", + "forum": "https://forum.matomo.org", + "source": "https://github.com/Findus23/plugin-LanguageToogle" + }, + "homepage": "https://lw1.at", + "license": "GPL v3+", + "keywords": [ + "language", + "customisation" + ] +} diff --git a/screenshots/.gitkeep b/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/screenshots/settings.png b/screenshots/settings.png new file mode 100644 index 0000000..9305db5 Binary files /dev/null and b/screenshots/settings.png differ diff --git a/stylesheets/styles.less b/stylesheets/styles.less new file mode 100644 index 0000000..1c7d406 --- /dev/null +++ b/stylesheets/styles.less @@ -0,0 +1,14 @@ +#CustomiseTranslationsPluginSettings { + .col { + width: 100%; + } + .input-field { + width: 100%; + } + textarea { + width: 100%; + } + .multiPairField .fieldUiControl1.hasMultiFields { + width: 400px; + } +}