Skip to content

Commit 81b4936

Browse files
authored
Merge pull request #2 from suntorytimed/separate_translation_file
Fix disclaimer translation
2 parents 1394744 + 90e4f0b commit 81b4936

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

templates/disclaimer.html

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,8 @@ <h2 data-i18n="termsOfUseTitle"></h2>
5353

5454
<script src="/static/translations.js"></script>
5555
<script>
56-
var timeoutMinutes = {{ timeout_minutes }};
57-
58-
document.addEventListener('DOMContentLoaded', function() {
59-
var elements = document.querySelectorAll('[data-i18n="dataStorageText"]');
60-
elements.forEach(function(element) {
61-
var key = element.getAttribute('data-i18n');
62-
var lang = i18n.getCurrentLanguage();
63-
if (translations[lang] && translations[lang][key]) {
64-
var text = translations[lang][key];
65-
text = text.replace('{{ timeout_minutes }}', timeoutMinutes);
66-
element.textContent = text;
67-
}
68-
});
69-
});
56+
window.timeoutMinutes = {{ timeout_minutes }};
7057
</script>
58+
<script src="/static/translations.js"></script>
7159
</body>
7260
</html>

templates/progress.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h2><span data-i18n="status"></span>: <span id="status-text" data-i18n="statusRu
121121

122122
if (reconnectAttempt > 1) {
123123
document.getElementById('status-message').textContent =
124-
`${i18n.translate('connectionLost')} (${i18n.translate('statusSearching')}...)`;
124+
`${i18n.translate('connectionLost')} (${i18n.translate('statusReconnecting')}...)`;
125125
}
126126

127127
eventSource = new EventSource(`/progress/${jobId}`);
@@ -207,7 +207,7 @@ <h2><span data-i18n="status"></span>: <span id="status-text" data-i18n="statusRu
207207
function manualReconnect() {
208208
const statusText = document.getElementById('status-text');
209209
const statusMessage = document.getElementById('status-message');
210-
statusText.textContent = i18n.translate('statusSearching');
210+
statusText.textContent = i18n.translate('statusReconnecting');
211211
statusMessage.textContent = i18n.translate('reconnecting');
212212

213213
reconnectAttempt = 0;

templates/translations.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const translations = {
5757
statusCompleted: "Abgeschlossen",
5858
statusFailed: "Fehlgeschlagen",
5959
statusLostConnection: "Verbindung verloren",
60-
statusSearching: "Suche nach PDF...",
60+
statusReconnecting: "Stelle Verbindung wieder her...",
6161
statusInProgress: "In Bearbeitung",
6262
tooltip: "Wenn der Status nicht korrekt angezeigt wird, kann es sein, dass die Konvertierung trotzdem im Hintergrund läuft. Bitte warten Sie einige Minuten und klicken Sie dann auf \"Verbindung wiederherstellen\".",
6363
startingConversion: "Starte Konvertierung...",
@@ -151,7 +151,7 @@ const translations = {
151151
statusCompleted: "Completed",
152152
statusFailed: "Failed",
153153
statusLostConnection: "Connection lost",
154-
statusSearching: "Searching for PDF...",
154+
statusReconnecting: "Reconnecting...",
155155
statusInProgress: "In progress",
156156
tooltip: "If the status is not displayed correctly, the conversion may still be running in the background. Please wait a few minutes and then click \"Reconnect\".",
157157
startingConversion: "Starting conversion...",
@@ -214,21 +214,31 @@ const i18n = {
214214
return translations[lang] && translations[lang][key] ?
215215
translations[lang][key] : key;
216216
},
217+
218+
replacePlaceholders: function(text) {
219+
if (typeof window.timeoutMinutes !== 'undefined') {
220+
text = text.replace(/\{\{\s*timeout_minutes\s*\}\}/g, window.timeoutMinutes);
221+
}
222+
223+
return text;
224+
},
217225

218226
updatePageContent: function() {
219227
const lang = this.getCurrentLanguage();
220228

221229
document.querySelectorAll('[data-i18n]').forEach(element => {
222230
const key = element.getAttribute('data-i18n');
223231
if (translations[lang] && translations[lang][key]) {
232+
let text = translations[lang][key];
233+
text = this.replacePlaceholders(text);
224234
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
225235
if (element.type !== 'checkbox' && element.type !== 'radio') {
226-
element.placeholder = translations[lang][key];
236+
element.placeholder = text;
227237
}
228238
} else if (element.tagName === 'OPTION') {
229-
element.text = translations[lang][key];
239+
element.text = text;
230240
} else {
231-
element.textContent = translations[lang][key];
241+
element.textContent = text;
232242
}
233243
}
234244
});

0 commit comments

Comments
 (0)