diff options
author | Jonas Kohl | 2024-09-16 11:31:53 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-09-16 11:31:53 +0200 |
commit | 38f03c375eafdb6b95190729479c6fa0d721b400 (patch) | |
tree | 637616799ed5e20c72d8d7be7a78e72a11826cfa /src/application/i18n.php | |
parent | cb9b87997993702131ca24d4d0e1fd45ef64805c (diff) |
More i18n
Diffstat (limited to 'src/application/i18n.php')
-rw-r--r-- | src/application/i18n.php | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/application/i18n.php b/src/application/i18n.php index 964439f..2fcadab 100644 --- a/src/application/i18n.php +++ b/src/application/i18n.php @@ -6,8 +6,10 @@ $__i18n_msg_store = []; $__i18n_current_locale = null; function i18n_parse(string $contents, ?string $filename = null): array { - $syntax_error = fn(string $msg, ?int $line = null): never => - throw new Exception("i18n syntax error: $msg (in " . ($filename ?? "unknown") . ":" . ($line ?? 0) . ")"); + $syntax_error = fn(string $msg, int $line): never => + throw new Exception("i18n syntax error: $msg (in " . ($filename ?? "unknown") . ":" . $line . ")"); + $other_error = fn(string $msg, int $line): never => + throw new Exception("i18n error: $msg (in " . ($filename ?? "unknown") . ":" . $line . ")"); $msgs = []; $lines = explode("\n", $contents); @@ -27,7 +29,9 @@ function i18n_parse(string $contents, ?string $filename = null): array { if ($currentId !== "") { if ($currentContext !== "") $currentId = $currentContext . "\004" . $currentId; - $msgs[$currentId] ??= $currentMessage; + if (isset($msgs[$currentId])) + $other_error("duplicate message id '$currentId'", $lnNum); + $msgs[$currentId] = $currentMessage; } $currentId = json_decode(substr($ln, 2)); $currentContext = ""; @@ -58,7 +62,9 @@ function i18n_parse(string $contents, ?string $filename = null): array { if ($currentId !== "") { if ($currentContext !== "") $currentId = $currentContext . "\x7F" . $currentId; - $msgs[$currentId] ??= $currentMessage; + if (isset($msgs[$currentId])) + $other_error("duplicate message id '$currentId'", count($lines)); + $msgs[$currentId] = $currentMessage; } return $msgs; } |