Fix translation loading issue and ensure translations are applied before updating UI#293
Open
Dhanushcdivakar wants to merge 2 commits intowikimedia:masterfrom
Open
Fix translation loading issue and ensure translations are applied before updating UI#293Dhanushcdivakar wants to merge 2 commits intowikimedia:masterfrom
Dhanushcdivakar wants to merge 2 commits intowikimedia:masterfrom
Conversation
Member
|
@Abijeet Do you have thoughts about this PR? |
Abijeet
requested changes
Feb 12, 2025
|
|
||
| // Instead of $.each(), use Object.keys() and forEach() in vanilla JS | ||
| Object.keys(formats).forEach(function(key) { | ||
| console.log('appending ' + key); |
| gender = $( '.person option:selected' ).val(); | ||
| kittens = $( '.kittens' ).val(); | ||
| // Load the translation file | ||
| i18n.load('../assets/lang/ui_' + i18n.locale + '.json', i18n.locale) |
Member
There was a problem hiding this comment.
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 |
Member
There was a problem hiding this comment.
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 ); |
Member
There was a problem hiding this comment.
Where is this now? The translated string should update when the number of kittens, the person or the language is changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.