Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to edit meaning in WebUI #399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

### 1.3.1 to UNRELEASED
* Allow to edit Meaning field in WebUI

### 1.3.0 to 1.3.1

Expand Down
3 changes: 2 additions & 1 deletion Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function updateMessageAction(Request $request, $config, $domain, $locale)

$this->updater->updateTranslation(
$file, $format, $domain, $locale, $id,
$request->request->get('message')
$request->request->get('message'),
$request->request->get('meaning')
);

return new Response('Translation was saved');
Expand Down
16 changes: 9 additions & 7 deletions Resources/public/js/jms.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function JMSTranslationManager(updateMessagePath, isWritable)

if (data == 'Translation was saved')
{
$elem.parent().closest('td').prev('td').append(JMS.translation.ajax.savedMessageContent);
$elem.closest('tr').find('.notice').append(JMS.translation.ajax.savedMessageContent);
} else
{
$elem.parent().closest('td').prev('td').append(JMS.translation.ajax.unsavedMessageContent);
$elem.closest('tr').find('.notice').append(JMS.translation.ajax.unsavedMessageContent);
}
},
savedMessageContent: '<span class="alert-message label success">Translation was saved.</span>',
Expand All @@ -120,7 +120,7 @@ function JMSTranslationManager(updateMessagePath, isWritable)
$elem.data('timeoutId', setTimeout(function ()
{
$elem.data('timeoutId', undefined);
$parent.closest('td').prev('td').children('.alert-message').fadeOut(300, function ()
$parent.closest('tr').find('.alert-message').fadeOut(300, function ()
{
var $message = $(this);
$message.remove();
Expand All @@ -130,11 +130,13 @@ function JMSTranslationManager(updateMessagePath, isWritable)
},
blur: function(event, JMS)
{
var $elem = $(event.target);
$.ajax(JMS.updateMessagePath + '?id=' + encodeURIComponent($elem.data('id')), {
var $row = $(event.target).closest('tr');
var $meaning = $row.find('.meaning');
var $message = $row.find('.message');
$.ajax(JMS.updateMessagePath + '?id=' + encodeURIComponent($message.data('id')), {
type: JMS.translation.ajax.type,
headers: JMS.translation.ajax.headers,
data: {'_method': JMS.translation.ajax.dataMethod, 'message': $elem.val()},
data: {'_method': JMS.translation.ajax.dataMethod, 'message': $message.val(), 'meaning': $meaning.val()},
beforeSend: function (data)
{
JMS.translation.ajax.beforeSend(data, event, JMS);
Expand Down Expand Up @@ -165,7 +167,7 @@ function JMSTranslationManager(updateMessagePath, isWritable)
$elem.data('timeoutId', undefined);
}

$elem.parent().children('.alert-message').remove();
$elem.closest('tr').find('.alert-message').remove();
}
};

Expand Down
11 changes: 5 additions & 6 deletions Resources/views/Translate/messages.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
<p><abbr title="{{ id }}">{{ id|slice(0, 25) }}{% if id|length > 25 %}...{% endif %}</abbr></p>
</td>
<td>
<textarea data-id="{{ id }}" class="span6"{% if isWriteable is sameas(false) %} readonly="readonly"{% endif %}>{{ message.localeString }}</textarea></td>
<textarea data-id="{{ id }}" class="span6 message"{% if isWriteable is sameas(false) %} readonly="readonly"{% endif %}>{{ message.localeString }}</textarea>
<div class="notice"></div>
</td>
<td>
{% if message.meaning is not empty %}
<h6>Meaning</h6>
<p>{{ message.meaning }}</p>
{% endif %}

<h6>Meaning</h6>
<textarea class="span6 meaning" rows="3"{% if isWriteable is sameas(false) %} readonly="readonly"{% endif %}>{{ message.meaning }}</textarea>
{% if alternativeMessages[id] is defined %}
<h6>Alternative Translations</h6>
{% for locale, altMessage in alternativeMessages[id] %}
Expand Down
4 changes: 3 additions & 1 deletion Translation/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ public function getChangeSet(Config $config)
* @param string $locale
* @param string $id
* @param string $trans
* @param string $meaning
*/
public function updateTranslation($file, $format, $domain, $locale, $id, $trans)
public function updateTranslation($file, $format, $domain, $locale, $id, $trans, $meaning)
{
$catalogue = $this->loader->loadFile($file, $format, $locale, $domain);
$catalogue
->get($id, $domain)
->setLocaleString($trans)
->setMeaning($meaning)
->setNew(false)
;

Expand Down