question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(@aws-amplify/ui-react): Component re-render on I18n.setLanguage

See original GitHub issue

Is your feature request related to a problem? Please describe. Components are not re-rendering on I18n.setLanguage. Components are rendering initial language strings correctly but they do not re-render on language change.

Relates to aws-amplify/amplify-js#6346 aws-amplify/amplify-js#6115 #6962

Describe the solution you’d like Components should re-render on I18n.setLanguage

Suggestion from @ericclemmons https://github.com/aws-amplify/amplify-js/pull/6346#issuecomment-710227501 :

If I18n.setLanguage fired a Hub event, we could re-render the component 🤔 https://github.com/aws-amplify/amplify-js/blob/377acd0507e6d4be34bf36ea9c0694fa98ac04b1/packages/core/src/I18n/I18n.ts#L64-L66

Describe alternatives you’ve considered

  1. Force re-render using key attribute
    <AmplifySignIn key={lang} />
    
    Force re-creating the components will result in a screen flicker and loss of component state
  2. Specifying all texts in props
    <AmplifySignIn 
      headerText={I18n.get(Translations.XXXXX)}
      formFields={[
        {
          type: "email",
          label: I18n.get(Translations.XXXXX),
          placeholder: I18n.get(Translations.USERNAME_PLACEHOLDER),
          required: true,
        },
        {
          type: "password",
          label: I18n.get(Translations.XXXXX),
          placeholder: I18n.get(Translations.PASSWORD_PLACEHOLDER),
          required: true,
        }
      ]}>
    </AmplifySignIn>
    
    Doable but a big hassle : D

Additional context This is happening in @aws-amplify/ui-react. Need to check if other ui-components e.g. angular, vue, etc exhibit the same behavior.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
weicommented, Feb 4, 2021

@eokoneyo For now, you can specify attributes directly as seen in https://github.com/aws-amplify/amplify-js/issues/6962#issuecomment-710701413

0reactions
ericclemmonscommented, Nov 3, 2021

We’ll need to a PR to Amplify JS so I18n emits Hub events when the language changes.

Only then can the UI components subscribe to this event & re-render with the new dictionary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React i18next - Change language does not re-render ...
Currently we are using re-usable component library for our react projects that uses I18nextProvider and passed the i18n instance for the ...
Read more >
Step by step guide (v9) - react-i18next documentation
export default i18n;. Make sure to import i18n.js in index.js: import React, { Component } from "react";. import ReactDOM from "react-dom";. import '....
Read more >
Universe:i18n: Recommended way to re-render whole React ...
With tap:i18n , this worked automagically. But universe:i18n only updates the language strings if a component is explicitly re-rendered or a new ...
Read more >
A Guide to React Localization with i18next | Phrase
React-i18next is a powerful set of components, hooks, and plugins that sit on top of i18next. Learn how to use it to internationalize...
Read more >
React localization with i18next - LogRocket Blog
There, we have all our React components containing the content we can localize. Installing the i18next and react-i18next packages. To localize a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found