cosmetics

master
Jean-Christian Paul Denis 2021-09-25 17:38:46 +02:00
parent ba93fbac00
commit 13e7fc83e8
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
2 changed files with 53 additions and 45 deletions

View File

@ -283,7 +283,7 @@ class dcTranslaterModule
$zip = new fileUnzip($zip_file['tmp_name']);
$files = $zip->getFilesList();
foreach($files AS $file) {
foreach($files as $file) {
$f = $this->parseZipFilename($file, true);
if (!$this->translater->import_overwrite
@ -300,7 +300,7 @@ class dcTranslaterModule
];
}
foreach ($res AS $rs) {
foreach ($res as $rs) {
if (!is_dir($rs['root'])) {
files::makeDir($rs['root'], true);
}
@ -395,9 +395,9 @@ class dcTranslaterModule
*
* @param string $file The zip filename
* @param boolean $throw Silently failed
* @return mixed Array of file info or false
* @return mixed Array of file info
*/
public function parseZipFilename(string $file = '', bool $throw = false)
public function parseZipFilename(string $file = '', bool $throw = false): array
{
$is_file = preg_match('/^(.*?)\/locales\/(.*?)\/(.*?)(.po|.lang.php)$/', $file, $f);
@ -414,7 +414,7 @@ class dcTranslaterModule
__('Zip file %s is not in translater format'), $file
));
}
return false;
return [];
}
return [
'module' => $module,
@ -433,7 +433,7 @@ class dcTranslaterModule
* @param boolean $return_path Return path or name
* @return array The lang list
*/
public function getLangs(bool $return_path = false)
public function getLangs(bool $return_path = false): array
{
$res = [];

View File

@ -324,7 +324,7 @@ class dcTranslater
* @param array $res Internal recursion
* @return array List of path
*/
public static function scandir(string $path, string $dir = '', array $res = [])
public static function scandir(string $path, string $dir = '', array $res = []): array
{
$path = path::real($path, false);
if (!is_dir($path) || !is_readable($path)) {
@ -347,18 +347,59 @@ class dcTranslater
return $res;
}
/* Try if a file is a .lang.php file */
public static function isLangphpFile($file)
/**
* Encode a string
*
* @param string $str The string to encode
* @return string The encoded string
*/
public static function encodeMsg(string $str): string
{
return files::getExtension($file) == 'php' && stristr($file, '.lang.php');
return text::toUTF8(stripslashes(trim($str)));
}
/* Try if a file is a .po file */
public static function isPoFile($file)
/**
* Clean a po string
*
* @param string $string The string to clean
* @param boolean $reverse Un/escape string
* @return string The cleaned string
*/
public static function poString(string $string, bool $reverse = false): string
{
if ($reverse) {
$smap = array('"', "\n", "\t", "\r");
$rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r');
return trim((string) str_replace($smap, $rmap, $string));
} else {
$smap = array('/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\\"/');
$rmap = array('', "\n", "\r", "\t", '"');
return trim((string) preg_replace($smap, $rmap, $string));
}
}
/**
* Try if a file is a .po file
*
* @param string $file The path to test
* @return boolean Success
*/
public static function isPoFile(string $file): bool
{
return files::getExtension($file) == 'po';
}
/**
* Try if a file is a .lang.php file
*
* @param string $file The path to test
* @return boolean Success
*/
public static function isLangphpFile(string $file): bool
{
return files::getExtension($file) == 'php' && stristr($file, '.lang.php');
}
/**
* Check limit number of backup for a module
*
@ -445,8 +486,6 @@ class dcTranslater
/**
* Extract messages from a tpl contents
*
* support plurals
*
* @param string $content The contents
* @param string $func The function name
* @return array The messages
@ -485,36 +524,5 @@ class dcTranslater
}
return $final_strings;
}
/**
* Encode a string
*
* @param string $str The string to encode
* @return string The encoded string
*/
public static function encodeMsg(string $str): string
{
return text::toUTF8(stripslashes(trim($str)));
}
/**
* Clean a po string
*
* @param string $string The string to clean
* @param boolean $reverse Un/escape string
* @return string The cleaned string
*/
public static function poString(string $string, bool $reverse = false): string
{
if ($reverse) {
$smap = array('"', "\n", "\t", "\r");
$rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r');
return trim((string) str_replace($smap, $rmap, $string));
} else {
$smap = array('/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\\"/');
$rmap = array('', "\n", "\r", "\t", '"');
return trim((string) preg_replace($smap, $rmap, $string));
}
}
//@}
}