diff options
| author | Jonas Kohl | 2024-09-16 19:32:09 +0200 | 
|---|---|---|
| committer | Jonas Kohl | 2024-09-16 19:32:09 +0200 | 
| commit | 6b7e714b59e28bc138681662006941274c3261af (patch) | |
| tree | c683082c0a00681542db02d415bd45968f0a517b /src/application/i18n.php | |
| parent | fd3d969cf658475709db6a1e5090069cce51cbbd (diff) | |
A lot more stuff
Diffstat (limited to 'src/application/i18n.php')
| -rw-r--r-- | src/application/i18n.php | 26 | 
1 files changed, 24 insertions, 2 deletions
| diff --git a/src/application/i18n.php b/src/application/i18n.php index f5b755d..cdc61e1 100644 --- a/src/application/i18n.php +++ b/src/application/i18n.php @@ -9,7 +9,8 @@ const MESSAGE_DIR = __DIR__ . "/messages";  $__i18n_msg_store = [];  $__i18n_msg_store_plural = [];  $__i18n_msg_metadata = []; -$__i18n_current_locale = null; +/** @var string $__i18n_current_locale */ +$__i18n_current_locale = "en";  const _I18N_MSGID = 0;  const _I18N_MSGSTR = 1; @@ -200,7 +201,7 @@ function i18n_get_plural(string $msgid_singular, string $msgid_plural, int $coun          $ctx->def("n", $count);          $parser = new Parser(new Scanner($expression));          $index = $parser->reduce($ctx); -        $index = max(0, min(count($msgs), $index)); +        $index = max(0, min(count($msgs) - 1, $index));          $msg = $msgs[$index];      } @@ -212,6 +213,27 @@ function i18n_get_plural(string $msgid_singular, string $msgid_plural, int $coun      );  } +function i18n_get_current_locale(): string { +    global $__i18n_current_locale; +    return $__i18n_current_locale; +} + +function i18n_get_available_locales(): array { +    global $__i18n_msg_store; +    return [ +        "en", +        ...array_keys($__i18n_msg_store), +    ]; +} + +function i18n_get_message_store(string $locale): array { +    global $__i18n_msg_store, $__i18n_msg_store_plural; +    return [ +        $__i18n_msg_store[$locale] ?? (object)[], +        $__i18n_msg_store_plural[$locale] ?? (object)[], +    ]; +} +  function __(string $msgid, array $params = [], ?string $context = null): string {      return i18n_get($msgid, $params, $context);  } |