How to swap out specific terms within a locale for different types of users #716
-
I have a set of phrases in an
I could create additional translation files but then the locale would be something like I've got it half working using a formatter. But I got an error when trying to read the userType from the page data so I've hard coded the user type in the formatter. And I'm having to pass in the term I want to change when calling the translation, but I want the translation file to already have the term and pass it directly to the formatter.
I hope that made sense 😊 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
From what I understand formatters are the thing you are looking for. But indeed, you don't have access to translations in there. // util
const toTerm = (term: Terms) => $LL.terms[term]()
// translation
title: 'Manage your {0:LocalizedString} here',
terms: {
fruit: 'fruit store',
bakery: 'bakery',
}
// +page.svelte
<h2>{$LL.home.title(toTerm(user.type))}</h2> Hope this is clear |
Beta Was this translation helpful? Give feedback.
From what I understand formatters are the thing you are looking for. But indeed, you don't have access to translations in there.
You could create a utility function to get to the translated value instead of using a formatter.
Hope this is clear