You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
final class PortalLocale
|
|
{
|
|
public const ZH = 'zh-CN';
|
|
|
|
public const EN = 'en';
|
|
|
|
public const PORTAL_PARTICIPANT = 'participant';
|
|
|
|
public const PORTAL_AUDIENCE = 'audience';
|
|
|
|
public static function fromRequest(?string $lang): string
|
|
{
|
|
$value = strtolower(trim((string) $lang));
|
|
|
|
return $value === 'en' || $value === self::EN ? self::EN : self::ZH;
|
|
}
|
|
|
|
public static function isValid(string $locale): bool
|
|
{
|
|
return $locale === self::ZH || $locale === self::EN;
|
|
}
|
|
|
|
public static function choose(?string $lang, string $zh, string $en): string
|
|
{
|
|
return self::fromRequest($lang) === self::EN ? $en : $zh;
|
|
}
|
|
|
|
public static function invalidCodeMessage(?string $lang): string
|
|
{
|
|
return self::choose(
|
|
$lang,
|
|
'验证码无效或已过期',
|
|
'The verification code is invalid or has expired.',
|
|
);
|
|
}
|
|
|
|
public static function competitionMissingMessage(?string $lang): string
|
|
{
|
|
return self::choose(
|
|
$lang,
|
|
'赛事不存在或未发布',
|
|
'This competition is unavailable or unpublished.',
|
|
);
|
|
}
|
|
}
|