-
Notifications
You must be signed in to change notification settings - Fork 162
Fix translation loading issue and ensure translations are applied before updating UI #293
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
base: master
Are you sure you want to change the base?
Conversation
|
@Abijeet Do you have thoughts about this PR? |
|
|
||
| // Instead of $.each(), use Object.keys() and forEach() in vanilla JS | ||
| Object.keys(formats).forEach(function(key) { | ||
| console.log('appending ' + key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray console.log
| gender = $( '.person option:selected' ).val(); | ||
| kittens = $( '.kittens' ).val(); | ||
| // Load the translation file | ||
| i18n.load('../assets/lang/ui_' + i18n.locale + '.json', i18n.locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return the promise from loadTranslations object and simple use .then in the caller to run code after the translations are loaded.
| function loadTranslations(callback) { | ||
| // Assuming i18n is an object with a load method | ||
| const i18n = { | ||
| locale: 'en', // Replace with dynamic locale if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The locale should be determined based on the value selected in the dropdown
| $( document ).ready( function ( $ ) { | ||
| 'use strict'; | ||
| updateText(); | ||
| $( '.kittens, .person, .language' ).on( 'change keyup', updateText ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this now? The translated string should update when the number of kittens, the person or the language is changed.
This commit addresses an issue where translations were being loaded asynchronously, causing the UI elements to be populated before the translations were available. The fix ensures that translations are fully loaded before they are applied to the UI, improving the user experience by preventing untranslated text from appearing initially.