-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-224 Move languages selector to a component
- Loading branch information
Showing
5 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
modules/settings/components/LanguageSelectorList/LanguageSelectorList.component.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
3 changes: 3 additions & 0 deletions
3
modules/settings/components/LanguageSelectorList/optionBody.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<option value='{langKey}' {isSelectedHTMLAttr}> | ||
{langFlagEmoji} {langName} | ||
</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters