Skip to content
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
9 changes: 8 additions & 1 deletion Controller/SymfonyProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ public function editAction(Request $request, string $token): Response
$translation = $this->storage->syncAndFetchMessage($message->getLocale(), $message->getDomain(), $message->getKey());

$content = $this->twig->render('@Translation/SymfonyProfiler/edit.html.twig', [
'message' => $translation,
'translation' => $translation,
'message' => $message,
'key' => $request->query->get('message_id'),
]);

return new Response($content);
}

// Assert: This is a POST request
if ('save_for_default' === $request->request->get('action')) {
$requestCollector = $this->getProfiler()->loadProfile($token)->getCollector('translation');
if ($requestCollector instanceof TranslationDataCollector) {
$message->setLocale($requestCollector->getLocale());
}
}
$message->setTranslation((string) $request->request->get('translation'));
$this->storage->update($message->convertToMessage());

Expand Down
4 changes: 2 additions & 2 deletions Resources/public/js/symfonyProfiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ function getEditForm(key) {
});
}

function saveEditForm(key, translation) {
function saveEditForm(key, translation, additionalData = {}) {
var el = document.getElementById(key).getElementsByClassName("translation");
el[0].innerHTML = getLoaderHTML();

fetch(translationEditUrl, {
method: 'POST',
body: serializeQueryString({message_id: key, translation:translation}),
body: serializeQueryString(Object.assign({message_id: key, translation:translation}, additionalData)),
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down
11 changes: 8 additions & 3 deletions Resources/views/SymfonyProfiler/edit.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<textarea style="width: 100%; border: 1px solid var(--metric-border-color); padding: 4px; margin-bottom: 5px; border-radius: 6px; background-color: var(--metric-value-background); color: var(--color-text)" id="edit_{{ key }}">{{ message.translation }}</textarea>
<input type="button" class="btn btn-sm" value="Save" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value)'>
<input type="button" class="btn btn-sm" value="Cancel" onclick='cancelEditForm("{{ key }}", "{{ message.translation }}")'>
<textarea style="width: 100%; border: 1px solid var(--metric-border-color); padding: 4px; margin-bottom: 5px; border-radius: 6px; background-color: var(--metric-value-background); color: var(--color-text)" id="edit_{{ key }}">{{ translation.translation }}</textarea>
{% if message.state == constant('Symfony\\Component\\Translation\\DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK') %}
<input type="button" class="btn btn-sm" value="Save Fallback" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value)'>
<input type="button" class="btn btn-sm" value="Save Default" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value, {action: "save_for_default"})'>
{% else %}
<input type="button" class="btn btn-sm" value="Save" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value)'>
{% endif %}
<input type="button" class="btn btn-sm" value="Cancel" onclick='cancelEditForm("{{ key }}", "{{ translation.translation }}")'>
Loading