92810[FEATURE] Provide language labels as virtual JavaScript modules
Commit message
Review
-
Code review CR +2 Done
- Benjamin Franzke +2
- Andreas Nedbal +1
- Benjamin Kott +1
-
Verified V +2 Done
- Benjamin Franzke +2
- Andreas Nedbal +1
- Benjamin Kott +1
- core-ci +1 CI
Issues 2
Files 24
- Build/lib/generate-label-types.js3new+87 −0
- Build/lib/map-import.js+6 −0
- Build/Sources/TypeScript/backend/localization/label-provider.ts3new+39 −0
- Build/Sources/TypeScript/backend/user-settings-manager.ts+34 −18
- Build/types/labels/.gitignorenew+1 −0
- Build/types/TYPO3/index.d.ts+8 −0
- Build/Gruntfile.js+31 −1
- Build/tsconfig.json+1 −0
- typo3/sysext/backend/Classes/Controller/EditDocumentController.php+1 −2
- typo3/sysext/backend/Classes/Controller/JavaScriptLanguageDomainController.php12new+77 −0
- typo3/sysext/backend/Classes/Middleware/JavaScriptLabelImportMapEntryResolver.phpnew+72 −0
- typo3/sysext/backend/Classes/Utility/BackendUtility.php+0 −1
- typo3/sysext/backend/Configuration/Backend/Routes.php+9 −0
- typo3/sysext/backend/Configuration/JavaScriptModules.php3+2 −0
- typo3/sysext/backend/Configuration/RequestMiddlewares.php+8 −1
- typo3/sysext/backend/Resources/Private/Language/locallang.xlf+12 −0
- typo3/sysext/backend/Resources/Public/JavaScript/localization/label-provider.jsnew+13 −0
- typo3/sysext/backend/Resources/Public/JavaScript/user-settings-manager.js+1 −1
- typo3/sysext/core/Classes/Middleware/BackendUserAuthenticator.php+3 −0
- typo3/sysext/core/Classes/Page/Event/ResolveVirtualJavaScriptImportEvent.phpnew+42 −0
Show 4 more files
- typo3/sysext/core/Classes/Page/ImportMap.php+29 −1
- typo3/sysext/core/Documentation/Changelog/14.2/Feature-108941-ProvideLanguageLabelsAsVirtualJavaScriptModules.rstnew+56 −0
- typo3/sysext/setup/Classes/Controller/SetupModuleController.php+0 −2
- typo3/sysext/setup/Resources/Private/Templates/Main.fluid.html+0 −5
Review log 3848
Show 1723 earlier messages
-
Benjamin Franzke uploaded patch set 1 02/12/26, 07:11
-
Andreas Kienast commented on patch set 1 02/12/26, 07:18
-
core-ci voted on patch set 1 V -1 02/12/26, 07:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95688
-
Benjamin Franzke commented on patch set 1 02/12/26, 07:33
JavaScriptLanguageDomainController.php:60Replycontent length is about bytes, not (virtual) "character length", therefore `strlen` is correct here. -
Andreas Kienast commented on patch set 1 02/12/26, 07:37
JavaScriptLanguageDomainController.php:60ReplyAcknowledged -
Benjamin Franzke uploaded patch set 2
V -102/12/26, 08:10 -
core-ci voted on patch set 2 V +1 02/12/26, 08:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95691
-
Tobias Wojtylak commented on patch set 2 02/12/26, 08:52
language-domain-factory.ts:21is `get` really a good/verbose function name. How about using `translate`. The function does more then just return the value for a keyJavaScriptLanguageDomainController.php:60do we really need to set this manually?JavaScriptLanguageDomainController.php:62Don't we need conditional handling here? something like: `$etag = '"' . md5($javaScriptModuleContents) . '"'; if ($request->getHeaderLine('If-None-Match') === $etag) { return $this->responseFactory->createResponse(304) ->withHeader('ETag', $etag); } ` -
Tobias Wojtylak commented on patch set 2 V +1 02/12/26, 09:19
The proposed solution is definitely better than anything that is currently implemented 👍. What I don’t like is that JavaScript code is being constructed and returned in the JavaScriptLanguageDomainController. But that may be a personal preference I checked out and tested the code during the from-wizard rewrite. It worked perfectly. -
Benjamin Franzke uploaded patch set 3
V +102/12/26, 12:37 -
Benjamin Franzke uploaded patch set 4 02/12/26, 12:41
-
Benjamin Franzke uploaded patch set 5 02/12/26, 12:54
-
core-ci voted on patch set 4 V +1 02/12/26, 12:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95717
-
core-ci voted on patch set 5 V +1 02/12/26, 13:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95721
-
core-ci voted on patch set 3 V -1 02/12/26, 13:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95713
-
Benjamin Franzke uploaded patch set 6
V +102/12/26, 13:48 -
Benjamin Franzke commented on patch set 6 02/12/26, 13:48
language-domain-factory.ts:21ReplyThe translation already happened, we do only retrieve the translation. Therefore `get` fits better than an imperative `translate`. (We should not imply an action, when it is *always* a lookup).JavaScriptLanguageDomainController.php:60ReplyYes, we do not have a helper for that, We can add that in here later on: > 91599: [FEATURE] Add convenience ResponseFactory methods | https://review.typo3.org/c/Packages/TYPO3.CMS/+/91599JavaScriptLanguageDomainController.php:62ReplyThanks, I dropped this. ETag is not relevant, since we use far future caching anyway. -
Benjamin Franzke commented on patch set 6 02/12/26, 13:51
Reply
I made sure to * only generate the bare minimum, and only via JSON (to avoid writing own clever logic for escaping things) * all functionality is provided via the separate `@typo3/core/language-domain-factory.js` Therefore I think is ok/fine here. -
Benni Mack commented on patch set 6 02/12/26, 13:59
RequestHandler.php:83Any reason we need a dynamic listener registered?RequestHandler.php:120can't we move this out of the request handler?JavaScriptModules.php:60When introducing a new prefix (such as APP, PKG) I think we should document this for outsiders to understand that this is a special case. -
Tobias Wojtylak commented on patch set 6 02/12/26, 14:06
language-domain-factory.ts:21ReplyI disagree placeholders are also being replaced here, if I understand the code correctly. That`s more than just a simple get....JavaScriptLanguageDomainController.php:63```suggestion ->withHeader('Cache-Control', 'public, max-age=' . $lifetime) ``` Is there any reason for using private? -
Benjamin Franzke commented on patch set 6 02/12/26, 14:32
language-domain-factory.ts:21ReplyIt is still a lookup, I think `get()` is fine.JavaScriptLanguageDomainController.php:63ReplyPrivate is used to prevent Information disclosure (regarding installed extensions) in shared caches.RequestHandler.php:83ReplyThis should only be evaluated in backend context. For example frontend usage would require a different route. This is very similar to the `prefixWithSitePath` usecase, therefore I've added it here.RequestHandler.php:120ReplyIt is meant for backend requests only. We can, but I do not see a benefit, do you?JavaScriptModules.php:60ReplyThis is meant to be internal (the event is internal). -
core-ci voted on patch set 6 V +1 02/12/26, 14:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95739
-
Tobias Wojtylak commented on patch set 6 02/12/26, 14:56
I think we still have a problem with caching and language switching. When I change the language in the backend to de (it was previously en), I see the cached labels (en).
-
Benjamin Franzke commented on patch set 6 02/12/26, 15:04
Reply
yes, we need to trigger a reload in such (and other) cases. This topic is currently being worked on in the following patch, which is why I wanted to leave this out for now: > 92793: [BUGFIX] Reload backend after extension state changes | https://review.typo3.org/c/Packages/TYPO3.CMS/+/92793 But we can block this patch until that's implemented, fine by me. -
Benjamin Franzke commented on patch set 6 02/12/26, 15:28
Reply
Pushed in a separate patch for now: > 92823: [WIP][TASK] Refresh backend when language is changed | https://review.typo3.org/c/Packages/TYPO3.CMS/+/92823 but as mentioned, maybe it will be implemented via Oli's patch anyway. -
Benjamin Franzke commented on patch set 6 02/12/26, 15:33
RequestHandler.php:120ReplyI can move this and the dynamic listener to a middleware (I do not care), as written above, I've added it here for consistency with `prefixWithSitePath`. -
Benjamin Kott commented on patch set 6 CR +1 V +1 02/12/26, 23:14
i have no hard opinion on the request handler topic. the patch feels good and does what it should. -
Benjamin Kott commented on patch set 6 02/12/26, 23:16
language-domain-factory.ts:22yeah, maybe a @todo refactor would also be sufficient -
Benjamin Kott commented on patch set 6 02/12/26, 23:33
generate-label-types.js:43it could just generate workspaces.module.d.ts instead of putting it into folders -
Benjamin Franzke commented on patch set 6 CR -1 02/12/26, 23:34
language-domain-factory.ts:22Replyack, I wanted to remove it (was only for me), but forgot about it. I changed the bullshit part (used `any` before), so I'll remove it.generate-label-types.js:27@benjamin.kott@outlook.com suggested to use a `.d.ts` file instead of a folder here, which is indeed better, as we do not refer to a package, but a single module here. Will adapt.RequestHandler.php:120Replywill move into a middleware -
Benjamin Franzke uploaded patch set 7
CR +1V +102/13/26, 09:35 -
Benjamin Franzke commented on patch set 7 02/13/26, 09:35
Reply
Discussed with Benji to include it in here.language-domain-factory.ts:22ReplyDonelanguage-domain-factory.ts:21ReplyHope it is ok for you to keep get here, the reason is basically that we want something real short, as it is used often in templates… Terms like `translate` and `resolve` would be a bit too verbose.generate-label-types.js:27ReplyDoneJavaScriptLanguageDomainController.php:63ReplyHope it is ok to mark this as resolved. Feel free to untick, if you have further remarks.RequestHandler.php:83ReplyKept (at least for now), since I want to expose this only in backend requests for now (Information Disclosure).RequestHandler.php:120ReplyDone.JavaScriptModules.php:60ReplyAdded a note in here. -
Benjamin Franzke uploaded patch set 8 02/13/26, 09:36
-
core-ci voted on patch set 8 V +1 02/13/26, 09:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95813
-
Benjamin Kott uploaded patch set 9
V +102/13/26, 10:09 -
core-ci voted on patch set 7 V +1 02/13/26, 10:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95812
-
core-ci voted on patch set 9 V +1 02/13/26, 10:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95818
-
Tobias Wojtylak commented on patch set 8 02/13/26, 12:24
JavaScriptLanguageDomainController.php:63ReplyThe specification says: The "private" directive indicates that parts of the response message are intended for a **single user** [...] https://www.w3.org/Protocols/HTTP/Issues/cache-private.html In my opinion translation files that are the same for everyone like (other) assets. But I don’t really mind either, if you think private is the right choice, I’m fine with that.. -
Tobias Wojtylak commented on patch set 9 02/13/26, 12:36
label-provider.ts:21Is it a good idea to throw an error? JS might crash on missing label How about logging this error via console.error(`Missing label for key: ${key}`); and returning the key (or empty string) as fallback -
Benjamin Franzke commented on patch set 9 02/16/26, 07:10
label-provider.ts:21ReplyI think we made this mistake for too long, e.g. to resolve fallbacks when a label was missing. This often resulted in situations that labels could not be translated, because it always used the english fallback. A key-fallback would be even less-useful, since it would only show a label (which is rarely readable at all). Let's be strict for now, we can always get laxer if really needed (the other way around is always harder).JavaScriptLanguageDomainController.php:63Replyyup, from a user perspective it could be shared across all logged in users, but as this endpoint is currently *only* accessible for logged-in users, we do not want the data to be visible/retrievable for everyone from a shared cache. I basically want to prevent to introduce the following issue again: https://typo3.org/security/advisory/typo3-core-sa-2019-001 -
Benjamin Franzke uploaded patch set 10
V +102/16/26, 09:09 -
Tobias Wojtylak commented on patch set 9 02/16/26, 09:12
label-provider.ts:21ReplyStrictness is of course a good thing. However, if an error — for example in a lit template due to a missing string — results in the page no longer rendering properly and the user is left with a broken UI while only seeing an error in the console, then in my opinion we have a serious problem and a really bad user experience. This is my final comment on the matter. If this is indeed the intended behavior, then so be it. -
core-ci voted on patch set 10 V +1 02/16/26, 09:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95959
-
Andreas Nedbal voted on patch set 10 CR +1 V +1 02/16/26, 10:45
-
Benjamin Kott voted on patch set 10 CR +1 V +1 02/16/26, 13:45
-
Benjamin Franzke voted on patch set 10 CR +2 V +2 02/16/26, 13:53
-
Benjamin Franzke merged patch set 11 02/16/26, 13:53
-
Benjamin Franzke wrote 02/17/26, 18:11
Hashtag added: labels
JavaScriptLanguageDomainController.php:60