Issue Feature Closed

#108941Adjusting JavaScript Language Label Handling in TYPO3

Tobias Wojtylak 02/11/26, 11:54 updated 03/31/26, 08:11

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

  1. Simple and fast to implement

❌ Cons

  1. Language strings must still exist in the “main” frame (e.g., passed via `PageRenderer::addInlineLanguageDomain`).

2. Load Translation Keys Dynamically via AJAX

  1. 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.
  2. The request would pass the translation domain (e.g., form.messages).
  3. A TYPO3 backend controller would use LanguageService::getLabelsFromResource to return the labels.
  4. These labels could then be stored in a JavaScript object, e.g., `TYPO3.langByDomain` (TBD: key), and accessed via lll.

✅ Pros

  1. Language strings do not need to be predefined in frames; they are loaded dynamically when needed.

❌ Cons

  1. 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).
  2. Implementation is more complex.

Reviews 9