Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested templates #39

Open
Loskir opened this issue Aug 13, 2020 · 1 comment
Open

Nested templates #39

Loskir opened this issue Aug 13, 2020 · 1 comment

Comments

@Loskir
Copy link
Contributor

Loskir commented Aug 13, 2020

Add the t function to templateData so that we can use t inside the template itself

For example:

greeting: hello!
main: i like trains.
end: bye!

text: |-
  ${t('greeting')}

  ${t('main')}

  ${t('end')}
@EdJoPaTo
Copy link
Contributor

EdJoPaTo commented Oct 7, 2020

you can already add it yourself when needed.

bot.command('translaception', async ctx => {
  const result = ctx.i18n.t('whatever', {t: ctx.i18n.t})
  await ctx.reply(result)
})

For a more permanent solution add it via templateData on the I18n initialisation:

const i18n = new I18n({
  
  templateData: {
    translateWithLanguageArgument: (languageCode: string, resourceKey: string) => i18n.t(languageCode, resourceKey),
    translateWithUserLanguage: (resourceKey: string) => i18n.t((this as any).languageCode, resourceKey),
    uppercase: (value: string) => value.toUpperCase()
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants