mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 08:19:05 +01:00
Rework/improve generate_lang_file.php / generate_ldapsaisie.pot.sh scripts
This commit is contained in:
parent
b3f208aa60
commit
30daa59c8e
7 changed files with 1544 additions and 1099 deletions
|
@ -54,11 +54,17 @@ class LSconfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Récupération d'une valeur
|
||||
* Get a specific configuration variable value
|
||||
*
|
||||
* @param[in] $var string Le nom de valeur à récupérer (Exemple : cacheSearch)
|
||||
* @param[in] $var string The configuration variable name
|
||||
* @param[in] $default mixed The default value to return if configuration variable
|
||||
* is not set (Default : null)
|
||||
* @param[in] $cast string The type of expected value. The configuration variable
|
||||
* value will be cast as this type. Could be : bool, int,
|
||||
* float or string. (Optional, default : raw value)
|
||||
* @param[in] $data array The configuration data (optional)
|
||||
*
|
||||
* @retval mixed La valeur de la variable, ou false si son nom n'est parsable
|
||||
* @retval mixed The configuration variable value
|
||||
**/
|
||||
public static function get($var, $default=null, $cast=null, $data=null) {
|
||||
$vars = explode('.', $var);
|
||||
|
@ -87,6 +93,59 @@ class LSconfig {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of keys of a specific configuration variable
|
||||
*
|
||||
* @param[in] $var string The configuration variable name
|
||||
* @param[in] $data array The configuration data (optional)
|
||||
*
|
||||
* @retval array An array of the keys of a specific configuration variable
|
||||
**/
|
||||
public static function keys($var, $data=null) {
|
||||
$value = self :: get($var, null, null, $data);
|
||||
return (is_array($value)?array_keys($value):array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of configuration variables with their value that matching a specific pattern
|
||||
*
|
||||
* The character '*' could replace any part (expect the first one) of the configuration
|
||||
* variable name. In this case, the keys of the parent value will be iterated to compose
|
||||
* the result.
|
||||
*
|
||||
* @param[in] $pattern string The configuration variable pattern
|
||||
* @param[in] $default mixed The default value to return if configuration variable
|
||||
* is not set (optional, see self :: get())
|
||||
* @param[in] $cast string The type of expected value (optional, see self :: get())
|
||||
* @param[in] $data array The configuration data (optional, see self :: get())
|
||||
*
|
||||
* @retval array The list of matching configuration variables with their value
|
||||
**/
|
||||
public static function getMatchingKeys($pattern, $default=null, $cast=null, $data=null, $prefix=null) {
|
||||
$return = array();
|
||||
if ($pos = strpos($pattern, '*')) {
|
||||
// Handle subkey
|
||||
$root_key = (is_string($prefix)?"$prefix.":"").substr($pattern, 0, ($pos-1));
|
||||
$suffix = substr($pattern, $pos+2, (strlen($pattern)-$pos));
|
||||
$subkeys = self :: keys($root_key);
|
||||
if ($suffix) {
|
||||
foreach ($subkeys as $subkey)
|
||||
$return = array_merge($return, self :: getMatchingKeys($suffix, $default, $cast, $data, "$root_key.$subkey"));
|
||||
}
|
||||
else {
|
||||
foreach ($subkeys as $subkey) {
|
||||
$key = "$root_key.$subkey";
|
||||
$return[$key] = self :: get($key, $default, $cast, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$key = (is_string($prefix)?"$prefix.":"").$pattern;
|
||||
$return[$key] = self :: get($key, $default, $cast, $data);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Définition d'une valeur
|
||||
*
|
||||
|
|
2
public_html/lang/.gitignore
vendored
Normal file
2
public_html/lang/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
ldapsaisie-main.pot
|
||||
ldapsaisie-templates.pot
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -30,26 +30,67 @@ chdir(dirname(__FILE__).'/../');
|
|||
require_once('core.php');
|
||||
require_once('conf/config.inc.php');
|
||||
|
||||
$withoutselectlist=False;
|
||||
$available_onlys = array("config", "templates", "addons");
|
||||
$only = null;
|
||||
$available_withouts = array_merge($available_onlys, array("select-list"));
|
||||
$withouts = array();
|
||||
$copyoriginalvalue=False;
|
||||
$interactive=False;
|
||||
$output=False;
|
||||
$additionalfileformat=False;
|
||||
$lang=False;
|
||||
$encoding=False;
|
||||
$available_formats=array('php', 'pot');
|
||||
$format=$available_formats[0];
|
||||
$translations=array();
|
||||
$debug = false;
|
||||
$load_files = array();
|
||||
function usage($error, $exit_code=0) {
|
||||
global $argv, $available_withouts, $available_onlys;
|
||||
if ($error)
|
||||
echo "$error\n\n";
|
||||
echo "Usage : ".$argv[0]." [file1] [file2] [-h] [options]\n";
|
||||
echo " -W/--without Disable specified messages. Must be one of the following values :\n";
|
||||
echo " '".implode("','", $available_withouts)."'\n";
|
||||
echo " -O/--only Only handle specified messages. Must be one of the following values :\n";
|
||||
echo " '".implode("','", $available_onlys)."'\n";
|
||||
echo " -c/--copy-original-value Copy original value as translated value when no translated value exists\n";
|
||||
echo " -i/--interactive Interactive mode : ask user to enter translated on each translation needed\n";
|
||||
echo " -a/--additional-file-format Additional file format output\n";
|
||||
echo " -l/--lang Load this specify lang (format : [lang].[encoding])\n";
|
||||
echo " -o/--output Output file (default : stdout)\n";
|
||||
echo " -f/--format Output file format : php or pot (default : php)\n";
|
||||
echo " -d/--debug Enable debug mode\n";
|
||||
exit($exit_code);
|
||||
}
|
||||
|
||||
function realtive_path($path) {
|
||||
if ($path[0] == '/')
|
||||
return $path;
|
||||
global $curdir;
|
||||
return realpath($curdir)."/".$path;
|
||||
}
|
||||
|
||||
if ($argc > 1) {
|
||||
// Change dir again to manage file input
|
||||
chdir($curdir);
|
||||
for ($i=1;$i<$argc;$i++) {
|
||||
if (is_file($argv[$i])) {
|
||||
@include($argv[$i]);
|
||||
foreach($GLOBALS['LSlang'] as $msg => $trans) {
|
||||
$translations[$msg]=$trans;
|
||||
}
|
||||
if($argv[$i]=='--without' || $argv[$i]=='-W') {
|
||||
$i++;
|
||||
$without = strtolower($argv[$i]);
|
||||
if (!in_array($without, $available_withouts))
|
||||
die("Invalid -W/--without parameter. Must be one of the following values : '".implode("','", $available_withouts)."'.\n");
|
||||
elseif ($only)
|
||||
die("You could not use only -W/--without parameter combined with -O/--only parameter.\n");
|
||||
$withouts[] = $without;
|
||||
}
|
||||
elseif($argv[$i]=='--without-select-list' || $argv[$i]=='-W') {
|
||||
$withoutselectlist=True;
|
||||
elseif($argv[$i]=='--only' || $argv[$i]=='-O') {
|
||||
$i++;
|
||||
if ($only)
|
||||
die("You could specify only on -O/--only parameter.\n");
|
||||
$only = strtolower($argv[$i]);
|
||||
if (!in_array($only, $available_onlys))
|
||||
die("Invalid -O/--only parameter. Must be one of the following values : '".implode("','", $available_onlys)."'.\n");
|
||||
elseif ($without)
|
||||
die("You could not use only -O/--only parameter combined with -W/--without parameter.\n");
|
||||
}
|
||||
elseif($argv[$i]=='--copy-original-value' || $argv[$i]=='-c') {
|
||||
$copyoriginalvalue=True;
|
||||
|
@ -75,54 +116,105 @@ if ($argc > 1) {
|
|||
$i++;
|
||||
$output = $argv[$i];
|
||||
}
|
||||
elseif($argv[$i]=='--format' || $argv[$i]=='-f') {
|
||||
$i++;
|
||||
$format = strtolower($argv[$i]);
|
||||
if (!in_array($format, $available_formats)) {
|
||||
die("Invalid -f/--format parameter. Must be one of the following values : '".implode("','", $available_formats)."'.\n");
|
||||
}
|
||||
}
|
||||
elseif($argv[$i]=='--debug' || $argv[$i]=='-d') {
|
||||
$debug = true;
|
||||
}
|
||||
elseif($argv[$i]=='-h') {
|
||||
echo "Usage : ".$argv[0]." [file1] [file2] [-h] [options]\n";
|
||||
echo " -W/--without-select-list Don't add possibles values of select list\n";
|
||||
echo " -c/--copy-original-value Copy original value as translated value when no translated value exists\n";
|
||||
echo " -i/--interactive Interactive mode : ask user to enter translated on each translation needed\n";
|
||||
echo " -a/--additional-file-format Additional file format output\n";
|
||||
echo " -l/--lang Load this specify lang (format : [lang].[encoding])\n";
|
||||
echo " -o/--output Output file (default : stdout)\n";
|
||||
exit(0);
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
$path = realtive_path($argv[$i]);
|
||||
if (is_file($path))
|
||||
$load_files[] = $path;
|
||||
else
|
||||
usage($argv[$i]." : Invalid lang file to load.", 1);
|
||||
}
|
||||
}
|
||||
chdir(dirname(__FILE__).'/../');
|
||||
}
|
||||
|
||||
$data=array();
|
||||
|
||||
function add($msg) {
|
||||
function debug($msg) {
|
||||
global $debug, $output;
|
||||
if (!$debug) return true;
|
||||
$fd = ($output?STDOUT: STDERR);
|
||||
fwrite($fd, "$msg\n");
|
||||
}
|
||||
|
||||
function add($msg, $context=null) {
|
||||
debug("add($msg, $context)");
|
||||
if ($msg!='' && _($msg) == "$msg") {
|
||||
global $data, $translations, $interactive, $copyoriginalvalue;
|
||||
global $data, $translations, $interactive, $copyoriginalvalue, $format;
|
||||
|
||||
// Message already exists ?
|
||||
if (array_key_exists($msg, $data)) {
|
||||
if ($context && !in_array($context, $data[$msg]['contexts']))
|
||||
$data[$msg]['contexts'][] = $context;
|
||||
return True;
|
||||
}
|
||||
elseif (array_key_exists($msg, $translations)) {
|
||||
$data[$msg]=$translations[$msg];
|
||||
|
||||
// Handle translation
|
||||
$translation = "";
|
||||
if (array_key_exists($msg, $translations)) {
|
||||
$translation = $translations[$msg];
|
||||
}
|
||||
elseif ($interactive) {
|
||||
elseif ($interactive && $format != 'pot') {
|
||||
if ($copyoriginalvalue) {
|
||||
fwrite(STDERR, "\"$msg\"\n\n => Please enter translated string (or leave empty to copy original string) : ");
|
||||
$in = trim(fgets(STDIN));
|
||||
if ($in)
|
||||
$data[$msg]=$in;
|
||||
$translation = $in;
|
||||
else
|
||||
$data[$msg]=$msg;
|
||||
$translation = $msg;
|
||||
}
|
||||
else {
|
||||
fwrite(STDERR, "\"$msg\"\n\n => Please enter translated string (or 'c' to copy original message, leave empty to pass) : ");
|
||||
$in = trim(fgets(STDIN));
|
||||
if ($in) {
|
||||
if ($in=="c")
|
||||
$data[$msg]=$msg;
|
||||
$translation = $msg;
|
||||
else
|
||||
$data[$msg]=$in;
|
||||
$translation = $in;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$data[$msg]="";
|
||||
$data[$msg] = array (
|
||||
'translation' => $translation,
|
||||
'contexts' => ($context?array($context):array()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function addFromLSconfig($pattern, $value='value', $excludes=array()) {
|
||||
debug("addFromLSconfig($pattern, array(".implode(',', $excludes)."))");
|
||||
$keys = LSconfig :: getMatchingKeys($pattern);
|
||||
debug("addFromLSconfig : ".count($keys)." matching key(s)");
|
||||
foreach ($keys as $key => $value) {
|
||||
debug("addFromLSconfig : $key = $value");
|
||||
if ($value == 'key') {
|
||||
// Get the last key parts as value and all other as key
|
||||
$key_parts = explode('.', $key);
|
||||
$value = $key_parts[count($key_parts)-1];
|
||||
$key = implode('.', array_slice($key_parts, 0, count($key_parts)-1));
|
||||
}
|
||||
if (!in_array($value, $excludes) && is_string($value))
|
||||
add($value, $key);
|
||||
}
|
||||
}
|
||||
|
||||
// Load translation files
|
||||
foreach($load_files as $path) {
|
||||
debug("Load $path lang file");
|
||||
@include($path);
|
||||
foreach($GLOBALS['LSlang'] as $msg => $trans) {
|
||||
$translations[$msg]=$trans;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,196 +228,184 @@ if ($lang && $encoding) {
|
|||
}
|
||||
}
|
||||
|
||||
// LDAP Servers
|
||||
foreach($GLOBALS['LSconfig']['ldap_servers'] as $conf) {
|
||||
add($conf['name']);
|
||||
add($conf['subDnLabel']);
|
||||
add($conf['recoverPassword']['recoveryHashMail']['subject']);
|
||||
add($conf['recoverPassword']['recoveryHashMail']['msg']);
|
||||
add($conf['recoverPassword']['newPasswordMail']['subject']);
|
||||
add($conf['recoverPassword']['newPasswordMail']['msg']);
|
||||
if (is_array($conf['subDn'])) {
|
||||
foreach($conf['subDn'] as $name => $cf) {
|
||||
if ($name!='LSobject') {
|
||||
add($name);
|
||||
/*
|
||||
* Manage configuration parameters
|
||||
*/
|
||||
if (!in_array('config', $withouts) && (!$only || $only == 'config')) {
|
||||
// LDAP Servers
|
||||
$objects = array();
|
||||
foreach(LSconfig :: keys('ldap_servers') as $ldap_server_id) {
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.name");
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.subDnLabel");
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.recoverPassword.recoveryHashMail.subject");
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.recoverPassword.recoveryHashMail.msg");
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.recoverPassword.newPasswordMail.subject");
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.recoverPassword.newPasswordMail.msg");
|
||||
addFromLSconfig("ldap_servers.$ldap_server_id.subDn.*", 'key', array("LSobject"));
|
||||
|
||||
// LSaccess
|
||||
foreach (LSconfig :: get("ldap_servers.$ldap_server_id.LSaccess", array()) as $LSobject) {
|
||||
if (is_string($LSobject) && !in_array($LSobject, $objects) && LSsession :: loadLSobject($LSobject)) {
|
||||
$objects[] = $LSobject;
|
||||
}
|
||||
}
|
||||
|
||||
// Sub DN LSobjects
|
||||
foreach (LSconfig :: getMatchingKeys("ldap_servers.$ldap_server_id.subDn.*.LSobjects.*") as $LSobject)
|
||||
if (is_string($LSobject) && !in_array($LSobject, $objects) && LSsession :: loadLSobject($LSobject))
|
||||
$objects[] = $LSobject;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
debug('LSobjects list : '.implode(', ', $objects));
|
||||
|
||||
// LSobject
|
||||
foreach($objects as $obj) {
|
||||
addFromLSconfig("LSobjects.$obj.label");
|
||||
|
||||
// LSobject
|
||||
if (loadDir(LS_OBJECTS_DIR) && loadDir(LS_LOCAL_DIR.LS_OBJECTS_DIR)) {
|
||||
foreach($GLOBALS['LSobjects'] as $name => $conf) {
|
||||
add($conf['label']);
|
||||
|
||||
// LSrelation
|
||||
if (is_array($conf['LSrelation'])) {
|
||||
foreach($conf['LSrelation'] as $rel) {
|
||||
add($rel['label']);
|
||||
add($rel['emptyText']);
|
||||
}
|
||||
}
|
||||
addFromLSconfig("LSobjects.$obj.LSrelation.*.label");
|
||||
addFromLSconfig("LSobjects.$obj.LSrelation.*.emptyText");
|
||||
|
||||
// Custom Actions
|
||||
if (is_array($conf['customActions'])) {
|
||||
foreach($conf['customActions'] as $act) {
|
||||
add($act['label']);
|
||||
add($act['helpInfo']);
|
||||
add($act['question_format']);
|
||||
add($act['onSuccessMsgFormat']);
|
||||
}
|
||||
}
|
||||
addFromLSconfig("LSobjects.$obj.customActions.*.label");
|
||||
addFromLSconfig("LSobjects.$obj.customActions.*.helpInfo");
|
||||
addFromLSconfig("LSobjects.$obj.customActions.*.question_format");
|
||||
addFromLSconfig("LSobjects.$obj.customActions.*.onSuccessMsgFormat");
|
||||
|
||||
// LSform
|
||||
if (is_array($conf['LSform']['layout'])) {
|
||||
foreach($conf['LSform']['layout'] as $lay) {
|
||||
add($lay['label']);
|
||||
}
|
||||
}
|
||||
if (is_array($conf['LSform']['dataEntryForm'])) {
|
||||
foreach($conf['LSform']['dataEntryForm'] as $def) {
|
||||
add($def['label']);
|
||||
}
|
||||
}
|
||||
addFromLSconfig("LSobjects.$obj.LSform.layout.*.label");
|
||||
addFromLSconfig("LSobjects.$obj.LSform.dataEntryForm.*.label");
|
||||
|
||||
// LSsearch
|
||||
if (is_array($conf['LSsearch']['predefinedFilters'])) {
|
||||
foreach($conf['LSsearch']['predefinedFilters'] as $lay) {
|
||||
add($lay);
|
||||
}
|
||||
}
|
||||
if (is_array($conf['LSsearch']['extraDisplayedColumns'])) {
|
||||
foreach($conf['LSsearch']['extraDisplayedColumns'] as $cid => $cconf) {
|
||||
add($cconf['label']);
|
||||
}
|
||||
}
|
||||
if (is_array($conf['LSsearch']['customActions'])) {
|
||||
foreach($conf['LSsearch']['customActions'] as $act) {
|
||||
add($act['label']);
|
||||
add($act['question_format']);
|
||||
add($act['onSuccessMsgFormat']);
|
||||
}
|
||||
}
|
||||
addFromLSconfig("LSobjects.$obj.LSsearch.predefinedFilters.*");
|
||||
addFromLSconfig("LSobjects.$obj.LSsearch.extraDisplayedColumns.*.label");
|
||||
addFromLSconfig("LSobjects.$obj.LSsearch.customActions.*.label");
|
||||
addFromLSconfig("LSobjects.$obj.LSsearch.customActions.*.question_format");
|
||||
addFromLSconfig("LSobjects.$obj.LSsearch.customActions.*.onSuccessMsgFormat");
|
||||
|
||||
// Attributes
|
||||
foreach(LSconfig :: keys("LSobjects.$obj.attrs") as $attr) {
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.label");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.help_info");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.no_value_label");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.check_data.*.msg");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.validation.*.msg");
|
||||
|
||||
|
||||
if(is_array($conf['attrs'])) {
|
||||
foreach($conf['attrs'] as $attr) {
|
||||
add($attr['label']);
|
||||
add($attr['help_info']);
|
||||
add($attr['no_value_label']);
|
||||
add($attr['html_options']['mail']['subject']);
|
||||
add($attr['html_options']['mail']['msg']);
|
||||
|
||||
// LSattr_html_select_list
|
||||
if (($attr['html_type']=='select_list' || $attr['html_type']=='select_box') && is_array($attr['html_options']['possible_values']) && (!isset($attr['html_options']['translate_labels']) || $attr['html_options']['translate_labels']) && !$withoutselectlist) {
|
||||
foreach($attr['html_options']['possible_values'] as $pkey => $pname) {
|
||||
if (is_array($pname)) {
|
||||
add($pname['label']);
|
||||
if (is_array($pname['possible_values'])) {
|
||||
foreach($pname['possible_values'] as $pk => $pn) {
|
||||
if ($pk == 'OTHER_OBJECT') continue;
|
||||
elseif ($pk == 'OTHER_ATTRIBUTE') {
|
||||
if (is_array($pn) && ! isset($pn['attr'])) {
|
||||
foreach($pn as $pattr => $plabel)
|
||||
add($plabel);
|
||||
}
|
||||
}
|
||||
else add($pn);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($pkey == 'OTHER_ATTRIBUTE') {
|
||||
if (is_array($pname) && ! isset($pname['attr'])) {
|
||||
foreach($pname as $pattr => $plabel)
|
||||
add($plabel);
|
||||
}
|
||||
}
|
||||
elseif ($pkey != 'OTHER_OBJECT') {
|
||||
add($pname);
|
||||
}
|
||||
}
|
||||
}
|
||||
// HTML Options
|
||||
$html_type = LSconfig :: get("LSobjects.$obj.attrs.$attr.html_type");
|
||||
switch($html_type) {
|
||||
case 'boolean':
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.true_label");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.false_label");
|
||||
break;
|
||||
case 'jsonCompositeAttribute':
|
||||
$components = LSconfig :: keys("LSobjects.$obj.attrs.$attr.html_options.components");
|
||||
foreach($components as $c) {
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.label");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.help_info");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.check_data.*.msg");
|
||||
|
||||
// LSattr_html_valueWithUnit
|
||||
if (is_array($attr['html_options']['units'])) {
|
||||
foreach($attr['html_options']['units'] as $pname) {
|
||||
add($pname);
|
||||
}
|
||||
}
|
||||
|
||||
// LSattr_html_labeledValue
|
||||
if (is_array($attr['html_options']['labels'])) {
|
||||
foreach($attr['html_options']['labels'] as $klabel => $plabel) {
|
||||
add($plabel);
|
||||
}
|
||||
}
|
||||
|
||||
// LSattr_html_boolean
|
||||
if (isset($attr['html_options']['true_label'])) {
|
||||
add($attr['html_options']['true_label']);
|
||||
}
|
||||
if (isset($attr['html_options']['false_label'])) {
|
||||
add($attr['html_options']['false_label']);
|
||||
}
|
||||
|
||||
// LSattr_html_jsonCompositeAttribute
|
||||
if (is_array($attr['html_options']['components'])) {
|
||||
foreach($attr['html_options']['components'] as $c => $cconfig) {
|
||||
add($cconfig['label']);
|
||||
add($cconfig['help_info']);
|
||||
|
||||
// Component type select_list
|
||||
if (is_array($cconfig['options']['possible_values']) && (!isset($cconfig['options']['translate_labels']) || $cconfig['options']['translate_labels']) && !$withoutselectlist) {
|
||||
foreach($cconfig['options']['possible_values'] as $pkey => $pname) {
|
||||
if (is_array($pname)) {
|
||||
add($pname['label']);
|
||||
if (is_array($pname['possible_values'])) {
|
||||
foreach($pname['possible_values'] as $pk => $pn) {
|
||||
if ($pk == 'OTHER_OBJECT') continue;
|
||||
elseif ($pk == 'OTHER_ATTRIBUTE') {
|
||||
if (is_array($pn) && ! isset($pn['attr'])) {
|
||||
foreach($pn as $pattr => $plabel)
|
||||
add($plabel);
|
||||
}
|
||||
}
|
||||
else add($pn);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.$c.type") == 'select_list' &&
|
||||
LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.$c.options.translate_labels", "True", "bool") &&
|
||||
!in_array('select-list', $withouts)
|
||||
)
|
||||
{
|
||||
foreach(LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values", array()) as $pkey => $plabel) {
|
||||
if ($pkey == 'OTHER_OBJECT')
|
||||
continue;
|
||||
elseif ($pkey == 'OTHER_ATTRIBUTE') {
|
||||
if (is_array($pname) && ! isset($pname['attr'])) {
|
||||
foreach($pname as $pattr => $plabel)
|
||||
add($plabel);
|
||||
if (is_string($plabel))
|
||||
continue;
|
||||
elseif (is_array($plabel)) {
|
||||
if (isset($plabel['json_component_key']))
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.OTHER_ATTRIBUTE.json_component_label");
|
||||
else
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.OTHER_ATTRIBUTE.*");
|
||||
}
|
||||
}
|
||||
elseif ($pkey != 'OTHER_OBJECT') {
|
||||
add($pname);
|
||||
elseif(is_string($plabel)) {
|
||||
add($plabel, "LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.$pkey");
|
||||
}
|
||||
elseif (is_array($plabel)) {
|
||||
// Sub possible values
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.$pkey.label");
|
||||
foreach(LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.$pkey.possible_values", array()) as $ppkey => $pplabel) {
|
||||
if ($ppkey == 'OTHER_OBJECT')
|
||||
continue;
|
||||
elseif ($ppkey == 'OTHER_ATTRIBUTE') {
|
||||
if (is_string($pplabel))
|
||||
continue;
|
||||
elseif (is_array($pplabel)) {
|
||||
if (isset($pplabel['json_component_key']))
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.OTHER_ATTRIBUTE.json_component_label");
|
||||
else
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.OTHER_ATTRIBUTE.*");
|
||||
}
|
||||
}
|
||||
elseif(is_string($pplabel)) {
|
||||
add($pplabel, "LSobjects.$obj.attrs.$attr.html_options.$c.options.possible_values.$pkey.possible_values.$ppkey");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check data
|
||||
if (is_array($cconfig['check_data'])) {
|
||||
foreach($cconfig['check_data'] as $check) {
|
||||
add($check['msg']);
|
||||
}
|
||||
break;
|
||||
case 'labeledValue':
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.labels.*");
|
||||
break;
|
||||
case 'password':
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.mail.subject");
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.mail.msg");
|
||||
break;
|
||||
case 'select_list':
|
||||
case 'select_box':
|
||||
if (LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.translate_labels", "True", "bool") && !in_array('select-list', $withouts)) {
|
||||
foreach(LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.possible_values", array()) as $pkey => $plabel) {
|
||||
if ($pkey == 'OTHER_OBJECT')
|
||||
continue;
|
||||
elseif ($pkey == 'OTHER_ATTRIBUTE') {
|
||||
if (is_string($plabel))
|
||||
continue;
|
||||
elseif (is_array($plabel)) {
|
||||
if (isset($plabel['json_component_key']))
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.possible_values.OTHER_ATTRIBUTE.json_component_label");
|
||||
else
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.possible_values.OTHER_ATTRIBUTE.*");
|
||||
}
|
||||
}
|
||||
elseif(is_string($plabel)) {
|
||||
add($plabel, "LSobjects.$obj.attrs.$attr.html_options.possible_values.$pkey");
|
||||
}
|
||||
elseif (is_array($plabel)) {
|
||||
// Sub possible values
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.possible_values.$pkey.label");
|
||||
foreach(LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.possible_values.$pkey.possible_values", array()) as $ppkey => $pplabel) {
|
||||
if ($ppkey == 'OTHER_OBJECT')
|
||||
continue;
|
||||
elseif ($ppkey == 'OTHER_ATTRIBUTE') {
|
||||
if (is_string($pplabel))
|
||||
continue;
|
||||
elseif (is_array($pplabel)) {
|
||||
if (isset($pplabel['json_component_key']))
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.possible_values.OTHER_ATTRIBUTE.json_component_label");
|
||||
else
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.possible_values.OTHER_ATTRIBUTE.*");
|
||||
}
|
||||
}
|
||||
elseif(is_string($pplabel)) {
|
||||
add($pplabel, "LSobjects.$obj.attrs.$attr.html_options.possible_values.$pkey.possible_values.$ppkey");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check data
|
||||
if (is_array($attr['check_data'])) {
|
||||
foreach($attr['check_data'] as $check) {
|
||||
add($check['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
// validation
|
||||
if (is_array($attr['validation'])) {
|
||||
foreach($attr['validation'] as $valid) {
|
||||
add($valid['msg']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'valueWithUnit':
|
||||
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.units.*");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -334,112 +414,177 @@ if (loadDir(LS_OBJECTS_DIR) && loadDir(LS_LOCAL_DIR.LS_OBJECTS_DIR)) {
|
|||
/*
|
||||
* Manage template file
|
||||
*/
|
||||
|
||||
function parse_template_file($file) {
|
||||
foreach(file($file) as $line) {
|
||||
if (preg_match_all('/\{ *tr +msg=["\']([^\}]+)["\'] *\}/',$line,$matches)) {
|
||||
foreach($matches[1] as $t)
|
||||
add($t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function find_and_parse_template_file($dir) {
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file=='.' || $file=='..') continue;
|
||||
if (is_dir($dir.'/'.$file)) {
|
||||
find_and_parse_template_file($dir.'/'.$file);
|
||||
}
|
||||
elseif (is_file($dir."/".$file) && preg_match('/\.tpl$/',$file)) {
|
||||
parse_template_file($dir.'/'.$file);
|
||||
if (!in_array('templates', $withouts) && (!$only || $only == 'templates')) {
|
||||
function parse_template_file($file) {
|
||||
debug("parse_template_file($file) : start ...");
|
||||
$count = 0;
|
||||
foreach(file($file) as $line) {
|
||||
$count ++;
|
||||
if (preg_match_all('/\{ *tr +msg=["\']([^\}]+)["\'] *\}/',$line,$matches)) {
|
||||
foreach($matches[1] as $t) {
|
||||
debug(" - \"$t\" # Line $count");
|
||||
add($t, "$file:$count");
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
debug("parse_template_file($file) : done.");
|
||||
}
|
||||
|
||||
function find_and_parse_template_file($dir) {
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file=='.' || $file=='..') continue;
|
||||
if (is_dir($dir.'/'.$file)) {
|
||||
find_and_parse_template_file($dir.'/'.$file);
|
||||
}
|
||||
elseif (is_file($dir."/".$file) && preg_match('/\.tpl$/',$file)) {
|
||||
parse_template_file($dir.'/'.$file);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
find_and_parse_template_file(LS_TEMPLATES_DIR);
|
||||
find_and_parse_template_file(LS_LOCAL_DIR.LS_TEMPLATES_DIR);
|
||||
find_and_parse_template_file(LS_TEMPLATES_DIR);
|
||||
find_and_parse_template_file(LS_LOCAL_DIR.LS_TEMPLATES_DIR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Manage addons files
|
||||
*/
|
||||
|
||||
function parse_addon_file($file) {
|
||||
foreach(file($file) as $line) {
|
||||
$offset=0;
|
||||
while ($pos = strpos($line,'__(',$offset)) {
|
||||
$quote='';
|
||||
$res='';
|
||||
for ($i=$pos+3;$i<strlen($line);$i++) {
|
||||
if (empty($quote)) {
|
||||
// Quote char not detected : try to detect it
|
||||
if ($line[$i]=='\\' || $line[$i]==" " || $line[$i]=="\t") {
|
||||
// Space or escape char : pass
|
||||
$i++;
|
||||
if (!in_array('addons', $withouts) && (!$only || $only == 'addons')) {
|
||||
function parse_addon_file($file) {
|
||||
$count = 0;
|
||||
foreach(file($file) as $line) {
|
||||
$count++;
|
||||
$offset=0;
|
||||
while ($pos = strpos($line,'__(',$offset)) {
|
||||
$quote='';
|
||||
$res='';
|
||||
for ($i=$pos+3;$i<strlen($line);$i++) {
|
||||
if (empty($quote)) {
|
||||
// Quote char not detected : try to detect it
|
||||
if ($line[$i]=='\\' || $line[$i]==" " || $line[$i]=="\t") {
|
||||
// Space or escape char : pass
|
||||
$i++;
|
||||
}
|
||||
elseif ($line[$i]=='"' || $line[$i]=="'") {
|
||||
// Quote detected
|
||||
$quote=$line[$i];
|
||||
}
|
||||
elseif ($line[$i]=='$' || $line[$i]==')') {
|
||||
// Variable translation not possible or end function call detected
|
||||
$offset=$i;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// Unknown case : continue
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
elseif ($line[$i]=='"' || $line[$i]=="'") {
|
||||
// Quote detected
|
||||
$quote=$line[$i];
|
||||
}
|
||||
elseif ($line[$i]=='$' || $line[$i]==')') {
|
||||
// Variable translation not possible or end function call detected
|
||||
$offset=$i;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// Unknown case : continue
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
elseif (!empty($quote)) {
|
||||
// Quote char already detected : try to detect end quote char
|
||||
if ($line[$i]=='\\') {
|
||||
// Escape char detected : pass this char and the following one
|
||||
$res.=$line[$i];
|
||||
$i++;
|
||||
$res.=$line[$i];
|
||||
}
|
||||
elseif ($line[$i]==$quote) {
|
||||
// End quote char detected : set offset for next detection and break this one
|
||||
$offset=$i;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// End quote char not detected : append current char to result
|
||||
$res.=$line[$i];
|
||||
elseif (!empty($quote)) {
|
||||
// Quote char already detected : try to detect end quote char
|
||||
if ($line[$i]=='\\') {
|
||||
// Escape char detected : pass this char and the following one
|
||||
$res.=$line[$i];
|
||||
$i++;
|
||||
$res.=$line[$i];
|
||||
}
|
||||
elseif ($line[$i]==$quote) {
|
||||
// End quote char detected : set offset for next detection and break this one
|
||||
$offset=$i;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// End quote char not detected : append current char to result
|
||||
$res.=$line[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($res)) add($res, "$file:$count");
|
||||
}
|
||||
if (!empty($res)) add($res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function find_and_parse_addon_file($dir) {
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if (preg_match('/^LSaddons\.(.+)\.php$/',$file)) {
|
||||
parse_addon_file($dir.'/'.$file);
|
||||
function find_and_parse_addon_file($dir) {
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if (preg_match('/^LSaddons\.(.+)\.php$/',$file)) {
|
||||
parse_addon_file($dir.'/'.$file);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
find_and_parse_addon_file(LS_ADDONS_DIR);
|
||||
find_and_parse_addon_file(LS_LOCAL_DIR.LS_ADDONS_DIR);
|
||||
}
|
||||
|
||||
find_and_parse_addon_file(LS_ADDONS_DIR);
|
||||
find_and_parse_addon_file(LS_LOCAL_DIR.LS_ADDONS_DIR);
|
||||
|
||||
|
||||
// Sort resulting strings
|
||||
ksort($data);
|
||||
|
||||
/*
|
||||
* Handle output file format
|
||||
*/
|
||||
function output_php($fd) {
|
||||
global $additionalfileformat, $data, $copyoriginalvalue;
|
||||
fwrite($fd, "<?php\n\n");
|
||||
|
||||
if (!$additionalfileformat) fwrite($fd, "\$GLOBALS['LSlang'] = array (\n");
|
||||
|
||||
foreach($data as $key => $key_data) {
|
||||
if ($copyoriginalvalue && $key_data['translation'] == "") {
|
||||
$val = $key;
|
||||
}
|
||||
else
|
||||
$val = $key_data['translation'];
|
||||
$key=str_replace('"','\\"',$key);
|
||||
$val=str_replace('"','\\"',$val);
|
||||
foreach ($key_data['contexts'] as $context)
|
||||
fwrite($fd, "\n# $context");
|
||||
if ($additionalfileformat) {
|
||||
fwrite($fd, "\n\$GLOBALS['LSlang'][\"$key\"] = \"$val\";\n");
|
||||
}
|
||||
else {
|
||||
fwrite($fd, "\n\"$key\" =>\n \"$val\",\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!$additionalfileformat) fwrite($fd, "\n);\n");
|
||||
}
|
||||
|
||||
function clean_for_pot_file($val) {
|
||||
$val = str_replace('"', '\\"', $val);
|
||||
return str_replace("\n", "\\n", $val);
|
||||
}
|
||||
|
||||
function output_pot($fd) {
|
||||
global $data, $copyoriginalvalue;
|
||||
foreach($data as $key => $key_data) {
|
||||
if ($copyoriginalvalue && $key_data['translation'] == "") {
|
||||
$val = $key;
|
||||
}
|
||||
else
|
||||
$val = $key_data['translation'];
|
||||
foreach ($key_data['contexts'] as $context)
|
||||
fwrite($fd, "#: $context\n");
|
||||
$key = clean_for_pot_file($key);
|
||||
$val = clean_for_pot_file($val);
|
||||
fwrite($fd, "msgid \"$key\"\nmsgstr \"$val\"\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Determine where to write result
|
||||
if ($output) {
|
||||
$output = realtive_path($output);
|
||||
try {
|
||||
debug("Open output file ($output)");
|
||||
$fd = fopen($output, 'w');
|
||||
}
|
||||
catch(Exception $e) {
|
||||
|
@ -454,26 +599,22 @@ if ($output) {
|
|||
else
|
||||
$fd = STDOUT;
|
||||
|
||||
fwrite($fd, "<?php\n\n");
|
||||
|
||||
if (!$additionalfileformat) fwrite($fd, "\$GLOBALS['LSlang'] = array (\n");
|
||||
|
||||
foreach($data as $key => $val) {
|
||||
if ($copyoriginalvalue && $val=="") {
|
||||
$val=$key;
|
||||
}
|
||||
$key=str_replace('"','\\"',$key);
|
||||
$val=str_replace('"','\\"',$val);
|
||||
if ($additionalfileformat) {
|
||||
fwrite($fd, "\$GLOBALS['LSlang'][\"$key\"] = \"$val\";\n");
|
||||
}
|
||||
else {
|
||||
fwrite($fd, "\n\"$key\" =>\n \"$val\",\n");
|
||||
}
|
||||
// Generate output
|
||||
debug("Output format : $format");
|
||||
switch($format) {
|
||||
case 'pot':
|
||||
output_pot($fd);
|
||||
break;
|
||||
case 'php':
|
||||
default:
|
||||
output_php($fd);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$additionalfileformat) fwrite($fd, "\n);\n");
|
||||
|
||||
if ($output)
|
||||
// Close output file (is specified)
|
||||
if ($output) {
|
||||
debug("Close output file ($output)");
|
||||
fclose($fd);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
|
22
public_html/lang/generate_ldapsaisie.pot.sh
Normal file → Executable file
22
public_html/lang/generate_ldapsaisie.pot.sh
Normal file → Executable file
|
@ -1,7 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd ../
|
||||
# Detect
|
||||
PUBLIC_HTML=$( realpath $( dirname $0 )/../ )
|
||||
|
||||
rm -fr tmp/*
|
||||
# Clean php file in tmp directory
|
||||
[ -d "$PUBLIC_HTML/tmp" ] && rm -fr "$PUBLIC_HTML/tmp/*.php"
|
||||
|
||||
xgettext --from-code utf-8 -o lang/ldapsaisie.pot $( find -name "*.php" )
|
||||
# Extract messages from LdapSaisie PHP files using xgettext
|
||||
xgettext --from-code utf-8 \
|
||||
-o "$PUBLIC_HTML/lang/ldapsaisie-main.pot" \
|
||||
--omit-header \
|
||||
--copyright-holder="Easter-eggs" \
|
||||
--keyword="__" \
|
||||
$( find "$PUBLIC_HTML" -name "*.php" )
|
||||
|
||||
# Extract other messages from LdapSaisie templates files
|
||||
$PUBLIC_HTML/lang/generate_lang_file.php -o "$PUBLIC_HTML/lang/ldapsaisie-templates.pot" \
|
||||
-f pot \
|
||||
--only templates
|
||||
|
||||
# Merge previous results in ldapsaisie.pot file
|
||||
msgcat $PUBLIC_HTML/lang/ldapsaisie-main.pot $PUBLIC_HTML/lang/ldapsaisie-templates.pot -o $PUBLIC_HTML/lang/ldapsaisie.pot
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue