8000 refactor and extract language mapping to a self-contained private fun… · symfony/symfony@e546ec6 · GitHub
[go: up one dir, main page]

Skip to content

Commit e546ec6

Browse files
author
Peter Culka
committed
refactor and extract language mapping to a self-contained private function
1 parent 4b14ad5 commit e546ec6

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/Symfony/Component/Translation/Bridge/Crowdin/CrowdinProvider.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,7 @@ public function read(array $domains, array $locales): TranslatorBag
109109
$translatorBag = new TranslatorBag();
110110
$responses = [];
111111

112-
$localeLanguageMap = [];
113-
114-
foreach ($this->listLanguages() as $language) {
115-
if (\in_array($language['data']['locale'], $locales)) {
116-
$localeLanguageMap[$language['data']['locale']] = $language['data']['id'];
117-
}
118-
if (\in_array($language['data']['osxLocale'], $locales)) {
119-
// try an underscore locale version
120-
$localeLanguageMap[$language['data']['osxLocale']] = $language['data']['id'];
121-
}
122-
if (\in_array($language['data']['id'], $locales)) {
123-
// try fallback to language id
124-
$localeLanguageMap[$language['data']['id']] = $language['data']['id'];
125-
}
126-
}
127-
128-
if (\count($localeLanguageMap) !== \count($locales)) {
129-
$message = sprintf(
130-
'Unable to find all requested locales in Crowdin: "%s" not found.',
131-
implode(', ', array_diff($locales, array_keys($localeLanguageMap)))
132-
);
133-
$this->logger->error($message);
134-
throw new \InvalidArgumentException($message);
135-
}
112+
$localeLanguageMap = $this->mapLocalesToLanguageId($locales);
136113

137114
foreach ($domains as $domain) {
138115
$fileId = $this->getFileIdByDomain($fileList, $domain);
@@ -448,4 +425,32 @@ private function getFileList(): array
448425

449426
return $result;
450427
}
428+
429+
private function mapLocalesToLanguageId(array $locales): array
430+
{
431+
$localeLanguageMap = [];
432+
foreach ($this->listLanguages() as $language) {
433+
if (\in_array($language['data']['locale'], $locales)) {
434+
$localeLanguageMap[$language['data']['locale']] = $language['data']['id'];
435+
}
436+
if (\in_array($language['data']['osxLocale'], $locales)) {
437+
// try an underscore locale version
438+
$localeLanguageMap[$language['data']['osxLocale']] = $language['data']['id'];
439+
}
440+
if (\in_array($language['data']['id'], $locales)) {
441+
// try fallback to language id
442+
$localeLanguageMap[$language['data']['id']] = $language['data']['id'];
443+
}
444+
}
445+
446+
if (\count($localeLanguageMap) !== \count($locales)) {
447+
$message = sprintf(
448+
'Unable to find all requested locales in Crowdin: "%s" not found.',
449+
implode(', ', array_diff($locales, array_keys($localeLanguageMap)))
450+
);
451+
$this->logger->error($message);
452+
throw new \InvalidArgumentException($message);
453+
}
454+
return $localeLanguageMap;
455+
}
451456
}

0 commit comments

Comments
 (0)
0