Project

General

Profile

Actions

Feature #93334

open

New syntax for labels

Added by Benni Mack almost 4 years ago. Updated 10 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Localization
Target version:
-
Start date:
2021-01-21
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

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
Actions

Also available in: Atom PDF