mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 09:59: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) {
|
||||
global $LSlang_cli_logger;
|
||||
$LSlang_cli_logger -> debug("Looking for string to translate in '$file' template file");
|
||||
$count = 0;
|
||||
foreach(file($file) as $line) {
|
||||
$count ++;
|
||||
if (preg_match_all('/\{ *tr +msg=["\']([^\}]+)["\'] *\}/',$line,$matches)) {
|
||||
foreach($matches[1] as $t) {
|
||||
foreach(file($file) as $line_count => $line) {
|
||||
$line_count ++;
|
||||
if (preg_match_all('/\{ *tr +.*msg=(["\'])(?P<msg>[^"}]+)\1.*\}/', $line, $matches)) {
|
||||
foreach($matches["msg"] as $t) {
|
||||
$t = preg_replace('/[\'"]\|escape\:.*$/', '', $t);
|
||||
$LSlang_cli_logger -> trace(" - \"$t\" # Line $count");
|
||||
_cli_add_str_to_translate($t, _cli_absolute2relative_path($file).":$count");
|
||||
$LSlang_cli_logger -> trace(" - \"$t\" # Line $line_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
|
||||
*/
|
||||
function _cli_find_and_parse_template_file($dir) {
|
||||
global $LSlang_cli_logger;
|
||||
if (is_dir($dir)) {
|
||||
$LSlang_cli_logger -> debug("Looking for string to translate in template directory '$dir'");
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file=='.' || $file=='..') continue;
|
||||
if (is_dir($dir.'/'.$file)) {
|
||||
_cli_find_and_parse_template_file($dir.'/'.$file);
|
||||
if (is_dir("$dir/$file")) {
|
||||
_cli_find_and_parse_template_file("$dir/$file");
|
||||
}
|
||||
elseif (is_file($dir."/".$file) && preg_match('/\.tpl$/',$file)) {
|
||||
_cli_parse_template_file($dir.'/'.$file);
|
||||
_cli_parse_template_file("$dir/$file");
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
|
|
|
@ -705,7 +705,9 @@ function LStemplate_smarty_getFData($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) {
|
||||
|
|
Loading…
Reference in a new issue