Skip to content

Commit b75de53

Browse files
authored
Merge pull request #36 from itk-dev/feature/js-translation-placeholders
Handled placeholders in JS translations
2 parents cac0222 + 708000b commit b75de53

File tree

8 files changed

+183
-27
lines changed

8 files changed

+183
-27
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
* [PR-36](https://github.com/itk-dev/rpa-process-overview/pull/36)
11+
* Handled placeholders in JS translations
12+
* Updated translations
1013
* [PR-33](https://github.com/itk-dev/rpa-process-overview/pull/33)
1114
* Add popover with more info and rerun option
1215
* [PR-31](https://github.com/itk-dev/rpa-process-overview/pull/31)

src/Controller/ProcessOverviewController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ public function show(ProcessOverviewGroup $group, ProcessOverview $overview): Re
3636
]),
3737
'messages' => array_map('strval', [
3838
'Go to previous page' => strval(t('Go to previous page')),
39-
'Go to page' => t('Go to page'),
39+
'Go to page {page}' => t('Go to page {page}'),
4040
'Go to next page' => t('Go to next page'),
4141
'Missing data' => t('Missing data'),
4242
'Failed processes' => t('Failed processes'),
4343
'The process was restarted' => t('The process was restarted'),
44-
'An error occurred when the process was restarted' => t('An error occurred when the process was restarted'),
44+
'An error occurred when trying to restart the process' => t('An error occurred when trying to restart the process'),
4545
'Rerun step' => t('Rerun step'),
46-
'Finished at' => t('Finished at'),
47-
'Failed at' => t('Failed at'),
48-
'Error code' => t('Error code'),
49-
'Loading data...' => t('Loading data...'),
50-
'of' => t('of'),
46+
'Finished at {finishedAt}' => t('Finished at {finishedAt}'),
47+
'Failed {failedAt} at' => t('Failed at {failedAt}'),
48+
'Error code: {code}' => t('Error code: {code}'),
49+
'Loading data' => t('Loading data'),
50+
'Showing {from}–{to} of {total}' => t('Showing {from}–{to} of {total}'),
5151
'An error occurred while fetching the data' => t('An error occurred while fetching the data'),
5252
]),
5353
'page_size' => $overviewOptions['data']['page_size'] ?? 5,

translations/messages+intl-icu.da.xlf

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
<source>Options</source>
5454
<target state="translated">Indstillinger</target>
5555
</trans-unit>
56-
<trans-unit id="rjoPh2q" resname="RPA Process Overview">
57-
<source>RPA Process Overview</source>
58-
<target state="translated">RPA-procesoverblik</target>
59-
</trans-unit>
6056
<trans-unit id="ExFLJqx" resname="Home">
6157
<source>Home</source>
6258
<target state="translated">Hjem</target>
@@ -129,6 +125,82 @@
129125
<source>Process ({label})</source>
130126
<target state="translated">Proces ({label})</target>
131127
</trans-unit>
128+
<trans-unit id="P9_Y7yU" resname="Created by">
129+
<source>Created by</source>
130+
<target state="translated">Oprettet af</target>
131+
</trans-unit>
132+
<trans-unit id="LVVWz4T" resname="Created at">
133+
<source>Created at</source>
134+
<target state="translated">Oprettet</target>
135+
</trans-unit>
136+
<trans-unit id="ZHIlC6b" resname="Go to previous page">
137+
<source>Go to previous page</source>
138+
<target state="translated">Gå til forrige side</target>
139+
</trans-unit>
140+
<trans-unit id="YiuzkhO" resname="Go to next page">
141+
<source>Go to next page</source>
142+
<target state="translated">Gå til næste side</target>
143+
</trans-unit>
144+
<trans-unit id="ICfdxrk" resname="Missing data">
145+
<source>Missing data</source>
146+
<target state="translated">Manglende data</target>
147+
</trans-unit>
148+
<trans-unit id="SGmWohz" resname="Failed processes">
149+
<source>Failed processes</source>
150+
<target state="translated">Fejlede processer</target>
151+
</trans-unit>
152+
<trans-unit id="QOhsBcU" resname="An error occurred while fetching the data">
153+
<source>An error occurred while fetching the data</source>
154+
<target state="translated">Fejl under indlæsning af data</target>
155+
</trans-unit>
156+
<trans-unit id="eF09fJD" resname="Citizen search">
157+
<source>Citizen search</source>
158+
<target state="translated">__Citizen search</target>
159+
</trans-unit>
160+
<trans-unit id="tx702.d" resname="Citizen information">
161+
<source>Citizen information</source>
162+
<target state="translated">Borgerinformation</target>
163+
</trans-unit>
164+
<trans-unit id="XPwqrmY" resname="An error occurred while searching">
165+
<source>An error occurred while searching</source>
166+
<target state="translated">Fejl ved søgning</target>
167+
</trans-unit>
168+
<trans-unit id="M.iCN3v" resname="Go to page {page}">
169+
<source>Go to page {page}</source>
170+
<target state="translated">Gå til side {page}</target>
171+
</trans-unit>
172+
<trans-unit id="KXqovG." resname="Loading data …">
173+
<source>Loading data …</source>
174+
<target state="translated">Henter data …</target>
175+
</trans-unit>
176+
<trans-unit id="iMqbR_1" resname="Showing {from}–{to} of {total}">
177+
<source>Showing {from}–{to} of {total}</source>
178+
<target state="translated">Viser {from}–{to} of {total}</target>
179+
</trans-unit>
180+
<trans-unit id="rogeeu2" resname="The process was restarted">
181+
<source>The process was restarted</source>
182+
<target state="translated">Processen blev genstartet</target>
183+
</trans-unit>
184+
<trans-unit id="U5QT.Nm" resname="An error occurred when trying to restart the process">
185+
<source>An error occurred when trying to restart the process</source>
186+
<target state="translated">Fejl under forsøg på at genstarte proces</target>
187+
</trans-unit>
188+
<trans-unit id="tIp4N7k" resname="Rerun step">
189+
<source>Rerun step</source>
190+
<target state="translated">Genstart proces</target>
191+
</trans-unit>
192+
<trans-unit id="wmAX68g" resname="Finished at {finishedAt}">
193+
<source>Finished at {finishedAt}</source>
194+
<target state="translated">Afsluttet {finishedAt}</target>
195+
</trans-unit>
196+
<trans-unit id="jmp.PI_" resname="Failed at {failedAt}">
197+
<source>Failed at {failedAt}</source>
198+
<target state="translated">Fejlet {failedAt}</target>
199+
</trans-unit>
200+
<trans-unit id="cyzVmW2" resname="Error code: {code}">
201+
<source>Error code: {code}</source>
202+
<target state="translated">Fejlkode: {code}</target>
203+
</trans-unit>
132204
</body>
133205
</file>
134206
</xliff>

translations/messages+intl-icu.en.xlf

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
<source>Options</source>
5454
<target>Options</target>
5555
</trans-unit>
56-
<trans-unit id="rjoPh2q" resname="RPA Process Overview">
57-
<source>RPA Process Overview</source>
58-
<target>RPA Process Overview</target>
59-
</trans-unit>
6056
<trans-unit id="ExFLJqx" resname="Home">
6157
<source>Home</source>
6258
<target>Home</target>
@@ -129,6 +125,82 @@
129125
<source>Process ({label})</source>
130126
<target>Process ({label})</target>
131127
</trans-unit>
128+
<trans-unit id="P9_Y7yU" resname="Created by">
129+
<source>Created by</source>
130+
<target>Created by</target>
131+
</trans-unit>
132+
<trans-unit id="LVVWz4T" resname="Created at">
133+
<source>Created at</source>
134+
<target>Created at</target>
135+
</trans-unit>
136+
<trans-unit id="ZHIlC6b" resname="Go to previous page">
137+
<source>Go to previous page</source>
138+
<target>Go to previous page</target>
139+
</trans-unit>
140+
<trans-unit id="YiuzkhO" resname="Go to next page">
141+
<source>Go to next page</source>
142+
<target>Go to next page</target>
143+
</trans-unit>
144+
<trans-unit id="ICfdxrk" resname="Missing data">
145+
<source>Missing data</source>
146+
<target>Missing data</target>
147+
</trans-unit>
148+
<trans-unit id="SGmWohz" resname="Failed processes">
149+
<source>Failed processes</source>
150+
<target>Failed processes</target>
151+
</trans-unit>
152+
<trans-unit id="QOhsBcU" resname="An error occurred while fetching the data">
153+
<source>An error occurred while fetching the data</source>
154+
<target>An error occurred while fetching the data</target>
155+
</trans-unit>
156+
<trans-unit id="eF09fJD" resname="Citizen search">
157+
<source>Citizen search</source>
158+
<target>Citizen search</target>
159+
</trans-unit>
160+
<trans-unit id="tx702.d" resname="Citizen information">
161+
<source>Citizen information</source>
162+
<target>Citizen information</target>
163+
</trans-unit>
164+
<trans-unit id="XPwqrmY" resname="An error occurred while searching">
165+
<source>An error occurred while searching</source>
166+
<target>An error occurred while searching</target>
167+
</trans-unit>
168+
<trans-unit id="M.iCN3v" resname="Go to page {page}">
169+
<source>Go to page {page}</source>
170+
<target>Go to page {page}</target>
171+
</trans-unit>
172+
<trans-unit id="KXqovG." resname="Loading data …">
173+
<source>Loading data …</source>
174+
<target>Loading data …</target>
175+
</trans-unit>
176+
<trans-unit id="iMqbR_1" resname="Showing {from}–{to} of {total}">
177+
<source>Showing {from}–{to} of {total}</source>
178+
<target>Showing {from}–{to} of {total}</target>
179+
</trans-unit>
180+
<trans-unit id="rogeeu2" resname="The process was restarted">
181+
<source>The process was restarted</source>
182+
<target>The process was restarted</target>
183+
</trans-unit>
184+
<trans-unit id="U5QT.Nm" resname="An error occurred when trying to restart the process">
185+
<source>An error occurred when trying to restart the process</source>
186+
<target>An error occurred when trying to restart the process</target>
187+
</trans-unit>
188+
<trans-unit id="tIp4N7k" resname="Rerun step">
189+
<source>Rerun step</source>
190+
<target>Rerun step</target>
191+
</trans-unit>
192+
<trans-unit id="wmAX68g" resname="Finished at {finishedAt}">
193+
<source>Finished at {finishedAt}</source>
194+
<target>Finished at {finishedAt}</target>
195+
</trans-unit>
196+
<trans-unit id="jmp.PI_" resname="Failed at {failedAt}">
197+
<source>Failed at {failedAt}</source>
198+
<target>Failed at {failedAt}</target>
199+
</trans-unit>
200+
<trans-unit id="cyzVmW2" resname="Error code: {code}">
201+
<source>Error code: {code}</source>
202+
<target>Error code: {code}</target>
203+
</trans-unit>
132204
</body>
133205
</file>
134206
</xliff>

widgets/src/_standalone/ProcessOverview/Pagination.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@
3434
class="flex items-center justify-between border-t border-neutral-400 dark:border-neutral-700 px-4 py-3"
3535
>
3636
<div class="min-w-[200px] flex items-center text-sm dark:text-gray-300">
37-
<!-- Todo find a way to handle placeholders -->
38-
<span>{size * page - size}-{size * page} {t('of')} {total}</span>
37+
<span
38+
>{t('Showing {from}–{to} of {total}', {
39+
from: size * page - size + 1,
40+
to: Math.min(size * page, total),
41+
total
42+
})}</span
43+
>
3944
</div>
4045
<div class="flex items-center space-x-2">
4146
<PaginationButton
@@ -50,7 +55,7 @@
5055
{#each totalAmountOfPagesAsIntegerArray as index}
5156
<PaginationButton
5257
selected={page === index}
53-
label={t('Go to page')}
58+
label={t('Go to page {page}', { page: index })}
5459
id={String(index)}
5560
changePage={() => changePage(index)}>{index}</PaginationButton
5661
>

widgets/src/_standalone/ProcessOverview/config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ export const config: OverviewConfig = (() => {
2222
return {};
2323
})();
2424

25-
export const t = (text: string) => config.messages?.[text] ?? text + ' (missing translation)';
25+
export const t = (text: string, placeholders: object = {}) => {
26+
const translated = config.messages?.[text] ?? text + ' (missing translation)';
27+
28+
// Replace `{key}` with `placeholders[key]`. If `key` is not defined, return the placeholder (incl. `{}`).
29+
return translated.replace(/\{([^\}]+)\}/g, (match, key) => {
30+
return placeholders[key] ?? match;
31+
});
32+
};

widgets/src/_standalone/ProcessOverview/index.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
{:else if fetching}
6565
<div class="flex justify-center mb-5">
6666
<Spinner>
67-
<h2 class="my-3 dark:text-white text-neutral-900">{t('Loading data...')}</h2>
67+
<h2 class="my-3 dark:text-white text-neutral-900">{t('Loading data')}</h2>
6868
</Spinner>
6969
</div>
7070
{:else if null === data}

widgets/src/lib/Popover.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,18 @@
9999
{failure.message}
100100
</div>
101101
<div class="py-1 font-thin">
102-
{t('Error code')}
103-
{failure.code}
102+
{t('Error code: {code}', { code: failure.code })}
104103
</div>
105104
{/if}
106105

107106
{#if finishedAt}
108107
<div class="py-1 font-thin">
109-
{t('Finished at')}
110-
{finishedAt}
108+
{t('Finished at {finishedAt}', { finishedAt })}
111109
</div>
112110
{/if}
113111
{#if failedAt}
114112
<div class="py-1 font-thin">
115-
{t('Failed at')}
116-
{failedAt}
113+
{t('Failed at {failedAt}', { failedAt })}
117114
</div>
118115
{/if}
119116
<!-- For consistency, the button is always visible on failed processes, and disabled if they cannot rerun -->
@@ -133,7 +130,7 @@
133130
{#if error}
134131
<div class="py-1 font-bold max-w-[280px] flex items-center">
135132
<Bell className="h-8 w-8 mr-2" />
136-
{t('An error occurred when the process was restarted')}
133+
{t('An error occurred when trying to restart the process')}
137134
</div>
138135
{/if}
139136
{/if}

0 commit comments

Comments
 (0)