react-stripe-elements icon indicating copy to clipboard operation
react-stripe-elements copied to clipboard

Elements locale option not localizing

Open adambarghouthi opened this issue 6 years ago • 5 comments

Hi, I'm having trouble localizing the Elements component. Here's my code below:

const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PK)

const PaymentMethodForm = (props) => {
  const { locale } = React.useContext(LocaleContext)

  return (
    <Elements key={locale} locale={locale} stripe={stripePromise}>
      <Body {...props} />
    </Elements>
  )
}

export default PaymentMethodForm

If I do loadStripe(process.env.NEXT_PUBLIC_STRIPE_PK, { locale: locale }), it works but obviously it won't detect if the user changes the locale because it loads outside the component.

Is the stripePromise overriding the locale I'm passing to the Elements component with my browser's locale? Because I keep seeing the Elements component render in English even when the locale changes. Would appreciate some help, thanks!

adambarghouthi avatar Sep 23 '20 16:09 adambarghouthi

Hi @adambarghouthi, I found the same issue and also this thread with a "strong" workaround. Basically it forces to reload the component changing the key https://github.com/stripe/react-stripe-elements/issues/225

glaucopater avatar Feb 10 '21 16:02 glaucopater

I'm having a similar issue. This is how I'm invoking Elements:

<Elements key={language} locale={language} stripe={stripePromise}>

If I pass fr into locale the field it doesn't do anything. Furthermore my linter goes crazy because locale is apparently not set on ElementProps (supposedly).

Every other sample with Stripe.js works except for the hooks versions. I'm using it correctly given the documentation: https://github.com/stripe/react-stripe-elements#elements. I'm also on the latest version of the dpeendency.

davedbase avatar Feb 22 '21 17:02 davedbase

@davedbase have you tried what @glaucopater suggested? A strong reset of the component using a key prop that changes with the locale should work (I haven't tried it yet but I've seen it used in other instances)

adambarghouthi avatar Mar 01 '21 14:03 adambarghouthi

@adambarghouthi I created a topic here: https://github.com/stripe/react-stripe-elements/issues/554 which shows the exact method I'm using. I'm basically giving it a key when it first mounts but there's more details in my specific issue that might be useful.

davedbase avatar Mar 01 '21 19:03 davedbase

it's in the options prop! thanks @davedbase

adambarghouthi avatar Mar 03 '21 01:03 adambarghouthi