Closed milotoor closed 8 months ago
@milotoor, thank you for opening this issue. I'm going to mark this as a bug and review this with the team internally. We'll keep you posted on when we have a fix ready!
@milotoor Good day, a fix for this issue made it out with Amplify 6.0.10. Could you please let us know if this release resolved your issue?
@jimblanc thank you for letting me know! I can confirm that v6.0.10 addresses my issue. I appreciate the swift turnaround!
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication, Internationalization
Amplify Categories
auth
Environment information
Describe the bug
I have the following code in my TypeScript React application, and I can confirm that it is being executed at runtime:
However, the
ConfirmSignIn
view continued to show the "Confirm TOTP Code" text instead:This is in contrast to the same application using
aws-amplify
v5, which properly rendered the translation. I believe that the discrepancy is due to the way default language detection works between v5 and v6. The v6 Internationalization docs (as well as the v5 docs) claim thatAfter adding a breakpoint in the
ConfirmSignIn
component and descending several frames (throughgetChallengeText
and into the staticI18n
and the package-privateI18n
class) I found that the translation was failing because the wrappedI18n
class's_lang
property wasnull
:I was subsequently surprised to find that the
I18n.setDefaultLanguage
method--the code which is responsible for setting the_lang
property usingwindow.navigator.language
--was not being called. Furthermore, because the wrappedI18n
class is package-private, that method is not exposed for me to call.Now, I can remedy this by cloning the contents of
setDefaultLanguage
in my codebase (in my case callingsetLanguage('en')
will likely be sufficient). But this appears to be a bug and not something that users should have to do. In v5 this is not an issue because thesetDefaultLanguage
method does not exist; its contents are simply included in theI18n
class constructor.The issue appears to have been introduced recently, when
I18n
was un-deprecated following its(temporary) deprecation:11795 deprecates the
I18n
class (for reasons unclear to me). ThesetDefaultLanguage
is born and thewindow.navigator.language
usage is removed from the class constructor. The new method is called fromI18n.get
.11711 removes the call to
setDefaultLanguage
from theI18n.get
method. This is when the regression is introduced and the contents ofsetDefaultLanguage
become unreachable. However, the class is marked as deprecated and nobody seems to notice or mind.12112 un-deprecates
I18n
and the regression becomes an actual problem againExpected behavior
The language should be automatically detected, as advertised in the documentation.
Reproduction steps
aws-amplify
and@aws-amplify/ui-react
(the latter package is not relevant to this bug report, only for the reproduction)Render the
Authenticator
using your favorite UI library (example in React, taken from theAuthenticator
component docs). Include a translation:Code Snippet
See above.
Log output
No informative logs to report
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response