Skip to content

Commit adbdbec

Browse files
authored
Merge pull request #46 from devforth/added_component_interpolation_instead_v_html
Changed v-html translations to t-i18n-component
2 parents c81f52f + bc70ef8 commit adbdbec

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/10-i18n.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,24 @@ const adminForth = new AdminForth({
273273
274274
### HTML in translations
275275
276-
Sometimes you might want to have HTML in translations. You can use `v-html` directive for this. For example:
276+
Sometimes you might want to have HTML in translations. You can use `i18n-t` translation component for this. For example:
277277
278278
```html
279-
<h1 class="mb-4 text-xl font-extrabold text-gray-900 dark:text-white md:text-2xl lg:text-3xl"
280-
v-html='$t("<span class=\"text-transparent bg-clip-text bg-gradient-to-r to-emerald-600 from-sky-400\">Apartments</span> Statistics.")'></h1>
279+
<span class="hidden sm:inline">
280+
<i18n-t keypath="Showing {from} to {to} of {total} Entries" tag="p" >
281+
<template v-slot:from>
282+
<strong>{{ from }}</strong>
283+
</template>
284+
<template v-slot:to>
285+
<strong>{{ to }}</strong>
286+
</template>
287+
<template v-slot:total>
288+
<strong>{{ totalRows }}</strong>
289+
</template>
290+
</i18n-t>
291+
</span>
281292
```
282293
283-
> 🪪 Security alert. Please keep in mind that if you are using `v-html="$t(`, the roles who have access to translations resource can make HTML/XSS injections, though anyway if you are using [Audit Log](/docs/tutorial/Plugins/AuditLog/) plugin you can track all changes in translations and understand who made them.
284-
285294
### Pluralization
286295
287296
Frontend uses same pluralization rules as vue-i18n library. You can use it in the same way. For example:

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,33 @@
234234
<span class="text-sm text-gray-700 dark:text-gray-400">
235235
<span v-if="((page || 1) - 1) * pageSize + 1 > totalRows">{{ $t('Wrong Page') }} </span>
236236
<template v-else>
237-
<span class="hidden sm:inline"
238-
v-html="$t('Showing {from} to {to} of {total} Entries', {from: ((page || 1) - 1) * pageSize + 1, to: Math.min((page || 1) * pageSize, totalRows), total: totalRows})
239-
.replace(/\d+/g, '<strong>$&</strong>')">
240-
</span>
241-
<span class="sm:hidden"
242-
v-html="$t('{from} - {to} of {total}', {from: ((page || 1) - 1) * pageSize + 1, to: Math.min((page || 1) * pageSize, totalRows), total: totalRows})
243-
.replace(/\d+/g, '<strong>$&</strong>')
244-
">
237+
238+
<span class="hidden sm:inline">
239+
<i18n-t keypath="Showing {from} to {to} of {total} Entries" tag="p" >
240+
<template v-slot:from>
241+
<strong>{{ from }}</strong>
242+
</template>
243+
<template v-slot:to>
244+
<strong>{{ to }}</strong>
245+
</template>
246+
<template v-slot:total>
247+
<strong>{{ totalRows }}</strong>
248+
</template>
249+
</i18n-t>
245250
</span>
246-
251+
<span class="sm:hidden">
252+
<i18n-t keypath="{from} - {to} of {total}" tag="p" >
253+
<template v-slot:from>
254+
<strong>{{ from }}</strong>
255+
</template>
256+
<template v-slot:to>
257+
<strong>{{ to }}</strong>
258+
</template>
259+
<template v-slot:total>
260+
<strong>{{ totalRows }}</strong>
261+
</template>
262+
</i18n-t>
263+
</span>
247264
</template>
248265
</span>
249266
</div>
@@ -302,6 +319,8 @@ const page = ref(1);
302319
const sort = ref([]);
303320
304321
322+
const from = computed(() => ((page.value || 1) - 1) * props.pageSize + 1);
323+
const to = computed(() => Math.min((page.value || 1) * props.pageSize, props.totalRows));
305324
306325
watch(() => page.value, (newPage) => {
307326
emits('update:page', newPage);

0 commit comments

Comments
 (0)