#93334New syntax for labels
Description
The syntax for “LLL:” has several drawbacks
- It references a path (also uses EXT:) which makes it hard to override
- Changing label files is more error prone
- The paths are unnecessary longer (EXT:my_ext/Resources/Private/Language/locallang_.xlf) and it is confusing for newcomers to understand both the folder structure and the naming (what does “locallang” mean? or “LLL”?).
For this reason, I propose a more “speakable” approach, since we talk about “labels” in this case (not to be confused with “translations” in content).
What I want to address
- Making the syntax more consistent – find better solutions for “LLL:”
- Decouple the label identifier from the file name when addressing the label (making transitions from label names easier)
- Decouple the label identifier from an extension name + path
- Shorten the identifier massively for its usage
- Make it easier for people who CREATE such files to address.
A new syntax proposal (totally up for discussion)
“label://vendor.package.namespace/resource-name/identifier-in-resource”
Examples
Previously: LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general
New: label://typo3.core/form.tabs/general
Previously: LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:pages.tabs.metadata
New: label://typo3.core/tca/pages.tabs.metadata
For a TER extension: LLL:EXT:news/Resources/Private/Language/locallang.xlf:news.title
New: label://georgringer.news/default/news.title
For other extensions: LLL:EXT:my_ext/Resources/Private/Language/locallang_modules.xlf:my-module
New: label://a-random-namespace/modules/my-module
Usages
Fluid:
<f:translate identifier="label://a-random-namespace/modules/my-module">Fallback string</f:translate>
TypoScript:
page.10 = TEXT page.10.lang = label://my.site/resource/site-name
PHP:
$langService->label('label://my.site/resource/site-name')
So, under the hood this is what happens:
- A “LabelProviderService” contains all available files registered within the system
- The existing “languageService” gets extended to translate the new “label://” syntax into the actual resource + identifier
- The existing “languageService->label()” is added to make the syntax more understandable, and falls back if no “LLL:” or “label://” syntax is used
- For existing extensions, existing labels can be provided automatically by checking for Resources/Private/Language/locallang.xlf and registering with the composer-name syntax automatically, making any registration for language file very easy and consistent via a ServiceProvider during build-time.
Manual registration would be possible as well
LabelProvider->registerResource($pathToFile = '...', $namespace = 'my.site', $resourceName = 'default');
Backwards-compatibility
- We still allow “LLL:” for a LONG time (just like we keep GeneralUtility::makeInstance() until a long time)
Still up for discussion
- Overriding labels from extensions locally
- Dealing with translation server files
Reviews 18
- main 91191[BUGFIX] Allow new domain syntax for resourceOverrides
- 14.3 94616[BUGFIX] Allow new domain syntax for resourceOverrides
- 14.3 94374[BUGFIX] Use translation domain in EXT:linkvalidator mail template
- main 94340[BUGFIX] Use translation domain in EXT:linkvalidator mail template
- main 90389[FEATURE] Introduce translation domain shortcuts for XLF files
- main 92321[FEATURE] Allow adding inline language domains to JavaScript
- main 91919[BUGFIX] Use proper index for translation files added in cache-warmup to Symfony translator
- main 91942[BUGFIX] Properly resolve "english" XLIFF translation domain
- main 91567[BUGFIX] Enforce "_" over "-" in localization domain naming
- main 91129[FEATURE] TranslateViewHelper supports new Translation Domain syntax
- main 91370[TASK] Adapt translation domain in EXT:linkvalidator
- main 91344[TASK] Adapt translation domain in EXT:impexp
- main 91341[TASK] Adapt translation domain in EXT:filemetadata
- main 91270[TASK] Adapt translation domain in EXT:seo
- main 91320[TASK] Adapt translation domain in EXT:dashboard
- main 91066[FEATURE] Use translation domain mappings over LLL as simplified labels
- 13.4 91140[BUGFIX] Use proper labels in Redirects module
- main 91125[BUGFIX] Use proper labels in Redirects module
Related issues 13
- Task #107436Add symfony/translation component
- Task #107461Split Label File resolving into separate class
- Task #107789Utilize language domain mapping in TCA
- Task #107790Utilize language domain mapping in Modules.php
- Task #107843Move fallback handling into LocalizationFactory (thinning out LanguageService)
- Feature #107844Add new API over $GLOBALS[LANG]
- Task #107845Extend CLI command language:domain:list
- Bug #108058New translation domain mapper cannot handle dashes
- Task #108352Improve performance of Localization\LocalizationFactory::getMessageCatalogue to make cache:warmup faster
- Bug #108355Translation files in cache-warmup need proper index in Symfony translator
- Bug #108362LabelFileResolver::getOrderedFileResources adds every file to key en
- Bug #109962Translations missing at ValidatorTask mail from Linkvalidator
- Task #107759Utilize language domain mapping in extbase f:translate shorthand notation