fix(fireedge): preload locale catalog server-side to eliminate translation flash - #7978
Open
huiquanyun wants to merge 1 commit into
Open
fix(fireedge): preload locale catalog server-side to eliminate translation flash#7978huiquanyun wants to merge 1 commit into
huiquanyun wants to merge 1 commit into
Conversation
…ation flash
TranslationProvider initialises with an empty messages object, causing a
flash of untranslated (English) text on every page load before the async
locale script resolves. This is particularly impactful for non-English
locales (zh_CN, fr_FR, etc.) where untranslated text is completely foreign.
Changes:/n- App.js: Read the default locale JSON at request time and inject as
window.locale in the HTML template (alongside existing preloads)
- translationProvider.js: Initialise useState with root.locale ?? {}
instead of {}, so the first render uses preloaded translations
The async loadMessages path is unchanged and still runs to ensure the
full catalog is loaded. Falls back gracefully if the JSON file is missing.
Tested on OpenNebula 7.2.0 with zh_CN locale.
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.
Summary
FireEdge Sunstone currently flashes untranslated (English) text on every page load before the locale catalog is asynchronously loaded. This PR eliminates the flash by preloading the default locale catalog server-side and initialising
TranslationProviderwith those messages.Problem
When a user opens FireEdge Sunstone, the
TranslationProvidercomponent initialises its translation state with an empty messages object:/n/n```javascriptconst [state, setState] = useState({
error: null,
isLoading: true,
locale,
messages: {}, // ← empty on first render
})
loadLocaleCatalogreads fromclient/assets/languages/<locale>.jsonand gracefully returns{}if the file is missing or unparseable.2. Client-side TranslationProvider init (
translationProvider.js)Initialise the translation state with the preloaded messages instead of an empty object:/n/n```javascript
const preloadedMessages = root.locale ?? {}
const hasPreloaded = Object.keys(preloadedMessages).length > 0
const [state, setState] = useState({
error: null,
isLoading: !hasPreloaded,
locale,
messages: preloadedMessages,
})