diff --git a/src/mibew/libs/classes/Mibew/Controller/Localization/TranslationController.php b/src/mibew/libs/classes/Mibew/Controller/Localization/TranslationController.php
index 2c9ca536..78a5e238 100644
--- a/src/mibew/libs/classes/Mibew/Controller/Localization/TranslationController.php
+++ b/src/mibew/libs/classes/Mibew/Controller/Localization/TranslationController.php
@@ -17,6 +17,8 @@
namespace Mibew\Controller\Localization;
+use Mibew\Database;
+use Mibew\Http\Exception\NotFoundException;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -34,24 +36,13 @@ class TranslationController extends AbstractController
{
$operator = $this->getOperator();
- $source = $request->query->get('source');
- if (!preg_match("/^[\w-]{2,5}$/", $source)) {
- $source = DEFAULT_LOCALE;
- }
-
$target = $request->query->get('target');
if (!preg_match("/^[\w-]{2,5}$/", $target)) {
$target = CURRENT_LOCALE;
}
- $lang1 = load_messages($source);
- $lang2 = load_messages($target);
-
$page = array(
- 'lang1' => $source,
- 'lang2' => $target,
- 'title1' => $this->getLocaleName($source),
- 'title2' => $this->getLocaleName($target),
+ 'localeName' => $this->getLocaleName($target),
'errors' => array(),
);
@@ -63,53 +54,47 @@ class TranslationController extends AbstractController
}
// Prepare localization constants to display.
- $result = array();
- $all_keys = array_keys($lang1);
- foreach ($all_keys as $key) {
- $t_source = htmlspecialchars($lang1[$key]);
- if (isset($lang2[$key])) {
- $value = htmlspecialchars($lang2[$key]);
- } else {
- $value = "absent";
- }
- $result[] = array(
- 'id' => $key,
- 'l1' => $t_source,
- 'l2' => $value,
+ $strings = $this->loadStrings($target);
+ foreach ($strings as $key => $item) {
+ $strings[$key] = array(
+ 'id' => $item['stringid'],
+ 'source' => htmlentities($item['source']),
+ 'translation' => (empty($item['translation'])
+ ? "absent"
+ : htmlspecialchars($item['translation'])),
);
}
// Sort localization constants in the specified order.
$order = $request->query->get('sort');
- if (!in_array($order, array('id', 'l1'))) {
- $order = 'id';
+ if (!in_array($order, array('source', 'translation'))) {
+ $order = 'source';
}
- if ($order == 'id') {
+ if ($order == 'source') {
usort(
- $result,
+ $strings,
function ($a, $b) {
- return strcmp($a['id'], $b['id']);
+ return strcmp($a['source'], $b['source']);
}
);
- } elseif ($order == 'l1') {
+ } elseif ($order == 'translation') {
usort(
- $result,
+ $strings,
function ($a, $b) {
- return strcmp($a['l1'], $b['l1']);
+ return strcmp($a['translation'], $b['translation']);
}
);
}
- $pagination = setup_pagination($result, 100);
+ $pagination = setup_pagination($strings, 100);
$page['pagination'] = $pagination['info'];
$page['pagination.items'] = $pagination['items'];
$page['formtarget'] = $target;
- $page['formsource'] = $source;
$page['availableLocales'] = $locales_list;
$page['availableOrders'] = array(
- array('id' => 'id', 'name' => getlocal('Key identifier')),
- array('id' => 'l1', 'name' => getlocal('Source language string')),
+ array('id' => 'source', 'name' => getlocal('Source string')),
+ array('id' => 'translation', 'name' => getlocal('Translation')),
);
$page['formsort'] = $order;
$page['title'] = getlocal('Translations');
@@ -132,41 +117,27 @@ class TranslationController extends AbstractController
$operator = $this->getOperator();
$string_id = $request->attributes->get('string_id');
-
- $source = $request->query->get('source');
- if (!preg_match("/^[\w-]{2,5}$/", $source)) {
- $source = DEFAULT_LOCALE;
+ $string = $this->loadString($string_id);
+ if (!$string) {
+ throw new NotFoundException('The string is not found.');
}
- $target = $request->query->has('target')
- ? $request->query->get('target')
- : $request->request->get('target');
- if (!preg_match("/^[\w-]{2,5}$/", $target)) {
- $target = CURRENT_LOCALE;
- }
-
- $lang1 = load_messages($source);
- $lang2 = load_messages($target);
+ $target = $string['locale'];
$page = array(
- 'title1' => $this->getLocaleName($source),
- 'title2' => $this->getLocaleName($target),
+ 'localeName' => $this->getLocaleName($target),
// Use errors list stored in the request. We need to do so to have
// an ability to pass the request from the "submitEditForm" action.
'errors' => $request->attributes->get('errors', array()),
);
-
- $translation = isset($lang2[$string_id]) ? $lang2[$string_id] : '';
// Override translation value from the request if needed.
- if ($request->request->has('translation')) {
- $translation = $request->request->get('translation');
- }
+ $translation = $request->request->get('translation', $string['translation']);
$page['saved'] = false;
$page['key'] = $string_id;
$page['target'] = $target;
- $page['formoriginal'] = isset($lang1[$string_id]) ? $lang1[$string_id] : '