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

Retrieve Translations (t) for Given Locale #421

Open
Dan6erbond opened this issue Aug 27, 2024 · 1 comment
Open

Retrieve Translations (t) for Given Locale #421

Dan6erbond opened this issue Aug 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Dan6erbond
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I'd like to use next-international outside of the Next.js context, specifically when sending emails with react-email. For this my plan was to provide it with the translated texts but it seems there's no way to use await getI18n() and provide it with the locale I want. I tried working around that with createT but it didn't seem that intuitive after playing around a bit with it especially if I want to have working types.

Additionally, I want server actions to use the locale I hardcode for the website (this may change from values in the CMS) so that the email title and other metadata are in the correct language as well. getI18n() defaults to the user's locale which could be different from the site admin's preferred language.

Describe the solution you'd like
A clear and concise description of what you want to happen.

getI18n() could take an optional locale parameter or a new getLocaleI18n() function could be added.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I was able to wrap react-email components with I18nClientProvider, but I'm not sure that's really the intended purpose and I haven't been able to test if this works properly when sending the emails.

Additional context
Add any other context or screenshots about the feature request here.

Sample server action:

  const payload = await getPayload();
  const { adminLanguage, contactEmailsTo } = await getSettings();
  const t = await getI18n(); // I want to pass adminLanguage here

  await payload.sendEmail({
    to: contactEmailsTo,
    subject: t("email.contactSubject", { name: formData.get("name") }),
    email: await render(
      <EmailTranslationsWrapper locale="de">
        <ContactEmail
          name={formData.get("name")}
          email={formData.get("email")}
          subject={formData.get("subject")}
          message={formData.get("message")}
        />
      </EmailTranslationsWrapper>,
    ),
  });
@Dan6erbond Dan6erbond added the enhancement New feature or request label Aug 27, 2024
@clementgateaud
Copy link

I also have the same need, I want to use translations in API route handlers to return error messages or send emails in a specific language.
I didn't find a way to do it 😕

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

No branches or pull requests

2 participants