diff options
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); } |