Repository navigation
Fall back to global translations in Component.translate - #2727
Merged
joelhawksley merged 3 commits intoOct 19, 2026
Merged
Conversation
Calling translate on the component class with a key that isn't in the sidecar translations raised UncaughtThrowError, because the I18n backend throws :exception for a missing key and nothing caught it. Components without sidecar translations raised NoMethodError on the nil backend. Fall back to I18n.translate in both cases, like the instance method falls back to the view context's translate.
Use I18nBackend#exists? to decide between sidecar and global translations in both the class and instance translate methods, rather than catching I18n's internal :exception throw. This also fixes `default:` shadowing existing global translations, since the sidecar backend applied the default before the fallback could run. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ba89fbcb-d0e9-4f12-8673-169fbe391979
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.
What are you trying to accomplish?
Component.translate(added in #1656) blows up for any key that isn't in the component's sidecar file:The I18n backend throws
:exceptionfor a missing key and expectsI18n.translateto catch it. The class method calls the backend directly, so nothing catches it. For components without sidecar translations,__vc_i18n_backendisnil.What approach did you choose and why?
Do what the instance method already does: try the sidecar backend first, catch the missing translation, and fall back to the global translations, here through
I18n.translate, since there's no view context on the class. A missing key now returns the usual "Translation missing" string, anddefault:andraise: truebehave like they do withI18n.t. When there are no sidecar translations, it goes straight toI18n.translate.Anything you want to highlight for special attention from reviewers?
The class method still doesn't do the HTML-safe handling for
_htmlkeys. #1656 left that out on purpose, so I didn't touch it.