Skip to content

Commit 565fdba

Browse files
committed
allow to save fallback translation as default
1 parent c5ab0bc commit 565fdba

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Controller/SymfonyProfilerController.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,21 @@ public function editAction(Request $request, string $token): Response
6464
$translation = $this->storage->syncAndFetchMessage($message->getLocale(), $message->getDomain(), $message->getKey());
6565

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

7172
return new Response($content);
7273
}
7374

7475
// Assert: This is a POST request
76+
if ('save_for_default' === $request->request->get('action')) {
77+
$requestCollector = $this->getProfiler()->loadProfile($token)->getCollector('translation');
78+
if ($requestCollector instanceof TranslationDataCollector) {
79+
$message->setLocale($requestCollector->getLocale());
80+
}
81+
}
7582
$message->setTranslation((string) $request->request->get('translation'));
7683
$this->storage->update($message->convertToMessage());
7784

Resources/public/js/symfonyProfiler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ function getEditForm(key) {
6969
});
7070
}
7171

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

7676
fetch(translationEditUrl, {
7777
method: 'POST',
78-
body: serializeQueryString({message_id: key, translation:translation}),
78+
body: serializeQueryString(Object.assign({message_id: key, translation:translation}, additionalData)),
7979
headers: {
8080
'X-Requested-With': 'XMLHttpRequest',
8181
'Content-Type': 'application/x-www-form-urlencoded',
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
<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>
2-
<input type="button" class="btn btn-sm" value="Save" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value)'>
3-
<input type="button" class="btn btn-sm" value="Cancel" onclick='cancelEditForm("{{ key }}", "{{ message.translation }}")'>
1+
<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>
2+
{% if message.state == constant('Symfony\\Component\\Translation\\DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK') %}
3+
<input type="button" class="btn btn-sm" value="Save Fallback" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value)'>
4+
<input type="button" class="btn btn-sm" value="Save Default" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value, {action: "save_for_default"})'>
5+
{% else %}
6+
<input type="button" class="btn btn-sm" value="Save" onclick='saveEditForm("{{ key }}", document.getElementById("edit_{{ key }}").value)'>
7+
{% endif %}
8+
<input type="button" class="btn btn-sm" value="Cancel" onclick='cancelEditForm("{{ key }}", "{{ translation.translation }}")'>

0 commit comments

Comments
 (0)