Refactor translations to use cached values#8084
Merged
Conversation
Contributor
|
Netlify Draft Deployment |
Contributor
Hydration Benchmark Report (vs Baseline)✅ Top 5 Improvements (Best Speedups)
🔻 Flop 5 Regressions (Worst Slowdowns)
📋 Show all results
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors translation handling across the component library by caching translation strings to avoid repeated translate() calls during rendering. Instead of calling translate() on every render, translations are now stored as constant values or private readonly properties that are computed once and reused.
Key changes include:
- Moving
translate()calls from render methods to module-level constants in functional components - Converting inline
translate()calls to cached private readonly properties in class components - Maintaining the same translation functionality while improving performance through caching
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| FormFieldCounter.tsx | Cached translation strings for "of" and "characters" labels as module constants |
| CustomSuggestionsToggle.tsx | Cached dropdown translation string as module constant |
| AlertIcon.tsx | Cached all alert type translation strings as module constants |
| Alert.tsx | Cached close alert translation as module constant |
| version/shadow.tsx | Moved version translation to private readonly property |
| toaster/shadow.tsx | Moved toast close all translation to private readonly property |
| table-stateless/table-settings.tsx | Cached multiple table settings translations as private readonly properties |
| table-stateless/component.tsx | Cached no entries translation as private readonly property |
| spin/shadow.tsx | Cached action running/done translations as private readonly properties |
| single-select/shadow.tsx | Cached delete selection and no results translations as private readonly properties |
| pagination/component.tsx | Cached all pagination-related translations as private readonly properties |
| modal/shadow.tsx | Cached close translation as private readonly property |
| link/component.tsx | Cached open link in tab translation as private readonly property |
| kolibri/shadow.tsx | Cached kolibri logo translation as private readonly property |
| input-password/shadow.tsx | Cached hide/show password translations as private readonly properties |
| input-file/shadow.tsx | Cached browse text and filename translations as private readonly properties |
| form/shadow.tsx | Cached form-related error and description translations as private readonly properties |
| card/component.tsx | Cached close translation as private readonly property |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Martin <6279703+deleonio@users.noreply.github.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 pull request introduces a consistent approach to handling translations across multiple components by storing translated strings in private readonly variables. This change improves code readability and maintainability by centralizing translation logic and reducing repetitive calls to the
translatefunction. Additionally, it updates various components to use these variables instead of directtranslatecalls.Translation Centralization and Usage Updates:
General Guidelines:
AGENTS.mdto include a guideline specifying that constant declarations should not precede import statements.Component-Specific Changes:
KolCard Component (
component.tsx):translateClosevariable and replaced direct calls totranslate('kol-close')with this variable. [1] [2]KolForm Component (
shadow.tsx):translateErrorListMessage,translateErrorList,translateFormDescription) and updated their usage in JSX elements. [1] [2] [3]KolInputFile Component (
shadow.tsx):translateDataBrowseText,translateFilenameText) and replaced direct calls totranslatewith these variables. [1] [2] [3] [4]KolInputPassword Component (
shadow.tsx):translateHidePasswordandtranslateShowPasswordvariables for password toggle labels and updated their usage. [1] [2]KolPagination Component (
component.tsx):translatePageFirst,translatePageBack,translatePageNext,translatePageLast,translateEntriesPerSite,translatePage,translatePagination) and updated their usage. [1] [2] [3] [4] [5] [6] [7] [8] [9]KolSingleSelect Component (
shadow.tsx):translateDeleteSelectionandtranslateNoResultsMessagevariables and updated their usage in JSX elements. [1] [2] [3]KolKolibri Component (
shadow.tsx):translateKolibriLogovariable for the Kolibri logo aria-label and updated its usage.KolLinkWc Component (
component.tsx):translateOpenLinkInTabvariable for external link labels and updated its usage. [1] [2] [3]KolModal Component (
shadow.tsx):translateClosevariable for modal close button label and updated its usage. [1] [2]