Skip to content

Commit b707155

Browse files
authored
Merge pull request #2089 from simplesamlphp/feature/symfony-intl
Remove Languages::$languages_names and use symfony instead
2 parents 68d8c5d + 8dc347e commit b707155

File tree

3 files changed

+8
-62
lines changed

3 files changed

+8
-62
lines changed

bin/translateAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
$attributes = [];
3434

35-
$languages = SimpleSAML\Locale\Language::$language_names;
35+
$languages = Symfony\Component\Intl\Languages::getNames();
3636
$languages['nb'] = $languages['no'];
3737
unset($languages['no']);
3838

src/SimpleSAML/Locale/Language.php

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace SimpleSAML\Locale;
1212

1313
use SimpleSAML\{Configuration, Logger, Utils};
14+
use Symfony\Component\Intl\Languages;
1415

1516
use function array_fill_keys;
1617
use function array_key_exists;
@@ -77,61 +78,6 @@ class Language
7778
*/
7879
private $customFunction;
7980

80-
/**
81-
* A list of languages supported with their names localized.
82-
* Indexed by something that mostly resembles ISO 639-1 code,
83-
* with some charming SimpleSAML-specific variants...
84-
* that must remain before 2.0 due to backwards compatibility
85-
*
86-
* @var array<string, string>
87-
*/
88-
public static array $language_names = [
89-
'no' => 'Bokmål', // Norwegian Bokmål
90-
'nn' => 'Nynorsk', // Norwegian Nynorsk
91-
'se' => 'Sámegiella', // Northern Sami
92-
'sma' => 'Åarjelh-saemien giele', // Southern Sami
93-
'da' => 'Dansk', // Danish
94-
'en' => 'English',
95-
'de' => 'Deutsch', // German
96-
'sv' => 'Svenska', // Swedish
97-
'fi' => 'Suomeksi', // Finnish
98-
'es' => 'Español', // Spanish
99-
'ca' => 'Català', // Catalan
100-
'fr' => 'Français', // French
101-
'it' => 'Italiano', // Italian
102-
'nl' => 'Nederlands', // Dutch
103-
'lb' => 'Lëtzebuergesch', // Luxembourgish
104-
'cs' => 'Čeština', // Czech
105-
'sl' => 'Slovenščina', // Slovensk
106-
'lt' => 'Lietuvių kalba', // Lithuanian
107-
'hr' => 'Hrvatski', // Croatian
108-
'hu' => 'Magyar', // Hungarian
109-
'pl' => 'Język polski', // Polish
110-
'pt' => 'Português', // Portuguese
111-
'pt-br' => 'Português brasileiro', // Portuguese
112-
'ru' => 'русский язык', // Russian
113-
'et' => 'eesti keel', // Estonian
114-
'tr' => 'Türkçe', // Turkish
115-
'el' => 'ελληνικά', // Greek
116-
'ja' => '日本語', // Japanese
117-
'zh' => '简体中文', // Chinese (simplified)
118-
'zh-tw' => '繁體中文', // Chinese (traditional)
119-
'ar' => 'العربية', // Arabic
120-
'fa' => 'پارسی', // Persian
121-
'ur' => 'اردو', // Urdu
122-
'he' => 'עִבְרִית', // Hebrew
123-
'id' => 'Bahasa Indonesia', // Indonesian
124-
'sr' => 'Srpski', // Serbian
125-
'lv' => 'Latviešu', // Latvian
126-
'ro' => 'Românește', // Romanian
127-
'eu' => 'Euskara', // Basque
128-
'af' => 'Afrikaans', // Afrikaans
129-
'zu' => 'IsiZulu', // Zulu
130-
'xh' => 'isiXhosa', // Xhosa
131-
'st' => 'Sesotho', // Sesotho
132-
'sk' => 'Slovenčina', // Slovak
133-
];
134-
13581
/**
13682
* A mapping of SSP languages to locales
13783
*
@@ -168,7 +114,7 @@ public function __construct(
168114
/**
169115
* Filter configured (available) languages against installed languages.
170116
*
171-
* @return string[] The set of languages both in 'language.available' and self::$language_names.
117+
* @return string[] The set of languages both in 'language.available' and Languages::getNames().
172118
*/
173119
private function getInstalledLanguages(): array
174120
{
@@ -178,12 +124,13 @@ private function getInstalledLanguages(): array
178124
);
179125
$availableLanguages = [];
180126
foreach ($configuredAvailableLanguages as $code) {
181-
if (array_key_exists($code, self::$language_names) && isset(self::$language_names[$code])) {
127+
if (Languages::exists($code)) {
182128
$availableLanguages[] = $code;
183129
} else {
184130
Logger::error("Language \"$code\" not installed. Check config.");
185131
}
186132
}
133+
187134
return $availableLanguages;
188135
}
189136

@@ -272,8 +219,8 @@ public function getLanguage(): string
272219
*/
273220
public function getLanguageLocalizedName(string $code): ?string
274221
{
275-
if (array_key_exists($code, self::$language_names) && isset(self::$language_names[$code])) {
276-
return self::$language_names[$code];
222+
if (Languages::exists($code)) {
223+
return Languages::getName($code);
277224
}
278225
Logger::error("Name for language \"$code\" not found. Check config.");
279226
return null;

tests/src/SimpleSAML/Locale/LanguageTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public function testGetLanguageListNoConfig(): void
7676
*/
7777
public function testGetLanguageListCorrectConfig(): void
7878
{
79-
// test langs from from language_names
8079
$c = Configuration::loadFromArray([
8180
'language.available' => ['en', 'nn', 'es'],
8281
], '', 'simplesaml');
@@ -97,7 +96,7 @@ public function testGetLanguageListIncorrectConfig(): void
9796
{
9897
// test non-existent langs
9998
$c = Configuration::loadFromArray([
100-
'language.available' => ['foo', 'bar'],
99+
'language.available' => ['foo', 'baz'],
101100
], '', 'simplesaml');
102101
$l = new Language($c);
103102
$l->setLanguage('foo');

0 commit comments

Comments
 (0)