• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / Yoast-SEO-for-TYPO3 / 21521134747

30 Jan 2026 03:30PM UTC coverage: 0.866% (-0.4%) from 1.275%
21521134747

push

github

RinyVT
[FEATURE] Version 12.0.0, added v14 support, removed v11 support including php8.0 and php8.1, rewrote backend javascript functionality to typescript and webcomponents

0 of 550 new or added lines in 53 files covered. (0.0%)

33 existing lines in 21 files now uncovered.

23 of 2657 relevant lines covered (0.87%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/Service/LocaleService.php
1
<?php
2

3
/**
4
 * This file is part of the "yoast_seo" extension for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9

10
declare(strict_types=1);
11

12
namespace YoastSeoForTypo3\YoastSeo\Service;
13

14
use TYPO3\CMS\Core\Localization\Locales;
15
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use YoastSeoForTypo3\YoastSeo\Traits\BackendUserTrait;
18
use YoastSeoForTypo3\YoastSeo\Traits\LanguageServiceTrait;
19

20
class LocaleService
21
{
22
    use BackendUserTrait;
23
    use LanguageServiceTrait;
24

25
    protected const APP_TRANSLATION_FILE_PATTERN = 'EXT:yoast_seo/Resources/Private/Language/wordpress-seo-%s.json';
26

27
    public function __construct(
28
        protected Locales $locales,
29
        protected SiteService $siteService
30
    ) {}
×
31

32
    /**
33
     * @return array<string, array<string, string>>
34
     */
35
    public function getTranslations(): array
36
    {
37
        $interfaceLocale = $this->getInterfaceLocale();
×
38

39
        if ($interfaceLocale === null) {
×
40
            // Fall back to English if no suitable locale could be resolved to prevent missing translations
41
            $interfaceLocale = 'en_GB';
×
42
        }
43

44
        $translationFilePath = GeneralUtility::getFileAbsFileName(
×
45
            sprintf(static::APP_TRANSLATION_FILE_PATTERN, $interfaceLocale)
×
46
        );
×
47

48
        if ($translationFilePath === '' || !file_exists($translationFilePath)) {
×
49
            return [];
×
50
        }
51

52
        if ($jsonContents = file_get_contents($translationFilePath)) {
×
53
            return json_decode($jsonContents, true);
×
54
        }
55

56
        return [];
×
57
    }
58

59
    /**
60
     * Try to resolve a supported locale based on the user settings
61
     * take the configured locale dependencies into account
62
     * so if the TYPO3 interface is tailored for a specific dialect
63
     * the local of a parent language might be used
64
     *
65
     * @return string|null
66
     */
67
    protected function getInterfaceLocale(): ?string
68
    {
69
        $locale = null;
×
70

71
        $translationConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['translations'] ?? [
×
72
            'availableLocales' => [],
×
73
            'languageKeyToLocaleMapping' => [],
×
74
        ];
×
75

76
        $userLanguage = $this->getBackendUser()->user['lang'] ?? '';
×
77
        if (empty($userLanguage) || $userLanguage === 'default') {
×
78
            $userLanguage = 'en';
×
79
        }
80

81
        $languageChain = $this->locales->getLocaleDependencies($userLanguage);
×
82
        array_unshift($languageChain, $userLanguage);
×
83

84
        // try to find a matching locale available for this plugins UI
85
        // take configured locale dependencies into account
86
        if ($languageChain !== null) {
×
87
            $suitableLocales = array_intersect(
×
88
                $languageChain,
×
89
                $translationConfiguration['availableLocales']
×
90
            );
×
91
            if (count($suitableLocales) > 0) {
×
92
                $locale = array_shift($suitableLocales);
×
93
            }
94
        }
95

96
        // if a locale couldn't be resolved try if an entry of the
97
        // language dependency chain matches legacy mapping
98
        if ($locale === null && $languageChain !== null) {
×
99
            $suitableLanguageKeys = array_intersect(
×
100
                $languageChain,
×
101
                array_flip(
×
102
                    $translationConfiguration['languageKeyToLocaleMapping']
×
103
                )
×
104
            );
×
105
            if (count($suitableLanguageKeys) > 0) {
×
106
                $locale = $translationConfiguration['languageKeyToLocaleMapping'][array_shift($suitableLanguageKeys)];
×
107
            }
108
        }
109

110
        return $locale;
×
111
    }
112

113
    public function getLocale(int $pageId, int &$languageId): ?string
114
    {
NEW
115
        $site = $this->siteService->getSiteByPageId($pageId);
×
NEW
116
        if ($site === null) {
×
UNCOV
117
            return null;
×
118
        }
119

NEW
120
        if ($languageId === -1) {
×
NEW
121
            $languageId = $site->getDefaultLanguage()->getLanguageId();
×
NEW
122
            return $this->getLanguageCode($site->getDefaultLanguage());
×
123
        }
NEW
124
        return $this->getLanguageCode($site->getLanguageById($languageId));
×
125
    }
126

127
    protected function getLanguageCode(SiteLanguage $siteLanguage): string
128
    {
UNCOV
129
        return $siteLanguage->getLocale()->getLanguageCode();
×
130
    }
131

132
    /**
133
     * @param array<string, mixed> $data
134
     */
135
    public function getLanguageIdFromData(array $data): int
136
    {
137
        if (!isset($data['databaseRow']['sys_language_uid'])) {
×
138
            return 0;
×
139
        }
140

141
        if (is_array($data['databaseRow']['sys_language_uid']) && count($data['databaseRow']['sys_language_uid']) > 0) {
×
142
            return (int)current($data['databaseRow']['sys_language_uid']);
×
143
        }
144
        return (int)$data['databaseRow']['sys_language_uid'];
×
145
    }
146

147
    /**
148
     * @return array<int, string>
149
     */
150
    public function getSupportedLanguages(): array
151
    {
152
        return $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['supportedLanguages'] ?? [];
×
153
    }
154
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc