mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 18:09:06 +01:00
Templating tr function: provided message could now be formated as LSformat string using extra provided parameters
Example: {tr msg="Hello %(who)!" who="World"}
This commit is contained in:
parent
087b7e3065
commit
65d1d50c3a
2 changed files with 14 additions and 11 deletions
|
@ -499,14 +499,13 @@ function _cli_add_possible_values_from_LSconfig($context, $withouts, $level=0) {
|
||||||
function _cli_parse_template_file($file) {
|
function _cli_parse_template_file($file) {
|
||||||
global $LSlang_cli_logger;
|
global $LSlang_cli_logger;
|
||||||
$LSlang_cli_logger -> debug("Looking for string to translate in '$file' template file");
|
$LSlang_cli_logger -> debug("Looking for string to translate in '$file' template file");
|
||||||
$count = 0;
|
foreach(file($file) as $line_count => $line) {
|
||||||
foreach(file($file) as $line) {
|
$line_count ++;
|
||||||
$count ++;
|
if (preg_match_all('/\{ *tr +.*msg=(["\'])(?P<msg>[^"}]+)\1.*\}/', $line, $matches)) {
|
||||||
if (preg_match_all('/\{ *tr +msg=["\']([^\}]+)["\'] *\}/',$line,$matches)) {
|
foreach($matches["msg"] as $t) {
|
||||||
foreach($matches[1] as $t) {
|
|
||||||
$t = preg_replace('/[\'"]\|escape\:.*$/', '', $t);
|
$t = preg_replace('/[\'"]\|escape\:.*$/', '', $t);
|
||||||
$LSlang_cli_logger -> trace(" - \"$t\" # Line $count");
|
$LSlang_cli_logger -> trace(" - \"$t\" # Line $line_count");
|
||||||
_cli_add_str_to_translate($t, _cli_absolute2relative_path($file).":$count");
|
_cli_add_str_to_translate($t, _cli_absolute2relative_path($file).":$line_count");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,15 +519,17 @@ function _cli_parse_template_file($file) {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _cli_find_and_parse_template_file($dir) {
|
function _cli_find_and_parse_template_file($dir) {
|
||||||
|
global $LSlang_cli_logger;
|
||||||
if (is_dir($dir)) {
|
if (is_dir($dir)) {
|
||||||
|
$LSlang_cli_logger -> debug("Looking for string to translate in template directory '$dir'");
|
||||||
if ($dh = opendir($dir)) {
|
if ($dh = opendir($dir)) {
|
||||||
while (($file = readdir($dh)) !== false) {
|
while (($file = readdir($dh)) !== false) {
|
||||||
if ($file=='.' || $file=='..') continue;
|
if ($file=='.' || $file=='..') continue;
|
||||||
if (is_dir($dir.'/'.$file)) {
|
if (is_dir("$dir/$file")) {
|
||||||
_cli_find_and_parse_template_file($dir.'/'.$file);
|
_cli_find_and_parse_template_file("$dir/$file");
|
||||||
}
|
}
|
||||||
elseif (is_file($dir."/".$file) && preg_match('/\.tpl$/',$file)) {
|
elseif (is_file($dir."/".$file) && preg_match('/\.tpl$/',$file)) {
|
||||||
_cli_parse_template_file($dir.'/'.$file);
|
_cli_parse_template_file("$dir/$file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($dh);
|
closedir($dh);
|
||||||
|
|
|
@ -705,7 +705,9 @@ function LStemplate_smarty_getFData($params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function LStemplate_smarty_tr($params) {
|
function LStemplate_smarty_tr($params) {
|
||||||
echo __($params['msg']);
|
$msg = __($params['msg']);
|
||||||
|
unset($params['msg']);
|
||||||
|
echo $params?getFData($msg, $params):$msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function LStemplate_smarty_img($params) {
|
function LStemplate_smarty_img($params) {
|
||||||
|
|
Loading…
Reference in a new issue