Skip to content

Commit

Permalink
Merge pull request #37 from tollwerk/develop
Browse files Browse the repository at this point in the history
Fix language / locale usage
  • Loading branch information
jkphl authored Sep 11, 2020
2 parents add0d45 + 4869f8a commit 9e1e9ce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions Classes/Utility/TcaUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
class TcaUtility
{
/**
* Supported languages
* Supported locales
*
* SELECT CONCAT(`lg_name_local`, " (", lg_name_en, ")") AS label, IF(lg_collate_locale = "", LOWER(lg_iso_2),
* lg_collate_locale) AS iso FROM `static_languages` ORDER BY lg_name_en ASC
*
* @var array
*/
public static $languages = [
public static $locales = [
['LLL:EXT:tw_base/Resources/Private/Language/locallang_db.xlf:pages.tx_twbase_title_language.auto', ''],
['Аҧсуа бызшәа (Abkhazian)', 'ab'],
['Afaraf (Afar)', 'aa'],
Expand Down Expand Up @@ -253,14 +253,25 @@ class TcaUtility
['isiZulu (Zulu)', 'zu']
];

/**
* Extract a list language subtags from the locales
*
* @return array[] languages
*/
public static function languages(): array {
return array_map(function(array $locale){
return [$locale[0], strtok($locale[1], '_')];
}, self::$locales);
}

/**
* Add track languages
*
* @param array $config
*/
public function trackLanguages(array &$config)
{
$config['items'] = self::$languages;
$config['items'] = self::languages();
unset($config['items'][0]);
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/LanguageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function renderStatic(
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
foreach (TcaUtility::$languages as $language) {
foreach (TcaUtility::languages() as $language) {
if ($arguments['identifier'] == $language[1]) {
return $language[0];
}
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => \Tollwerk\TwBase\Utility\TcaUtility::$languages,
'items' => \Tollwerk\TwBase\Utility\TcaUtility::languages(),
'size' => 1,
'minitems' => 0,
'maxitems' => 1
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => \Tollwerk\TwBase\Utility\TcaUtility::$languages,
'items' => \Tollwerk\TwBase\Utility\TcaUtility::languages(),
'size' => 1,
'minitems' => 0,
'maxitems' => 1
Expand Down

0 comments on commit 9e1e9ce

Please sign in to comment.