Skip to content

Translate inside a QRL function? #70

Closed Answered by robisim74
jimmynguyen1308 asked this question in Q&A
Discussion options

You must be logged in to vote

In Qwik, a QRL is a lazy loaded code snippet, and does not belong to the component$. Therefore it is not possible to use hooks, or closure functions like t: https://qwik.builder.io/docs/advanced/qrl/
To translate out of component$, you can use inlineTranlate: https://robisim74.gitbook.io/qwik-speak/library/translate#inlinetranslate

const ctx = useSpeakContext();

const fn = $(() => {
  return (
    <p>{inlineTranslate('app.example.text', ctx)}</p>
});

There is no equivalent function for usePlural (see #68), so you have to translate in the component$ and pass it to the QRL (and it works also for t):

const t = useTranslate();
const p = usePlural();

const myTranslations = t(['app.ex1', 'ap…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jimmynguyen1308
Comment options

Answer selected by jimmynguyen1308
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants