Skip to content

Commit

Permalink
GH-224 Move languages selector to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 26, 2022
1 parent 2b4475b commit b0bce6b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$includePath = $_EnginePath . 'modules/settings/';

include($includePath . './components/LanguageSelectorList/LanguageSelectorList.component.php');
include($includePath . './components/LoginHistoryEntry/LoginHistoryEntry.component.php');
include($includePath . './components/QuickTransportPlanetsList/QuickTransportPlanetsList.component.php');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace UniEngine\Engine\Modules\Settings\Components\LanguageSelectorList;

/**
* @param object $props
* @param number $props['currentUserLanguage']
*
* @return object $result
* @return string $result['componentHTML']
*/
function render($props) {
global $_Lang;

$currentUserLanguage = $props['currentUserLanguage'];

$localTemplateLoader = createLocalTemplateLoader(__DIR__);

$tplBodyCache = [
'optionBody' => $localTemplateLoader('optionBody'),
];
$availableLanguages = UNIENGINE_LANGS_AVAILABLE;

$options = array_map_withkeys(
$availableLanguages,
function ($langKey) use ($currentUserLanguage, &$_Lang, &$tplBodyCache) {
$langData = $_Lang['LanguagesAvailable'][$langKey];
$isSelectedHTMLAttr = ($langKey == $currentUserLanguage ? "selected" : "");

$tplParams = [
'langKey' => $langKey,
'isSelectedHTMLAttr' => $isSelectedHTMLAttr,
'langFlagEmoji' => $langData["flag_emoji"],
'langName' => $langData["name"],
];

return parsetemplate($tplBodyCache['optionBody'], $tplParams);
}
);

$componentHTML = implode('', $options);

return [
'componentHTML' => $componentHTML
];
}

?>
5 changes: 5 additions & 0 deletions modules/settings/components/LanguageSelectorList/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<option value='{langKey}' {isSelectedHTMLAttr}>
{langFlagEmoji} {langName}
</option>
15 changes: 3 additions & 12 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,10 @@
$_Lang['PHP_Insert_VacationMinDuration'] = $vacationMinSeconds;
$_Lang['PHP_Insert_VacationComeback'] = $Now + $vacationMinSeconds;
$_Lang['PHP_Insert_VacationComeback'] = date('d.m.Y', $_Lang['PHP_Insert_VacationComeback'])." {$_Lang['atHour']} ".date('H:i:s', $_Lang['PHP_Insert_VacationComeback']);
$_Lang['PHP_Insert_LanguageOptions'] = [];

foreach ($_Lang['LanguagesAvailable'] as $langKey => $langData) {
$isSelectedHTMLAttr = ($langKey == getCurrentLang() ? "selected" : "");

$_Lang['PHP_Insert_LanguageOptions'][] = (
"<option value='{$langKey}' {$isSelectedHTMLAttr}>" .
"{$langData["flag_emoji"]} {$langData["name"]}" .
"</option>"
);
}

$_Lang['PHP_Insert_LanguageOptions'] = implode('', $_Lang['PHP_Insert_LanguageOptions']);
$_Lang['PHP_Insert_LanguageOptions'] = Settings\Components\LanguageSelectorList\render([
'currentUserLanguage' => getCurrentLang(),
])['componentHTML'];

$ForceGoingOnVacationMsg = false;

Expand Down

0 comments on commit b0bce6b

Please sign in to comment.