i18n: Implement getAllCultures

This commit is contained in:
loblao 2016-09-05 10:40:30 -03:00 committed by Alex Grintsvayg
parent 5539860a0a
commit 0c9e7724af
3 changed files with 15 additions and 5 deletions

View file

@ -10,10 +10,10 @@ class i18nActions extends Actions
{ {
public static function setCulture() public static function setCulture()
{ {
$culture = isset($_POST['culture']) ? $_POST['culture'] : null; $culture = $_POST['culture'] ?? null;
// Validate // Validate
if ($culture && !($culture == 'en_US' || $culture == 'pt_PT')) if ($culture && !in_array($culture, i18n::getAllCultures()))
{ {
$culture = null; $culture = null;
} }

View file

@ -13,7 +13,8 @@ class i18n
protected static protected static
$language = null, $language = null,
$translations = [], $translations = [],
$country = null; $country = null,
$cultures = ['pt_PT', 'en_US'];
public static function register($culture = null) /*needed to trigger class include, presumably setup would happen here*/ public static function register($culture = null) /*needed to trigger class include, presumably setup would happen here*/
{ {
@ -56,6 +57,11 @@ class i18n
return static::$country; return static::$country;
} }
public static function getAllCultures()
{
return static::$cultures;
}
public static function formatCurrency($amount, $currency = 'USD') public static function formatCurrency($amount, $currency = 'USD')
{ {
return '<span class="formatted-currency">' . money_format('%.2n', $amount) . '</span>'; return '<span class="formatted-currency">' . money_format('%.2n', $amount) . '</span>';

View file

@ -25,8 +25,12 @@
<div class="control-item no-label-desktop"> <div class="control-item no-label-desktop">
<form id="language-form" action="/set-culture" method="POST"> <form id="language-form" action="/set-culture" method="POST">
<select id="language-dropdown" name="culture"> <select id="language-dropdown" name="culture">
<option>en_US</option> <?php
<option>pt_PT</option> foreach (i18n::getAllCultures() as $culture)
{
echo "<option>$culture</option>";
}
?>
</select> </select>
</form> </form>
</div> </div>