#108941Adjusting JavaScript Language Label Handling in TYPO3
Description
Problem
The JavaScript function lll (defined in https://github.com/TYPO3/typo3/blob/main/Build/Sources/TypeScript/core/lit-helper.ts#L43) searches for the requested label in the current window and the top window. Labels in the top frame are restricted to the backend scope.
If you e.g. create a modal like this:
const content = html`
<typo3-component-with-lll-calls />
`;
Modal.advanced({
title: lll('Hello World'),
});
…and your component <typo3-component-with-lll-calls> calls `lll` for labels that exist in the current frame but not in the top frame, these labels will not be resolved.</typo3-component-with-lll-calls>
Current Workarounds
Currently, developers manually add TYPO3.lang as a custom property on modal child elements via Modal callbacks , e.g.:
form.TYPO3lang = TYPO3.lang;
and do not use the generic `lll` function, which has some drawbacks e.g. placeholders are not replaced in these cases.
Reference: https://github.com/TYPO3/typo3/blob/main/Build/Sources/TypeScript/workspaces/workspaces.ts#L57
Proposed Solutions
1. Search Child Frames as Fallback (Quick Win?)
If a language key is not found in the current or top frame, we could search the child frames for the label:
else if (window.self === window.top) {
// fallback: search child frames for translation key
for (let i = 0; i < window.frames.length; i++) {
try {
if (typeof window.frames[i]?.TYPO3?.lang[key] === 'string') {
languagePool = window.frames[i].TYPO3.lang;
break;
}
} catch {
// cross-origin frame, skip
}
}
}
✅ Pros
- Simple and fast to implement
❌ Cons
- Language strings must still exist in the “main” frame (e.g., passed via `PageRenderer::addInlineLanguageDomain`).
2. Load Translation Keys Dynamically via AJAX
- If a key (possibly including a translation domain, e.g., form.messages:validation.error.1221565130 ( TBD : If it is possible to determine whether the key contains a translation domain? Yes: everything before `:`) is missing from TYPO3.lang, we load the translation file dynamically via an AJAX request.
- The request would pass the translation domain (e.g., form.messages).
- A TYPO3 backend controller would use LanguageService::getLabelsFromResource to return the labels.
- These labels could then be stored in a JavaScript object, e.g., `TYPO3.langByDomain` (TBD: key), and accessed via lll.
✅ Pros
- Language strings do not need to be predefined in frames; they are loaded dynamically when needed.
❌ Cons
- A new translation function may be required to support passing a translation domain (the current lll signature is (key: string, …args: any[]) and cannot accept additional parameters).
- Implementation is more complex.
Reviews 9
- main 92871[TASK] Use shared label for collapse_state_search.numberOfSearchMatches
- main 92925[TASK] Support ICU MessageFormat in JavaScript label API
- main 92935[TASK] Generate types for placeholders in JavaScript label API
- main 92868[TASK] Use JavaScript label imports in EXT:extensionmanager
- main 92867[TASK] Use JavaScript label imports in EXT:dashboard
- main 92815[TASK] Migrate bookmark modules to use JavaScript label modules
- main 92865[TASK] Add virtual label provider for JavaScript unit tests
- main 92810[FEATURE] Provide language labels as virtual JavaScript modules
- main 92817[TASK] Deprecate `PageRenderer->addInlineLanguageDomain()`