-
Hi, I have read the How (not) to use translations outside of React components blog post and I guess I understand the intentions, but I can't figure out how to properly use translation in some server functions, that are neither server actions or React component (but might be called from both). For example I might have a function Simple way would be to return But what type should I return when I also want to pass in parametr for the translate method?
The typescript page typescript integration page did not help. And is this approach need, when the function is called only from a server action or React server component? I'm not sure if the problems described in the blog post apply there (but I'm quite new to Next.js so I'm not sure about anything). Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This seems similar to how Zod can be used in Server Actions, while using translations. What happens is basically:
It's essentially the same pattern that's also described in the blog post:
So I'd try to avoid coupling your Does that help? |
Beta Was this translation helpful? Give feedback.
This seems similar to how Zod can be used in Server Actions, while using translations.
What happens is basically:
t
fromawait getTranslations
and turns the data structure into a human-readable error message (could also be a component in your case)It's essentially the same pattern that's also described in the blog post:
So I'd try to avoid coupling your
checkSomething
function to translations, but it could for example return error codes (e.g.code: 'PROBLEMATIC_MEMBER'
), potentially wit…