From decb55b8ffb004400a71a93e8d3f555e3eeba22a Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Thu, 30 May 2024 02:39:19 +0300 Subject: [PATCH] Add support for storing replaced text values and keys #2176 https://github.com/webmin/authentic-theme/commit/9e0d4cd9b65e34ee944bfda397dd42982d1251cc --- web-lib-funcs.pl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index ae5fb6600..f78c83edc 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -5819,17 +5819,23 @@ else { =head2 text(message, [substitute]+) Returns a translated message from %text, but with $1, $2, etc.. replaced with -the substitute parameters. This makes it easy to use strings with placeholders -that get replaced with programmatically generated text. For example : +the substitute parameters. If called without parameters, returns a hash of +values and keys which were already replaced. +This makes it easy to use strings with placeholders that get replaced with +programmatically generated text. - print &text('index_hello', $remote_user),"

\n"; +For example: + print &text('index_hello', $remote_user),"\n"; =cut sub text { +state %text_replaced; +return %text_replaced if (!defined($_[0])); my $t = &get_module_variable('%text', 1); my $rv = exists($t->{$_[0]}) ? $t->{$_[0]} : $text{$_[0]}; $rv =~ s/\$(\d+)/$1 < @_ ? $_[$1] : '$'.$1/ge; +$text_replaced{$rv} = $_[0] if ($rv); return $rv; }