summaryrefslogtreecommitdiff
path: root/src/application/i18n.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/application/i18n.php')
-rw-r--r--src/application/i18n.php14
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;
}