private function replaceContext(string $format, array $context): string {
        $msg = preg_replace_callback('`({[^\s{}]+})`', function ($m) use ($context) {
            $field = trim($m[1], '{}');
            if (array_key_exists($field, $context)) {
                return $context[$field];
            } else {
                return $m[1];
            }
        }, $format);
        return $msg;
    }