Skip to content

Conversation

@Dhanushcdivakar
Copy link

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.

@srish srish requested review from Abijeet and santhoshtr January 7, 2025 02:26
@srish
Copy link
Member

srish commented Feb 10, 2025

@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);
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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 );
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants