Nav: Add a (temporary) dropdown to allow user to change language

This commit is contained in:
loblao 2016-09-03 11:47:26 -03:00 committed by Alex Grintsvayg
parent e0b3d0921a
commit b30a7c0708
4 changed files with 56 additions and 2 deletions

View file

@ -94,6 +94,8 @@ class Controller
$router->any('/list/subscribe', 'MailActions::executeSubscribe');
$router->get('/list/confirm/{hash}', 'MailActions::executeConfirm');
$router->post('/language', 'i18nActions::setCulture');
$permanentRedirects = [
'/lbry-osx-latest.dmg' => '/get',
'/lbry-linux-latest.deb' => '/get',

View file

@ -0,0 +1,33 @@
<?php
/**
* Description of i18nActions
*
* @author Nacib Neme
*/
class i18nActions extends Actions
{
public static function setCulture()
{
$culture = isset($_POST['culture']) ? $_POST['culture'] : null;
// Validate
if ($culture && !($culture == 'en_US' || $culture == 'pt_PT'))
{
$culture = null;
}
if ($culture)
{
Session::set(Session::KEY_USER_CULTURE, $culture);
}
else
{
Session::unsetKey(Session::KEY_USER_CULTURE);
}
return [null, null];
}
}

View file

@ -21,4 +21,14 @@
</div>
<div class="control-item no-label-desktop">
<a href="https://github.com/lbryio"><span class="btn-label">GitHub</span><span class="icon-github icon-fw"></span></a>
</div>
</div>
<div class="control-item no-label-desktop">
<select id="language-dropdown">
<option>en_US</option>
<option>pt_PT</option>
</select>
</div>
<script type="text/javascript">
var _currentLang = '<?php echo i18n::getLanguage()."_".i18n::getCountry() ?>';
</script>

View file

@ -162,4 +162,13 @@ $(document).ready(function() {
});
});
}
});
var langDropdown = $('#language-dropdown');
langDropdown.val(_currentLang);
langDropdown.on('change', function(x) {
$.ajax({type: 'POST', url: '/language', data: {'culture': this.value},
success: function (d) {
window.location.reload();
}});
});
});