define locales folder name

This commit is contained in:
Jean-Christian Denis 2023-03-18 00:36:11 +01:00
parent 53557a94d9
commit 56862d5eb4
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
2 changed files with 10 additions and 7 deletions

View file

@ -21,9 +21,12 @@ use dcCore;
*/
class My
{
// required php version
/** @var string Required php version */
public const PHP_MIN = '8.1';
/** @var string Locales folder name */
public const LOCALES_FOLDER = 'locales';
/**
* This module id
*/

View file

@ -69,7 +69,7 @@ class TranslaterModule
$this->version = $define->get('version');
$this->root_writable = $define->get('root_writable');
$this->root = path::real($define->get('root'));
$this->locales = $this->root . DIRECTORY_SEPARATOR . 'locales';
$this->locales = $this->root . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER;
}
/// @name backup methods
@ -120,8 +120,8 @@ class TranslaterModule
case 'translater':
$tmp = path::real(dcCore::app()->plugins->moduleRoot(My::id()));
if ($tmp && is_writable($tmp)) {
@mkDir($tmp . '/locales');
$dir = $tmp . '/locales';
@mkDir($tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER);
$dir = $tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER;
}
break;
@ -421,7 +421,7 @@ class TranslaterModule
*/
public function parseZipFilename(string $file = '', bool $throw = false): array
{
$is_file = preg_match('/^(.*?)\/locales\/(.*?)\/(.*?)(.po|.lang.php)$/', $file, $f);
$is_file = preg_match('/^(.*?)\/' . preg_quote(My::LOCALES_FOLDER) . '\/(.*?)\/(.*?)(.po|.lang.php)$/', $file, $f);
if ($is_file) {
$module = $f[1] == $this->id ? $f[1] : false;
@ -462,11 +462,11 @@ class TranslaterModule
{
$res = [];
$prefix = preg_match('/(locales(.*))$/', $this->locales) ? 'locales' : '';
$prefix = preg_match('/(' . preg_quote(My::LOCALES_FOLDER) . '(.*))$/', $this->locales) ? My::LOCALES_FOLDER : '';
$files = Translater::scandir($this->locales);
foreach ($files as $file) {
if (!preg_match('/.*?locales\/([^\/]*?)\/([^\/]*?)(.lang.php|.po)$/', $prefix . $file, $m)) {
if (!preg_match('/.*?' . preg_quote(My::LOCALES_FOLDER) . '\/([^\/]*?)\/([^\/]*?)(.lang.php|.po)$/', $prefix . $file, $m)) {
continue;
}