Skip to content

Commit 5700020

Browse files
mkiebelebmack
authored andcommitted
[TASK] Adapt translation domain in EXT:seo
This patch adjusts translation domains within EXT:seo to use the new syntax. In addition, the file is moved from locallang_tca.xlf to db.xlf with a fallback layer in place for this file if third-party extensions have referenced it, the reference is continuing to work. A small drive-by fix is made including tests for resolving the proper locale in LabelFileResolver.php for label files with only two letter in the file name (db.xlf for example) which was previously mistaken for being a locale, but is now correctly detected as a filename. Related: #93334 Resolves: #107855 Releases: main Change-Id: I35b44cc63597cfcd6625237c2fb5a60955873800 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/91270 Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Lina Wolf <112@linawolf.de> Reviewed-by: Lina Wolf <112@linawolf.de> Tested-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Garvin Hicking <garvin@hick.ing>
1 parent 22e36ea commit 5700020

File tree

5 files changed

+117
-32
lines changed

5 files changed

+117
-32
lines changed

typo3/sysext/core/Classes/Localization/LabelFileResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ public function getAllLabelFilesOfPackage(string $packageKey): array
9999
/**
100100
* If a file is called "de_AT.locallang.xlf", this method returns "de_AT".
101101
* If there is no suffix, NULL is returned.
102+
*
103+
* However, for files like "db.xlf", "db" should not be detected as locale
102104
*/
103105
public function getLocaleFromLanguageFile(string $fileName): ?string
104106
{
105-
if (preg_match('/^[a-z]{2}([_-][A-z]{2})?\./', $fileName)) {
107+
if (substr_count($fileName, '.') > 1 && preg_match('/^[a-z]{2}([_-][A-z]{2,3})?\./', $fileName)) {
106108
return substr($fileName, 0, strpos($fileName, '.'));
107109
}
108110
return null;

typo3/sysext/core/Classes/Localization/LocalizationFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
*/
4545
readonly class LocalizationFactory
4646
{
47+
protected const MOVED_FILES = [
48+
// @todo: remove the following files in TYPO3 v15.0, they serve as a fallback for old syntax and files that have been moved
49+
'EXT:seo/Resources/Private/Language/locallang_tca.xlf' => 'EXT:seo/Resources/Private/Language/db.xlf',
50+
];
51+
4752
public function __construct(
4853
protected Translator $translator,
4954
#[Autowire(service: 'cache.l10n')]
@@ -72,6 +77,12 @@ public function __construct(
7277
public function getParsedData(string $fileReference, string $languageKey): array
7378
{
7479
$languageKey = $languageKey === 'default' ? 'en' : $languageKey;
80+
81+
if (isset(self::MOVED_FILES[$fileReference])) {
82+
trigger_error('The file ' . $fileReference . ' has been moved to ' . self::MOVED_FILES[$fileReference] . '. Please update your code accordingly.', E_USER_DEPRECATED);
83+
$fileReference = self::MOVED_FILES[$fileReference];
84+
}
85+
7586
$fileReference = $this->translationDomainMapper->mapDomainToFileName($fileReference);
7687
$systemCacheIdentifier = md5($fileReference . $languageKey);
7788

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
namespace TYPO3\CMS\Core\Tests\Unit\Localization;
19+
20+
use PHPUnit\Framework\Attributes\DataProvider;
21+
use PHPUnit\Framework\Attributes\Test;
22+
use TYPO3\CMS\Core\Localization\LabelFileResolver;
23+
use TYPO3\CMS\Core\Package\PackageManager;
24+
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25+
26+
final class LabelFileResolverTest extends UnitTestCase
27+
{
28+
#[Test]
29+
#[DataProvider('getLocaleFromLanguageFileDataProvider')]
30+
public function getLocaleFromLanguageFileReturnsTheLocaleOnlyForValidResults(string $languageFile, ?string $expected): void
31+
{
32+
$subject = new LabelFileResolver(
33+
$this->createMock(PackageManager::class),
34+
);
35+
$result = $subject->getLocaleFromLanguageFile($languageFile);
36+
self::assertEquals($expected, $result);
37+
}
38+
39+
public static function getLocaleFromLanguageFileDataProvider(): array
40+
{
41+
return [
42+
'without locale' => [
43+
'languageFile' => 'locallang.xlf',
44+
'expected' => null,
45+
],
46+
'with locale' => [
47+
'languageFile' => 'de.locallang.xlf',
48+
'expected' => 'de',
49+
],
50+
'with language and region code' => [
51+
'languageFile' => 'de_AT.locallang.xlf',
52+
'expected' => 'de_AT',
53+
],
54+
'with language and three-letter region code' => [
55+
'languageFile' => 'en_AUS.locallang.xlf',
56+
'expected' => 'en_AUS',
57+
],
58+
'with language and invalid region code' => [
59+
'languageFile' => 'en_AUS.locallang.xlf',
60+
'expected' => 'en_AUS',
61+
],
62+
'simple prefix with two letters' => [
63+
'languageFile' => 'db.xlf',
64+
'expected' => null,
65+
],
66+
'simple prefix with two letters and language code' => [
67+
'languageFile' => 'de.db.xlf',
68+
'expected' => 'de',
69+
],
70+
];
71+
}
72+
}

typo3/sysext/seo/Configuration/TCA/Overrides/pages.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'disabled' => true,
1010
],
1111
'social' => [
12-
'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.crop_variant.social',
12+
'title' => 'core.wizards:imwizard.crop_variant.social',
1313
'coverAreas' => [],
1414
'cropArea' => [
1515
'x' => '0.0',
@@ -19,11 +19,11 @@
1919
],
2020
'allowedAspectRatios' => [
2121
'1.91:1' => [
22-
'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.191_1',
22+
'title' => 'core.wizards:imwizard.ratio.191_1',
2323
'value' => 1200 / 630,
2424
],
2525
'NaN' => [
26-
'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
26+
'title' => 'core.wizards:imwizard.ratio.free',
2727
'value' => 0.0,
2828
],
2929
],
@@ -37,11 +37,11 @@
3737
'palettes' => [
3838
'seo' => [
3939
'label' => 'core.form.palettes:seo',
40-
'showitem' => 'seo_title;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.seo_title',
40+
'showitem' => 'seo_title',
4141
],
4242
'robots' => [
4343
'label' => 'core.form.palettes:robots',
44-
'showitem' => 'no_index;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_index_formlabel, no_follow;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_follow_formlabel',
44+
'showitem' => 'no_index, no_follow',
4545
],
4646
'canonical' => [
4747
'label' => 'core.form.palettes:canonical',
@@ -64,7 +64,7 @@
6464
'seo_title' => [
6565
'exclude' => true,
6666
'l10n_mode' => 'prefixLangTitle',
67-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.seo_title',
67+
'label' => 'seo.db:pages.seo_title',
6868
'config' => [
6969
'type' => 'input',
7070
'size' => 40,
@@ -76,7 +76,7 @@
7676
'exclude' => true,
7777
'l10n_mode' => 'exclude',
7878
'onChange' => 'reload',
79-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_index_formlabel',
79+
'label' => 'seo.db:pages.no_index_formlabel',
8080
'config' => [
8181
'type' => 'check',
8282
'renderType' => 'checkboxToggle',
@@ -91,7 +91,7 @@
9191
'no_follow' => [
9292
'exclude' => true,
9393
'l10n_mode' => 'exclude',
94-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_follow_formlabel',
94+
'label' => 'seo.db:pages.no_follow_formlabel',
9595
'config' => [
9696
'type' => 'check',
9797
'renderType' => 'checkboxToggle',
@@ -105,26 +105,26 @@
105105
],
106106
'sitemap_changefreq' => [
107107
'exclude' => true,
108-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq',
108+
'label' => 'seo.db:pages.sitemap_changefreq',
109109
'config' => [
110110
'type' => 'select',
111111
'renderType' => 'selectSingle',
112112
'items' => [
113-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.none', 'value' => ''],
114-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.always', 'value' => 'always'],
115-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.hourly', 'value' => 'hourly'],
116-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.daily', 'value' => 'daily'],
117-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.weekly', 'value' => 'weekly'],
118-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.monthly', 'value' => 'monthly'],
119-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.yearly', 'value' => 'yearly'],
120-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_changefreq.never', 'value' => 'never'],
113+
['label' => 'seo.db:pages.sitemap_changefreq.none', 'value' => ''],
114+
['label' => 'seo.db:pages.sitemap_changefreq.always', 'value' => 'always'],
115+
['label' => 'seo.db:pages.sitemap_changefreq.hourly', 'value' => 'hourly'],
116+
['label' => 'seo.db:pages.sitemap_changefreq.daily', 'value' => 'daily'],
117+
['label' => 'seo.db:pages.sitemap_changefreq.weekly', 'value' => 'weekly'],
118+
['label' => 'seo.db:pages.sitemap_changefreq.monthly', 'value' => 'monthly'],
119+
['label' => 'seo.db:pages.sitemap_changefreq.yearly', 'value' => 'yearly'],
120+
['label' => 'seo.db:pages.sitemap_changefreq.never', 'value' => 'never'],
121121
],
122122
'dbFieldLength' => 10,
123123
],
124124
],
125125
'sitemap_priority' => [
126126
'exclude' => true,
127-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.sitemap_priority',
127+
'label' => 'seo.db:pages.sitemap_priority',
128128
'config' => [
129129
'type' => 'select',
130130
'renderType' => 'selectSingle',
@@ -146,23 +146,23 @@
146146
],
147147
'canonical_link' => [
148148
'exclude' => true,
149-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link',
150-
'description' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link.description',
149+
'label' => 'seo.db:pages.canonical_link',
150+
'description' => 'seo.db:pages.canonical_link.description',
151151
'displayCond' => 'FIELD:no_index:=:0',
152152
'config' => [
153153
'type' => 'link',
154154
'allowedTypes' => ['page', 'url', 'record'],
155155
'size' => 50,
156156
'appearance' => [
157-
'browserTitle' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link',
157+
'browserTitle' => 'seo.db:pages.canonical_link',
158158
'allowedOptions' => ['params', 'rel'],
159159
],
160160
],
161161
],
162162
'og_title' => [
163163
'exclude' => true,
164164
'l10n_mode' => 'prefixLangTitle',
165-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.og_title',
165+
'label' => 'seo.db:pages.og_title',
166166
'config' => [
167167
'type' => 'input',
168168
'size' => 40,
@@ -173,7 +173,7 @@
173173
'og_description' => [
174174
'exclude' => true,
175175
'l10n_mode' => 'prefixLangTitle',
176-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.og_description',
176+
'label' => 'seo.db:pages.og_description',
177177
'config' => [
178178
'type' => 'text',
179179
'cols' => 40,
@@ -182,7 +182,7 @@
182182
],
183183
'og_image' => [
184184
'exclude' => true,
185-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.og_image',
185+
'label' => 'seo.db:pages.og_image',
186186
'config' => [
187187
'type' => 'file',
188188
'allowed' => 'common-image-types',
@@ -199,7 +199,7 @@
199199
'twitter_title' => [
200200
'exclude' => true,
201201
'l10n_mode' => 'prefixLangTitle',
202-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.twitter_title',
202+
'label' => 'seo.db:pages.twitter_title',
203203
'config' => [
204204
'type' => 'input',
205205
'size' => 40,
@@ -210,7 +210,7 @@
210210
'twitter_description' => [
211211
'exclude' => true,
212212
'l10n_mode' => 'prefixLangTitle',
213-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.twitter_description',
213+
'label' => 'seo.db:pages.twitter_description',
214214
'config' => [
215215
'type' => 'text',
216216
'cols' => 40,
@@ -219,7 +219,7 @@
219219
],
220220
'twitter_image' => [
221221
'exclude' => true,
222-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.twitter_image',
222+
'label' => 'seo.db:pages.twitter_image',
223223
'config' => [
224224
'type' => 'file',
225225
'allowed' => 'common-image-types',
@@ -235,15 +235,15 @@
235235
],
236236
'twitter_card' => [
237237
'exclude' => true,
238-
'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.twitter_card',
238+
'label' => 'seo.db:pages.twitter_card',
239239
'config' => [
240240
'type' => 'select',
241241
'renderType' => 'selectSingle',
242242
'default' => '',
243243
'items' => [
244244
['label' => '', 'value' => ''],
245-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.twitter_card.summary', 'value' => 'summary'],
246-
['label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.twitter_card.summary_large_image', 'value' => 'summary_large_image'],
245+
['label' => 'seo.db:pages.twitter_card.summary', 'value' => 'summary'],
246+
['label' => 'seo.db:pages.twitter_card.summary_large_image', 'value' => 'summary_large_image'],
247247
],
248248
'dbFieldLength' => 255,
249249
],

typo3/sysext/seo/Resources/Private/Language/locallang_tca.xlf renamed to typo3/sysext/seo/Resources/Private/Language/db.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3-
<file source-language="en" datatype="plaintext" original="EXT:seo/Resources/Private/Language/locallang_tca.xlf" date="2018-08-09T16:22:32Z"
3+
<file source-language="en" datatype="plaintext" original="EXT:seo/Resources/Private/Language/db.xlf" date="2018-08-09T16:22:32Z"
44
product-name="seo">
55
<header/>
66
<body>

0 commit comments

Comments
 (0)