-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fc8da9c
Showing
11 changed files
with
549 additions
and
0 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,2 @@ | ||
YTraduko | ||
======== |
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,62 @@ | ||
<?php /** @var rex_fragment $this */ ?> | ||
<form action="<?= $this->context->getUrl() ?>" method="post"> | ||
<section class="rex-page-section"> | ||
<div class="panel panel-default"> | ||
<div class="panel-body"> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th style="width: 50px"><?= $this->i18n('ytraduko_key') ?></th> | ||
<th style="width: 400px">de_de</th> | ||
<th><?= $this->escape($this->language) ?></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php $file = $this->package->getFile($this->language) ?> | ||
<?php foreach ($this->package->getSource() as $key => $value): ?> | ||
<tr> | ||
<td><code><?= $this->escape($key) ?></code></td> | ||
<td><?= $this->escape($value) ?></td> | ||
<td<?= isset($file[$key]) ? '' : ' class="has-error"' ?>> | ||
<input type="text" class="form-control" | ||
name="ytraduko[<?= $this->escape($this->package->getName()) ?>][<?= $this->escape($key) ?>]" | ||
value="<?= isset($file[$key]) ? $this->escape($file[$key]) : '' ?>" | ||
/> | ||
</td> | ||
</tr> | ||
<?php endforeach ?> | ||
<?php if ($this->package instanceof rex_ytraduko_addon): ?> | ||
<?php foreach ($this->package->getPlugins() as $plugin): ?> | ||
<tr> | ||
<th colspan="3"><?= $this->escape($plugin->getName()) ?></th> | ||
</tr> | ||
<?php $file = $plugin->getFile($this->language) ?> | ||
<?php foreach ($plugin->getSource() as $key => $value): ?> | ||
<tr> | ||
<td><code><?= $this->escape($key) ?></code></td> | ||
<td><?= $this->escape($value) ?></td> | ||
<td<?= isset($file[$key]) ? '' : ' class="has-error"' ?>> | ||
<input type="text" class="form-control" | ||
name="ytraduko[<?= $this->escape($plugin->getName()) ?>][<?= $this->escape($key) ?>]" | ||
value="<?= isset($file[$key]) ? $this->escape($file[$key]) : '' ?>" | ||
/> | ||
</td> | ||
</tr> | ||
<?php endforeach ?> | ||
<?php endforeach ?> | ||
<?php endif ?> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div class="panel-footer"> | ||
<div class="rex-form-panel-footer"> | ||
<div class="btn-toolbar"> | ||
<button class="btn btn-save rex-form-aligned pull-right" type="submit"<?= rex::getAccesskey($this->i18n('form_save'), 'save') ?>> | ||
<?= $this->i18n('form_save') ?> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</form> |
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,56 @@ | ||
<?php /** @var rex_fragment $this */ ?> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th class="rex-table-icon"> </th> | ||
<th style="width: 200px"><?= rex_i18n::msg('package_hname') ?></th> | ||
<th style="width: 100px"><?= rex_i18n::msg('package_hversion') ?></th> | ||
<th style="width: 100px" class="text-center">de_de</th> | ||
<?php foreach ($this->languages as $language): ?> | ||
<th class="text-center"><?= $this->escape($language) ?></th> | ||
<?php endforeach ?> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($this->packages as $package): /** @var rex_ytraduko_package $package */ ?> | ||
<tr> | ||
<td class="rex-table-icon"><i class="rex-icon rex-icon-package-addon"></i></td> | ||
<td><?= $this->escape($package->getName()) ?></td> | ||
<td><?= $this->escape($package->getVersion()) ?></td> | ||
<td class="text-center"><?= $package->countKeys() ?></td> | ||
<?php foreach ($this->languages as $language): ?> | ||
<?php $percentage = (int) (100 * $package->countLanguageKeys($language) / $package->countKeys()); ?> | ||
<td class="text-center"> | ||
<a href="<?= $this->context->getUrl(['language' => $language, 'package' => $package->getName()]) ?>"> | ||
<div class="progress" style="margin-bottom: 0"> | ||
<div class="progress-bar progress-bar-success" style="width: <?= $percentage ?>%"> | ||
<?= $percentage ?> % | ||
</div> | ||
<div class="progress-bar progress-bar-danger" style="width: <?= 100 - $percentage ?>%"></div> | ||
</div> | ||
</a> | ||
</td> | ||
<?php endforeach ?> | ||
</tr> | ||
<?php endforeach ?> | ||
</tbody> | ||
<tfoot> | ||
<tr style="background-color: #dfe3e9"> | ||
<td class="rex-table-icon"></td> | ||
<td><b><?= mb_strtoupper($this->i18n('ytraduko_total')) ?></b></td> | ||
<td></td> | ||
<td class="text-center"><b><?= $this->total['de_de'] ?></b></td> | ||
<?php foreach ($this->languages as $language): ?> | ||
<?php $percentage = (int) (100 * $this->total[$language] / $this->total['de_de']); ?> | ||
<td class="text-center"> | ||
<div class="progress" style="margin-bottom: 0"> | ||
<div class="progress-bar progress-bar-success" style="width: <?= $percentage ?>%"> | ||
<?= $percentage ?> % | ||
</div> | ||
<div class="progress-bar progress-bar-danger" style="width: <?= 100 - $percentage ?>%"></div> | ||
</div> | ||
</td> | ||
<?php endforeach ?> | ||
</tr> | ||
</tfoot> | ||
</table> |
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,44 @@ | ||
<?php /** @var rex_fragment $this */ ?> | ||
<ul class="nav navbar-nav"> | ||
<li> | ||
<a href="<?= $this->context->getUrl(['language' => null, 'package' => null]) ?>"> | ||
<?= $this->i18n('ytraduko_overview') ?> | ||
</a> | ||
</li> | ||
<li class="dropdown"> | ||
<?php | ||
$items = array_map(function (rex_ytraduko_package $package) { | ||
return [ | ||
'title' => $this->escape($package->getName()), | ||
'href' => $this->context->getUrl(['package' => $package->getName()]), | ||
'active' => $this->package === $package, | ||
]; | ||
}, $this->packages); | ||
|
||
$this->subfragment('core/dropdowns/dropdown.php', [ | ||
'toolbar' => true, | ||
'button_prefix' => $this->i18n('ytraduko_package').': ', | ||
'button_label' => $this->escape($this->package->getName()), | ||
'items' => $items, | ||
]); | ||
?> | ||
</li> | ||
<li class="dropdown"> | ||
<?php | ||
$items = array_map(function ($language) { | ||
return [ | ||
'title' => $this->escape($language), | ||
'href' => $this->context->getUrl(['language' => $language]), | ||
'active' => $this->language === $language, | ||
]; | ||
}, $this->languages); | ||
|
||
$this->subfragment('core/dropdowns/dropdown.php', [ | ||
'toolbar' => true, | ||
'button_prefix' => $this->i18n('ytraduko_language').': ', | ||
'button_label' => $this->escape($this->language), | ||
'items' => $items, | ||
]); | ||
?> | ||
</li> | ||
</ul> |
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,8 @@ | ||
ytraduko_overview = Übersicht | ||
|
||
ytraduko_package = Paket | ||
ytraduko_language = Sprache | ||
|
||
ytraduko_key = Schlüssel | ||
|
||
ytraduko_total = Gesamt |
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,58 @@ | ||
<?php | ||
|
||
class rex_ytraduko_addon extends rex_ytraduko_package | ||
{ | ||
/** @var rex_ytraduko_package[] */ | ||
private $plugins; | ||
|
||
/** | ||
* @param rex_addon $addon | ||
* | ||
* @return null|self | ||
*/ | ||
public static function create(rex_addon $addon) | ||
{ | ||
$countKeys = 0; | ||
$plugins = []; | ||
|
||
foreach ($addon->getRegisteredPlugins() as $plugin) { | ||
if (file_exists($plugin->getPath('lang/de_de.lang'))) { | ||
$package = new rex_ytraduko_package($plugin->getName(), $plugin->getVersion(), $plugin->getPath('lang')); | ||
if ($package->countKeys()) { | ||
$plugins[] = $package; | ||
$countKeys += $package->countKeys(); | ||
} | ||
} | ||
} | ||
|
||
if ($plugins || file_exists($addon->getPath('lang/de_de.lang'))) { | ||
$addon = new self($addon->getName(), $addon->getVersion(), $addon->getPath('lang')); | ||
$addon->plugins = $plugins; | ||
$addon->countKeys += $countKeys; | ||
if ($addon->countKeys()) { | ||
return $addon; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @return rex_ytraduko_package[] | ||
*/ | ||
public function getPlugins() | ||
{ | ||
return $this->plugins; | ||
} | ||
|
||
public function countLanguageKeys($language) | ||
{ | ||
$count = parent::countLanguageKeys($language); | ||
|
||
foreach ($this->plugins as $plugin) { | ||
$count += $plugin->countLanguageKeys($language); | ||
} | ||
|
||
return $count; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
class rex_ytraduko_file extends ArrayObject | ||
{ | ||
private $path; | ||
|
||
public function __construct($path) | ||
{ | ||
$this->path = $path; | ||
|
||
if (file_exists($path)) { | ||
$this->load(); | ||
} | ||
} | ||
|
||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
private function load() | ||
{ | ||
if ( | ||
($content = rex_file::get($this->path)) && | ||
preg_match_all('/^([^\s]*)\h*=\h*(\V*\S?)\h*$/m', $content, $matches, PREG_SET_ORDER) | ||
) { | ||
foreach ($matches as $match) { | ||
if ($match[2]) { | ||
$this[$match[1]] = $match[2]; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,105 @@ | ||
<?php | ||
|
||
class rex_ytraduko_package | ||
{ | ||
protected $name; | ||
protected $version; | ||
protected $path; | ||
|
||
/** @var rex_ytraduko_file */ | ||
protected $source; | ||
|
||
protected $countKeys; | ||
|
||
/** @var rex_ytraduko_file[] */ | ||
protected $files; | ||
|
||
protected function __construct($name, $version, $path) | ||
{ | ||
$this->name = $name; | ||
$this->version = $version; | ||
$this->path = $path; | ||
|
||
$this->source = new rex_ytraduko_file($path.'/de_de.lang'); | ||
$this->countKeys = count($this->source); | ||
} | ||
|
||
/** | ||
* @return self[] | ||
*/ | ||
public static function getAll() | ||
{ | ||
$all = []; | ||
$all['core'] = new self('core', rex::getVersion(), rex_path::core('lang')); | ||
|
||
$ignore = rex_addon::get('ytraduko')->getProperty('config')['packages_ignore']; | ||
|
||
foreach (rex_addon::getRegisteredAddons() as $addon) { | ||
if (in_array($addon->getName(), $ignore)) { | ||
continue; | ||
} | ||
|
||
$addon = rex_ytraduko_addon::create($addon); | ||
if ($addon) { | ||
$all[$addon->getName()] = $addon; | ||
} | ||
} | ||
|
||
return $all; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getVersion() | ||
{ | ||
return $this->version; | ||
} | ||
|
||
public function getSource() | ||
{ | ||
return $this->source; | ||
} | ||
|
||
public function countKeys() | ||
{ | ||
return $this->countKeys; | ||
} | ||
|
||
public function countLanguageKeys($language) | ||
{ | ||
return count($this->getFile($language)); | ||
} | ||
|
||
/** | ||
* @param string $language | ||
* | ||
* @return rex_ytraduko_file | ||
*/ | ||
public function getFile($language) | ||
{ | ||
if (!isset($this->files[$language])) { | ||
$this->files[$language] = new rex_ytraduko_file($this->path.'/'.$language.'.lang'); | ||
} | ||
|
||
return $this->files[$language]; | ||
} | ||
|
||
public function save($language) | ||
{ | ||
$content = rex_file::get($this->source->getPath()); | ||
$file = $this->getFile($language); | ||
|
||
foreach ($file as $key => $value) { | ||
$content = preg_replace( | ||
'/^('.preg_quote($key, '/').'\h*=\h*)(\V*\S)?\h*$/m', | ||
rtrim('${1}'.$value), | ||
$content | ||
); | ||
} | ||
|
||
rex_file::put($file->getPath(), $content); | ||
} | ||
} |
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,16 @@ | ||
package: ytraduko | ||
version: '0.1-dev' | ||
author: Gregor Harlan | ||
supportpage: www.redaxo.org/de/forum/ | ||
|
||
page: | ||
title: YTraduko | ||
icon: rex-icon fa-language | ||
perm: ytraduko[] | ||
|
||
requires: | ||
redaxo: '^5.3.0' | ||
|
||
config: | ||
languages: [en_gb, se_sv] | ||
packages_ignore: [debug, textile] |
Oops, something went wrong.