-
Notifications
You must be signed in to change notification settings - Fork 670
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
Not able to use next-intl
's createTranslator with Tailwind component
#1244
Comments
next-intl
's createTranslator with Tailwind component
Same error with |
@antoinerousseau Is it the same exact error or just a similar error? |
(working with @antoinerousseau here 👋 ) |
After digging around a lot this should be fixed by #1124 which I have tested myself. Not sure how this is caused but some of the polyfills we have currently on tailwind are causing this—something to do with tslib. @ababol @antoinerousseau lmk if you are blocked by not using intl here cuz I can make a patch for you from #1124. Also, the error overlay is just not helping here so I'm opening up a new PR #1264 to improve it to show something more accurate. Here's the actual stack trace: |
Thanks @gabrielmfern! But no worries it's not urgent, meanwhile we developed our own minimalist preview that uses RSC and next-intl :) |
Thanks @gabrielmfern!
#666 (comment) (see details) It works perfectly in dev mode but not when we actually build the web app (next build / next start). |
Nope, that's something else, someone also had this #1112 |
@gabrielmfern ist there any possibility to get a patch for this so we can test this? we also seem to run into this exact error. |
@mmachatschek Sure, no problem. And here is a quick guide of how to apply it if you have any trouble lmk if it works out for you |
@gabrielmfern the patch didn't solve the issue for me (we are not using the |
@gabrielmfern patch failed for me also. Using |
@mmachatschek @justinnais Could one of you give a reproduction for this? Seems like your issue is something else here 🤔 |
Also, were you not able to apply the patch or did it apply successfully but still fail when running? I tried applying it myself and wasn't able to, so I've updated it and it should apply properly now |
Failed to apply. I'll retry the patch. What's the best way to provide you a repro @gabrielmfern? |
@gabrielmfern for me the patch applied correctly with pnpm I'll provide a repro asap |
@gabrielmfern this is the reproduction repo: https://github.com/mmachatschek/react-email-repro-issue-1244 check the |
@mmachatschek Thank you so much for providing the reproduction here, I applied the patch I sent before and the error wasn't gone. I then realized I sent the wrong patch here, I properly got the diff and swapped the patch with the proper one and it seems to be working fine even with your repro. Also from what I saw you had an issue applying the patch @justinnais; if you were using If you used |
@gabrielmfern I can confirm that the provided patch is working now 👍 |
When trying to apply your patch, I get the following error:
Any idea? |
@gijsmin You need to apply the patch to |
what's plan of this PR |
a specific to patch-package patch would be appreciated since I cannot apply the patch even after modifying it, probably im doing something wrong but can't tell what. |
Just in case anyone is interesed, after watching this issue I decided to try using the i18next library and its working perfectly. I am using a simple nodejs backend app to send my emails, so you first need to install the libraries: npm install i18next i18next-fs-backend Then I have created some simple translations in spanish and english for my email data: const esMessages = {
notifications: {
templates: {
common: {
welcome: 'Hola {{name}}',
},
forgotPassword: {
email: {
preview: "Restablece tu contraseña en Fuel",
text: 'Parece que has olvidado tu contraseña, pulsa en el botón para poder cambiarla.',
button: 'CAMBIAR',
warning: 'Si no has solicitado reestablecer tu contraseña, ignora este mensaje o ponte en contacto con nosotros',
},
},
},
},
};
export default esMessages; const enMessages = {
notifications: {
templates: {
common: {
welcome: 'Hello {{name}}',
},
forgotPassword: {
email: {
text: 'It looks like you have forgotten your password, click the button to change it.',
button: 'CHANGE',
warning: 'If you did not request to reset your password, ignore this message or contact us',
},
},
},
},
};
export default enMessages; Now create a i18next instance per locale for performance reasons and just export a function to select the proper locale: import i18next from 'i18next';
import Backend from 'i18next-fs-backend';
import esMessages from './locales/es';
import enMessages from './locales/en';
const resources = {
es: { translation: esMessages },
en: { translation: ptMessages },
};
const createI18nInstance = (locale: string) => {
const instance = i18next.createInstance();
instance.use(Backend).init({
lng: locale,
fallbackLng: 'es',
resources,
});
return instance;
};
const i18n_es = createI18nInstance('es');
const i18n_en = createI18nInstance('en');
export const getIntl = (locale: string) => {
return locale === 'en' ? i18n_en : i18n_es;
}; And then just import the import { Html, Head, Text, Heading, Preview, Section } from '@react-email/components';
import { Container, Header, Footer, FooterText, FooterLinks, Button, Image } from '../components';
import { getIntl } from '../../../../intl';
interface PasswordResetEmailProps {
name: string;
resetLink: string;
locale: string;
}
const PasswordResetEmail = ({ name, resetLink, locale }: PasswordResetEmailProps) => {
const intl = getIntl(locale);
return (
<Html lang={locale}>
<Head />
<Preview>{intl.t('notifications.templates.forgotPassword.email.preview')}</Preview>
<Container>
<Header />
<Section className="text-center">
<Image src="people.jpg" width="200" />
<Heading className="text-xl text-gray-800 text-center mt-6">
{intl.t('notifications.templates.common.welcome', { name })}
</Heading>
<Text className="text-base text-gray-800 text-center mt-4">
{intl.t('notifications.templates.forgotPassword.email.text')}
</Text>
<Button href={resetLink}>{intl.t('notifications.templates.forgotPassword.email.button')}</Button>
<Text className="text-base text-gray-800 text-center mt-4">
{intl.t('notifications.templates.forgotPassword.email.warning')}
</Text>
</Section>
<Footer>
<FooterLinks />
</Footer>
</Container>
</Html>
);
};
PasswordResetEmail.PreviewProps = {
name: 'Nombre',
resetLink: 'https://example.com/reset-password',
locale: 'pt',
} as PasswordResetEmailProps;
export default PasswordResetEmail; I have tested in the dev environment and with a script rendering the component and sending it, both environments working fine! I hope this helps someone |
Akin to the solution posted by @angelhodar, i went for a more scriptey solution (previously posted at #431 ):
|
https://github.com/hyperse-io/translator it can works for import * as React from 'react';
import { createTranslator } from '@hyperse/translator';
import { Button, Html } from '@react-email/components';
const messages = {
es: {
PREVIEW: 'Haz click aquí para iniciar sesión con este enlace mágico',
},
en: {
PREVIEW: 'Click here to login with this magic link',
},
};
export default function Email(props) {
const { url, languageCode = 'en' } = props;
const t = createTranslator({
locale: languageCode,
messages,
namespace: languageCode as 'en',
});
return (
<Html lang="en">
<p>{t('PREVIEW')}</p>
<Button href={url}>email-address-change</Button>
</Html>
);
} |
We just merged #1383 and released it under canary, |
Describe the Bug
i have this template :
in preview mode i have this error :
when i remove Tailwind it s work correctly :
Which package is affected (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://gitlab.com/robin.louarn/programme-tz-2023
To Reproduce
nvm use
pnpm install
pnpm email:dev
Expected Behavior
see a preview of email
What's your node version? (if relevant)
20.11.0
The text was updated successfully, but these errors were encountered: