1
0
Fork 0
mirror of https://github.com/Findus23/plugin-CustomiseTranslations.git synced 2024-09-18 14:43:50 +02:00

initial version

This commit is contained in:
Lukas Winkler 2018-10-26 21:26:24 +02:00
commit 7f8aa5be4a
Signed by: lukas
GPG key ID: 54DE4D798D244853
12 changed files with 181 additions and 0 deletions

3
CHANGELOG.md Normal file
View file

@ -0,0 +1,3 @@
## Changelog
Here goes the changelog text.

22
CustomiseTranslations.php Normal file
View file

@ -0,0 +1,22 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CustomiseTranslations;
class CustomiseTranslations extends \Piwik\Plugin
{
public function registerEvents() {
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
);
}
public function getStylesheetFiles(&$files) {
$files[] = "plugins/CustomiseTranslations/stylesheets/styles.less";
}
}

26
MyCustomLoader.php Normal file
View file

@ -0,0 +1,26 @@
<?php
namespace Piwik\Plugins\CustomiseTranslations;
use Piwik\Translation\Loader\JsonFileLoader;
class MyCustomLoader extends JsonFileLoader
{
public function load($language, array $directories) {
$translations = parent::load($language, $directories);
$settings = new SystemSettings();
$trans = $settings->tranlations->getValue();
foreach ($trans as $translation) {
if ($translation["translationKey"] == "") {
continue;
}
$split = explode("_", $translation["translationKey"]);
$translations[$split[0]][$split[1]] = $translation["translationText"];
}
return $translations;
}
}

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# Matomo Customise Translations
## Description
This plugin allows you to quickly replace translatable texts in Matomo.

58
SystemSettings.php Normal file
View file

@ -0,0 +1,58 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CustomiseTranslations;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
use Piwik\Settings\FieldConfig;
use Piwik\Settings\Setting;
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @var Setting */
public $tranlations;
protected function init() {
$this->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));
}
}
};
});
}
}

5
config/config.php Normal file
View file

@ -0,0 +1,5 @@
<?php
return array(
'Piwik\Translation\Loader\JsonFileLoader' => DI\object('Piwik\Plugins\CustomiseTranslations\MyCustomLoader'),
);

10
lang/de.json Normal file
View file

@ -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"
}
}

10
lang/en.json Normal file
View file

@ -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"
}
}

28
plugin.json Normal file
View file

@ -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"
]
}

0
screenshots/.gitkeep Normal file
View file

BIN
screenshots/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

14
stylesheets/styles.less Normal file
View file

@ -0,0 +1,14 @@
#CustomiseTranslationsPluginSettings {
.col {
width: 100%;
}
.input-field {
width: 100%;
}
textarea {
width: 100%;
}
.multiPairField .fieldUiControl1.hasMultiFields {
width: 400px;
}
}