Skip to content

Commit

Permalink
validate locale
Browse files Browse the repository at this point in the history
  • Loading branch information
darcywong00 committed Dec 11, 2024
1 parent 82c5a54 commit e4fb670
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions _includes/locale/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public static function currentLocale() {
}

/**
* Override the current locale
* Validate and override the current locale
* @param $locale - the new current locale (xx-YY as specified in crowdin %locale%)
*/
public static function overrideCurrentLocale($locale) {
Locale::$currentLocale = $locale;
if (Locale::validateLocale($locale)) {
Locale::$currentLocale = $locale;
}
}

/**
Expand All @@ -32,7 +34,11 @@ public static function overrideCurrentLocale($locale) {
* @return true if valid locale
*/
public static function validateLocale($locale) {
if(preg_match('/^[[:alpha:]]{2,3}(-[[:alpha:]]{2,3})?$/i', $locale)) {
return true;
}

return false;
}

/**
Expand Down

0 comments on commit e4fb670

Please sign in to comment.