update PSR CS
parent
ba70d79862
commit
ce6b10dd3c
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +45,7 @@ class translaterAdminBehaviors
|
||||||
if (!(self::$translater instanceof dcTranslater)) {
|
if (!(self::$translater instanceof dcTranslater)) {
|
||||||
self::$translater = new dcTranslater($core, false);
|
self::$translater = new dcTranslater($core, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$translater;
|
return self::$translater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
_config.php
13
_config.php
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_MODULE')) {
|
if (!defined('DC_CONTEXT_MODULE')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +19,7 @@ $translater = new dcTranslater($core);
|
||||||
if (!empty($_POST['save'])) {
|
if (!empty($_POST['save'])) {
|
||||||
try {
|
try {
|
||||||
foreach ($translater->getDefaultSettings() as $k => $v) {
|
foreach ($translater->getDefaultSettings() as $k => $v) {
|
||||||
$translater->setSetting($k, (isset($_POST[$k]) ? $_POST[$k] : ''));
|
$translater->setSetting($k, ($_POST[$k] ?? ''));
|
||||||
}
|
}
|
||||||
dcPage::addSuccessNotice(
|
dcPage::addSuccessNotice(
|
||||||
__('Configuration successfully updated.')
|
__('Configuration successfully updated.')
|
||||||
|
@ -57,7 +56,9 @@ __('Write informations about author in files') . '</label></p>
|
||||||
<p><label for="parse_userinfo">' . __('User info:') . '</label>' .
|
<p><label for="parse_userinfo">' . __('User info:') . '</label>' .
|
||||||
form::field('parse_userinfo', 65, 255, $translater->parse_userinfo) . '</p>
|
form::field('parse_userinfo', 65, 255, $translater->parse_userinfo) . '</p>
|
||||||
<p class="form-note">' . sprintf(
|
<p class="form-note">' . sprintf(
|
||||||
__('Following informations can be used: %s'), implode(', ', $translater::$allowed_user_informations)) . '
|
__('Following informations can be used: %s'),
|
||||||
|
implode(', ', $translater::$allowed_user_informations)
|
||||||
|
) . '
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -73,8 +74,10 @@ form::field('export_filename', 65, 255, $translater->export_filename) . '</p>
|
||||||
<p><label for="backup_auto">' .
|
<p><label for="backup_auto">' .
|
||||||
form::checkbox('backup_auto', '1', $translater->backup_auto) .
|
form::checkbox('backup_auto', '1', $translater->backup_auto) .
|
||||||
__('Make backups when changes are made') . '</label></p>
|
__('Make backups when changes are made') . '</label></p>
|
||||||
<p><label for="backup_limit" class="classic">' . sprintf(__('Limit backups to %s files per module'),
|
<p><label for="backup_limit" class="classic">' . sprintf(
|
||||||
form::number('backup_limit', ['min' => 0, 'max' => 50, 'default' => $translater->backup_limit])) . '</label></p>
|
__('Limit backups to %s files per module'),
|
||||||
|
form::number('backup_limit', ['min' => 0, 'max' => 50, 'default' => $translater->backup_limit])
|
||||||
|
) . '</label></p>
|
||||||
<p><label for="backup_folder">' . __('Store backups in:') . '</label>' .
|
<p><label for="backup_folder">' . __('Store backups in:') . '</label>' .
|
||||||
form::combo('backup_folder', $translater::$allowed_backup_folders, $translater->backup_folder) . '</p>
|
form::combo('backup_folder', $translater::$allowed_backup_folders, $translater->backup_folder) . '</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$id = 'translater';
|
$id = 'translater';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (version_compare($core->getVersion($id), $core->plugins->moduleInfo($id, 'version'), '>=')) {
|
if (version_compare($core->getVersion($id), $core->plugins->moduleInfo($id, 'version'), '>=')) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -30,4 +30,5 @@ try {
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$core->error->add($e->getMessage());
|
$core->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,49 +10,72 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addUserAction(
|
$this->addUserAction(
|
||||||
/* type */ 'settings',
|
/* type */
|
||||||
/* action */ 'delete_all',
|
'settings',
|
||||||
/* ns */ 'translater',
|
/* action */
|
||||||
/* description */ __('delete all settings')
|
'delete_all',
|
||||||
|
/* ns */
|
||||||
|
'translater',
|
||||||
|
/* description */
|
||||||
|
__('delete all settings')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addUserAction(
|
$this->addUserAction(
|
||||||
/* type */ 'plugins',
|
/* type */
|
||||||
/* action */ 'delete',
|
'plugins',
|
||||||
/* ns */ 'translater',
|
/* action */
|
||||||
/* description */ __('delete plugin files')
|
'delete',
|
||||||
|
/* ns */
|
||||||
|
'translater',
|
||||||
|
/* description */
|
||||||
|
__('delete plugin files')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addUserAction(
|
$this->addUserAction(
|
||||||
/* type */ 'versions',
|
/* type */
|
||||||
/* action */ 'delete',
|
'versions',
|
||||||
/* ns */ 'translater',
|
/* action */
|
||||||
/* description */ __('delete the version number')
|
'delete',
|
||||||
|
/* ns */
|
||||||
|
'translater',
|
||||||
|
/* description */
|
||||||
|
__('delete the version number')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addDirectAction(
|
$this->addDirectAction(
|
||||||
/* type */ 'settings',
|
/* type */
|
||||||
/* action */ 'delete_all',
|
'settings',
|
||||||
/* ns */ 'translater',
|
/* action */
|
||||||
/* description */ sprintf(__('delete all %s settings'), 'translater')
|
'delete_all',
|
||||||
|
/* ns */
|
||||||
|
'translater',
|
||||||
|
/* description */
|
||||||
|
sprintf(__('delete all %s settings'), 'translater')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addDirectAction(
|
$this->addDirectAction(
|
||||||
/* type */ 'plugins',
|
/* type */
|
||||||
/* action */ 'delete',
|
'plugins',
|
||||||
/* ns */ 'translater',
|
/* action */
|
||||||
/* description */ sprintf(__('delete %s plugin files'), 'translater')
|
'delete',
|
||||||
|
/* ns */
|
||||||
|
'translater',
|
||||||
|
/* description */
|
||||||
|
sprintf(__('delete %s plugin files'), 'translater')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addDirectAction(
|
$this->addDirectAction(
|
||||||
/* type */ 'versions',
|
/* type */
|
||||||
/* action */ 'delete',
|
'versions',
|
||||||
/* ns */ 'translater',
|
/* action */
|
||||||
/* description */ sprintf(__('delete %s version number'), 'translater')
|
'delete',
|
||||||
|
/* ns */
|
||||||
|
'translater',
|
||||||
|
/* description */
|
||||||
|
sprintf(__('delete %s version number'), 'translater')
|
||||||
);
|
);
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class dcTranslaterLang
|
class dcTranslaterLang
|
||||||
{
|
{
|
||||||
/** @var dCore dcCore instance */
|
/** @var dCore dcCore instance */
|
||||||
|
@ -85,7 +84,6 @@ class dcTranslaterLang
|
||||||
|
|
||||||
# From str list
|
# From str list
|
||||||
foreach ($m_msgstrs as $rs) {
|
foreach ($m_msgstrs as $rs) {
|
||||||
|
|
||||||
if (!isset($res[$rs['msgid']])) {
|
if (!isset($res[$rs['msgid']])) {
|
||||||
$res[$rs['msgid']]['files'][] = [];
|
$res[$rs['msgid']]['files'][] = [];
|
||||||
$res[$rs['msgid']]['in_dc'] = false;
|
$res[$rs['msgid']]['in_dc'] = false;
|
||||||
|
@ -114,6 +112,7 @@ class dcTranslaterLang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +155,7 @@ class dcTranslaterLang
|
||||||
|
|
||||||
unset($contents);
|
unset($contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,9 +199,9 @@ class dcTranslaterLang
|
||||||
];
|
];
|
||||||
$exists[] = $entry['msgid'];
|
$exists[] = $entry['msgid'];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +80,7 @@ class dcTranslaterModule
|
||||||
if ($this->prop['root_writable']) {
|
if ($this->prop['root_writable']) {
|
||||||
$dir = $this->prop['locales'];
|
$dir = $this->prop['locales'];
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'plugin':
|
case 'plugin':
|
||||||
|
@ -88,6 +88,7 @@ class dcTranslaterModule
|
||||||
if ($tmp && is_writable($tmp)) {
|
if ($tmp && is_writable($tmp)) {
|
||||||
$dir = $tmp;
|
$dir = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'public':
|
case 'public':
|
||||||
|
@ -95,6 +96,7 @@ class dcTranslaterModule
|
||||||
if ($tmp && is_writable($tmp)) {
|
if ($tmp && is_writable($tmp)) {
|
||||||
$dir = $tmp;
|
$dir = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'cache':
|
case 'cache':
|
||||||
|
@ -103,6 +105,7 @@ class dcTranslaterModule
|
||||||
@mkDir($tmp . '/l10n');
|
@mkDir($tmp . '/l10n');
|
||||||
$dir = $tmp . '/l10n';
|
$dir = $tmp . '/l10n';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'translater':
|
case 'translater':
|
||||||
|
@ -111,11 +114,13 @@ class dcTranslaterModule
|
||||||
@mkDir($tmp . '/locales');
|
@mkDir($tmp . '/locales');
|
||||||
$dir = $tmp . '/locales';
|
$dir = $tmp . '/locales';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!$dir && $throw) {
|
if (!$dir && $throw) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to find backups folder for module %s'), $id
|
__('Failed to find backups folder for module %s'),
|
||||||
|
$id
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +142,7 @@ class dcTranslaterModule
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
$files = dcTranslater::scandir($backup);
|
$files = dcTranslater::scandir($backup);
|
||||||
foreach($files AS $file) {
|
foreach ($files as $file) {
|
||||||
$is_backup = preg_match(sprintf($this->backup_file_regexp, preg_quote($this->prop['id'])), $file, $m);
|
$is_backup = preg_match(sprintf($this->backup_file_regexp, preg_quote($this->prop['id'])), $file, $m);
|
||||||
|
|
||||||
if (is_dir($backup . '/' . $file)
|
if (is_dir($backup . '/' . $file)
|
||||||
|
@ -158,6 +163,7 @@ class dcTranslaterModule
|
||||||
$res[$m[1]][$file]['module'] = $this->prop['id'];
|
$res[$m[1]][$file]['module'] = $this->prop['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +179,8 @@ class dcTranslaterModule
|
||||||
|
|
||||||
if (!is_dir($this->prop['locales'] . '/' . $lang)) {
|
if (!is_dir($this->prop['locales'] . '/' . $lang)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to find language %s'), $lang
|
__('Failed to find language %s'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,8 +190,7 @@ class dcTranslaterModule
|
||||||
if (!is_dir($this->prop['locales'] . '/' . $lang . '/' . $file)
|
if (!is_dir($this->prop['locales'] . '/' . $lang . '/' . $file)
|
||||||
&& (dcTranslater::isLangphpFile($file) || dcTranslater::isPoFile($file))
|
&& (dcTranslater::isLangphpFile($file) || dcTranslater::isPoFile($file))
|
||||||
) {
|
) {
|
||||||
$res[$this->prop['locales'] . '/' . $lang . '/' .$file] =
|
$res[$this->prop['locales'] . '/' . $lang . '/' . $file] = $this->prop['id'] . '/locales/' . $lang . '/' . $file;
|
||||||
$this->prop['id'] . '/locales/' . $lang . '/' . $file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +200,7 @@ class dcTranslaterModule
|
||||||
@set_time_limit(300);
|
@set_time_limit(300);
|
||||||
$fp = fopen($backup . '/l10n-' . $this->prop['id'] . '-' . $lang . '-' . time() . '.bck.zip', 'wb');
|
$fp = fopen($backup . '/l10n-' . $this->prop['id'] . '-' . $lang . '-' . time() . '.bck.zip', 'wb');
|
||||||
$zip = new fileZip($fp);
|
$zip = new fileZip($fp);
|
||||||
foreach($res AS $from => $to) {
|
foreach ($res as $from => $to) {
|
||||||
$zip->addFile($from, $to);
|
$zip->addFile($from, $to);
|
||||||
}
|
}
|
||||||
$zip->write();
|
$zip->write();
|
||||||
|
@ -217,14 +223,15 @@ class dcTranslaterModule
|
||||||
|
|
||||||
if (!file_exists($backup . '/' . $file)) {
|
if (!file_exists($backup . '/' . $file)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to find file %s'), $file
|
__('Failed to find file %s'),
|
||||||
|
$file
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip = new fileUnzip($backup . '/' . $file);
|
$zip = new fileUnzip($backup . '/' . $file);
|
||||||
$zip_files = $zip->getFilesList();
|
$zip_files = $zip->getFilesList();
|
||||||
|
|
||||||
foreach($zip_files AS $zip_file) {
|
foreach ($zip_files as $zip_file) {
|
||||||
$f = $this->parseZipFilename($zip_file, true);
|
$f = $this->parseZipFilename($zip_file, true);
|
||||||
$zip->unzip($zip_file, $this->prop['locales'] . '/' . $f['lang'] . '/' . $f['group'] . $f['ext']);
|
$zip->unzip($zip_file, $this->prop['locales'] . '/' . $f['lang'] . '/' . $f['group'] . $f['ext']);
|
||||||
$done = true;
|
$done = true;
|
||||||
|
@ -256,7 +263,8 @@ class dcTranslaterModule
|
||||||
|
|
||||||
if (!files::isDeletable($backup . '/' . $file)) {
|
if (!files::isDeletable($backup . '/' . $file)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to delete file %s'), $file
|
__('Failed to delete file %s'),
|
||||||
|
$file
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +298,7 @@ class dcTranslaterModule
|
||||||
&& file_exists($this->prop['locales'] . '/' . $f['lang'] . '/' . $f['group'] . $f['ext'])
|
&& file_exists($this->prop['locales'] . '/' . $f['lang'] . '/' . $f['group'] . $f['ext'])
|
||||||
) {
|
) {
|
||||||
$not_overwrited[] = implode('-', [$f['lang'], $f['group'], $f['ext']]);
|
$not_overwrited[] = implode('-', [$f['lang'], $f['group'], $f['ext']]);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,13 +322,16 @@ class dcTranslaterModule
|
||||||
|
|
||||||
if (!empty($not_overwrited)) {
|
if (!empty($not_overwrited)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Some languages has not been overwrited %s'), implode(', ', $not_overwrited)
|
__('Some languages has not been overwrited %s'),
|
||||||
|
implode(', ', $not_overwrited)
|
||||||
));
|
));
|
||||||
} elseif (!$done) {
|
} elseif (!$done) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Nothing to import from %s'), $zip_file['name']
|
__('Nothing to import from %s'),
|
||||||
|
$zip_file['name']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,14 +356,13 @@ class dcTranslaterModule
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
foreach($langs AS $lang) {
|
foreach ($langs as $lang) {
|
||||||
if (!is_dir($this->prop['locales'] . '/' . $lang)) {
|
if (!is_dir($this->prop['locales'] . '/' . $lang)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$files = dcTranslater::scandir($this->prop['locales'] . '/' . $lang);
|
$files = dcTranslater::scandir($this->prop['locales'] . '/' . $lang);
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
||||||
if (is_dir($this->prop['locales'] . '/' . $lang . '/' . $file)
|
if (is_dir($this->prop['locales'] . '/' . $lang . '/' . $file)
|
||||||
|| !dcTranslater::isLangphpFile($file)
|
|| !dcTranslater::isLangphpFile($file)
|
||||||
&& !dcTranslater::isPoFile($file)
|
&& !dcTranslater::isPoFile($file)
|
||||||
|
@ -359,8 +370,7 @@ class dcTranslaterModule
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res[$this->prop['locales'] . '/' . $lang . '/' . $file] =
|
$res[$this->prop['locales'] . '/' . $lang . '/' . $file] = $this->prop['id'] . '/locales/' . $lang . '/' . $file;
|
||||||
$this->prop['id'] . '/locales/' . $lang . '/' . $file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,11 +421,14 @@ class dcTranslaterModule
|
||||||
if (!$is_file || !$module || !$lang || !$group || !$ext) {
|
if (!$is_file || !$module || !$lang || !$group || !$ext) {
|
||||||
if ($throw) {
|
if ($throw) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Zip file %s is not in translater format'), $file
|
__('Zip file %s is not in translater format'),
|
||||||
|
$file
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'module' => $module,
|
'module' => $module,
|
||||||
'lang' => $lang,
|
'lang' => $lang,
|
||||||
|
@ -455,6 +468,7 @@ class dcTranslaterModule
|
||||||
$res[$m[1]] = l10n::getLanguageName($m[1]); // Lang name
|
$res[$m[1]] = l10n::getLanguageName($m[1]); // Lang name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,14 +503,16 @@ class dcTranslaterModule
|
||||||
{
|
{
|
||||||
if (!l10n::isCode($lang)) {
|
if (!l10n::isCode($lang)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Unknow language %s'), $lang
|
__('Unknow language %s'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$langs = $this->getLangs();
|
$langs = $this->getLangs();
|
||||||
if (isset($langs[$lang])) {
|
if (isset($langs[$lang])) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Language %s already exists'), $lang
|
__('Language %s already exists'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +520,8 @@ class dcTranslaterModule
|
||||||
|
|
||||||
if (!empty($from_lang) && !isset($langs[$from_lang])) {
|
if (!empty($from_lang) && !isset($langs[$from_lang])) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to copy file from language %s'), $from_lang
|
__('Failed to copy file from language %s'),
|
||||||
|
$from_lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,7 +535,8 @@ class dcTranslaterModule
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
files::putContent($this->prop['locales'] . '/' . $lang . '/' . $file,
|
files::putContent(
|
||||||
|
$this->prop['locales'] . '/' . $lang . '/' . $file,
|
||||||
file_get_contents($this->prop['locales'] . '/' . $from_lang . '/' . $file)
|
file_get_contents($this->prop['locales'] . '/' . $from_lang . '/' . $file)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -538,14 +556,16 @@ class dcTranslaterModule
|
||||||
{
|
{
|
||||||
if (!l10n::isCode($lang)) {
|
if (!l10n::isCode($lang)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Unknow language %s'), $lang
|
__('Unknow language %s'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$langs = $this->getLangs();
|
$langs = $this->getLangs();
|
||||||
if (!isset($langs[$lang])) {
|
if (!isset($langs[$lang])) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to find language %s'), $lang
|
__('Failed to find language %s'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +599,8 @@ class dcTranslaterModule
|
||||||
|
|
||||||
if (empty($rs)) {
|
if (empty($rs)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('No string to write, language %s deleted'), $lang
|
__('No string to write, language %s deleted'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,14 +622,16 @@ class dcTranslaterModule
|
||||||
# Path is right formed
|
# Path is right formed
|
||||||
if (!l10n::isCode($lang)) {
|
if (!l10n::isCode($lang)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Unknow language %s'), $lang
|
__('Unknow language %s'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$files = $this->getLangs(true);
|
$files = $this->getLangs(true);
|
||||||
if (!isset($files[$lang])) {
|
if (!isset($files[$lang])) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to find language %s'), $lang
|
__('Failed to find language %s'),
|
||||||
|
$lang
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,6 +648,7 @@ class dcTranslaterModule
|
||||||
if (empty($loc)) {
|
if (empty($loc)) {
|
||||||
rmdir($this->prop['locales']);
|
rmdir($this->prop['locales']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,14 +665,13 @@ class dcTranslaterModule
|
||||||
|
|
||||||
$content = '';
|
$content = '';
|
||||||
if ($this->translater->parse_comment) {
|
if ($this->translater->parse_comment) {
|
||||||
$content .=
|
$content .= '# Language: ' . $lang->name . "\n" .
|
||||||
'# Language: ' . $lang->name . "\n" .
|
'# Module: ' . $this->id . ' - ' . $this->version . "\n" .
|
||||||
'# Module: ' . $this->id . " - " . $this->version . "\n" .
|
|
||||||
'# Date: ' . dt::str('%Y-%m-%d %H:%M:%S') . "\n";
|
'# Date: ' . dt::str('%Y-%m-%d %H:%M:%S') . "\n";
|
||||||
|
|
||||||
if ($this->translater->parse_user && $this->translater->parse_userinfo != '') {
|
if ($this->translater->parse_user && $this->translater->parse_userinfo != '') {
|
||||||
$search = dctranslater::$allowed_user_informations;
|
$search = dctranslater::$allowed_user_informations;
|
||||||
foreach($search AS $n) {
|
foreach ($search as $n) {
|
||||||
$replace[] = $this->core->auth->getInfo('user_' . $n);
|
$replace[] = $this->core->auth->getInfo('user_' . $n);
|
||||||
}
|
}
|
||||||
$info = trim(str_replace($search, $replace, $this->translater->parse_userinfo));
|
$info = trim(str_replace($search, $replace, $this->translater->parse_userinfo));
|
||||||
|
@ -656,11 +679,9 @@ class dcTranslaterModule
|
||||||
$content .= '# Author: ' . html::escapeHTML($info) . "\n";
|
$content .= '# Author: ' . html::escapeHTML($info) . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$content .=
|
$content .= '# Translated with translater ' . $this->core->plugins->moduleInfo('translater', 'version') . "\n\n";
|
||||||
'# Translated with translater ' . $this->core->plugins->moduleInfo('translater', 'version') . "\n\n";
|
|
||||||
}
|
}
|
||||||
$content .=
|
$content .= "msgid \"\"\n" .
|
||||||
"msgid \"\"\n" .
|
|
||||||
"msgstr \"\"\n" .
|
"msgstr \"\"\n" .
|
||||||
'"Content-Type: text/plain; charset=UTF-8\n"' . "\n" .
|
'"Content-Type: text/plain; charset=UTF-8\n"' . "\n" .
|
||||||
'"Project-Id-Version: ' . $this->id . ' ' . $this->version . '\n"' . "\n" .
|
'"Project-Id-Version: ' . $this->id . ' ' . $this->version . '\n"' . "\n" .
|
||||||
|
@ -676,8 +697,7 @@ class dcTranslaterModule
|
||||||
if ($this->translater->parse_comment) {
|
if ($this->translater->parse_comment) {
|
||||||
$msgids = $lang->getMsgids();
|
$msgids = $lang->getMsgids();
|
||||||
foreach ($msgids as $msg) {
|
foreach ($msgids as $msg) {
|
||||||
$comments[$msg['msgid']] = (isset($comments[$msg['msgid']]) ?
|
$comments[$msg['msgid']] = ($comments[$msg['msgid']] ?? '') .
|
||||||
$comments[$msg['msgid']] : '') .
|
|
||||||
'#: ' . trim($msg['file'], '/') . ':' . $msg['line'] . "\n";
|
'#: ' . trim($msg['file'], '/') . ':' . $msg['line'] . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,13 +726,15 @@ class dcTranslaterModule
|
||||||
if (is_dir($path['dirname']) && !is_writable($path['dirname'])
|
if (is_dir($path['dirname']) && !is_writable($path['dirname'])
|
||||||
|| file_exists($file) && !is_writable($file)) {
|
|| file_exists($file) && !is_writable($file)) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to grant write acces on file %s'), $file
|
__('Failed to grant write acces on file %s'),
|
||||||
|
$file
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($f = @files::putContent($file, $content))) {
|
if (!($f = @files::putContent($file, $content))) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
__('Failed to write file %s'), $file
|
__('Failed to write file %s'),
|
||||||
|
$file
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -734,9 +756,8 @@ class dcTranslaterModule
|
||||||
|
|
||||||
$content = '';
|
$content = '';
|
||||||
if ($this->translater->parse_comment) {
|
if ($this->translater->parse_comment) {
|
||||||
$content .=
|
$content .= '// Language: ' . $lang->name . "\n" .
|
||||||
'// Language: ' . $lang->name . "\n" .
|
'// Module: ' . $this->id . ' - ' . $this->verison . "\n" .
|
||||||
'// Module: ' . $this->id . " - " . $this->verison . "\n" .
|
|
||||||
'// Date: ' . dt::str('%Y-%m-%d %H:%M:%S') . "\n";
|
'// Date: ' . dt::str('%Y-%m-%d %H:%M:%S') . "\n";
|
||||||
|
|
||||||
if ($this->translater->parse_user && !empty($this->translater->parse_userinfo)) {
|
if ($this->translater->parse_user && !empty($this->translater->parse_userinfo)) {
|
||||||
|
@ -749,8 +770,7 @@ class dcTranslaterModule
|
||||||
$content .= '// Author: ' . html::escapeHTML($info) . "\n";
|
$content .= '// Author: ' . html::escapeHTML($info) . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$content .=
|
$content .= '// Translated with dcTranslater - ' . $this->core->plugins->moduleInfo('translater', 'version') . "\n\n";
|
||||||
'// Translated with dcTranslater - ' . $this->core->plugins->moduleInfo('translater', 'version') . "\n\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l10n::generatePhpFileFromPo($this->locales . '/' . $lang->code . '/' . $group, $content);
|
l10n::generatePhpFileFromPo($this->locales . '/' . $lang->code . '/' . $group, $content);
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -224,6 +223,7 @@ class dcTranslater
|
||||||
$s = self::$default_settings[$id];
|
$s = self::$default_settings[$id];
|
||||||
$this->core->blog->settings->translater->drop($s['id']);
|
$this->core->blog->settings->translater->drop($s['id']);
|
||||||
$this->core->blog->settings->translater->put($s['id'], $value, $s['type'], $s['label'], $overwrite, true);
|
$this->core->blog->settings->translater->put($s['id'], $value, $s['type'], $s['label'], $overwrite, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,8 +290,10 @@ class dcTranslater
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
sprintf(__('Failed to find module %s'), $id)
|
sprintf(__('Failed to find module %s'), $id)
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->modules[$type][$id];
|
return $this->modules[$type][$id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,8 +310,10 @@ class dcTranslater
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
sprintf(__('Failed find language %s'), $lang)
|
sprintf(__('Failed find language %s'), $lang)
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new dcTranslaterLang($module, $lang);
|
return new dcTranslaterLang($module, $lang);
|
||||||
}
|
}
|
||||||
//@}
|
//@}
|
||||||
|
@ -332,7 +336,7 @@ class dcTranslater
|
||||||
}
|
}
|
||||||
|
|
||||||
$files = files::scandir($path);
|
$files = files::scandir($path);
|
||||||
foreach($files AS $file) {
|
foreach ($files as $file) {
|
||||||
if (in_array($file, ['.', '..'])) {
|
if (in_array($file, ['.', '..'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -344,6 +348,7 @@ class dcTranslater
|
||||||
$res[] = empty($dir) ? $file : $dir . '/' . $file;
|
$res[] = empty($dir) ? $file : $dir . '/' . $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,14 +373,15 @@ class dcTranslater
|
||||||
public static function poString(string $string, bool $reverse = false): string
|
public static function poString(string $string, bool $reverse = false): string
|
||||||
{
|
{
|
||||||
if ($reverse) {
|
if ($reverse) {
|
||||||
$smap = array('"', "\n", "\t", "\r");
|
$smap = ['"', "\n", "\t", "\r"];
|
||||||
$rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r');
|
$rmap = ['\\"', '\\n"' . "\n" . '"', '\\t', '\\r'];
|
||||||
|
|
||||||
return trim((string) str_replace($smap, $rmap, $string));
|
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));
|
|
||||||
}
|
}
|
||||||
|
$smap = ['/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\\"/'];
|
||||||
|
$rmap = ['', "\n", "\r", "\t", '"'];
|
||||||
|
|
||||||
|
return trim((string) preg_replace($smap, $rmap, $string));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -411,7 +417,7 @@ class dcTranslater
|
||||||
public static function isBackupLimit(string $root, int $limit = 10, bool $throw = false): bool
|
public static function isBackupLimit(string $root, int $limit = 10, bool $throw = false): bool
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach(self::scandir($root) AS $file) {
|
foreach (self::scandir($root) as $file) {
|
||||||
if (!is_dir($root . '/' . $file)
|
if (!is_dir($root . '/' . $file)
|
||||||
&& preg_match('/^(l10n-' . $id . '(.*?).bck.zip)$/', $root)
|
&& preg_match('/^(l10n-' . $id . '(.*?).bck.zip)$/', $root)
|
||||||
) {
|
) {
|
||||||
|
@ -426,8 +432,10 @@ class dcTranslater
|
||||||
sprintf(__('Limit of %s backups for module %s exceed'), $this->backup_limit, $id)
|
sprintf(__('Limit of %s backups for module %s exceed'), $this->backup_limit, $id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,6 +472,7 @@ class dcTranslater
|
||||||
// should start with quote
|
// should start with quote
|
||||||
if (!in_array(substr($part, 0, 1), ['"', "'"])) {
|
if (!in_array(substr($part, 0, 1), ['"', "'"])) {
|
||||||
$p++;
|
$p++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// put back first parenthesis
|
// put back first parenthesis
|
||||||
|
@ -485,6 +494,7 @@ class dcTranslater
|
||||||
}
|
}
|
||||||
$p++;
|
$p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $final_strings;
|
return $final_strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,6 +537,7 @@ class dcTranslater
|
||||||
}
|
}
|
||||||
$p++;
|
$p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $final_strings;
|
return $final_strings;
|
||||||
}
|
}
|
||||||
//@}
|
//@}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class translaterProposals
|
||||||
{
|
{
|
||||||
public $core;
|
public $core;
|
||||||
|
|
||||||
private $stack = array();
|
private $stack = [];
|
||||||
|
|
||||||
public function __construct($core)
|
public function __construct($core)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +63,7 @@ class translaterRest
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$core->error->add($e->getMessage());
|
$core->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rsp;
|
return $rsp;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -60,12 +59,12 @@ class googleProposalTool extends translaterProposalTool
|
||||||
public function translate($str, $from, $to)
|
public function translate($str, $from, $to)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$data = array(
|
$data = [
|
||||||
'key' => $this->key,
|
'key' => $this->key,
|
||||||
'q' => $str,
|
'q' => $str,
|
||||||
'source' => $from,
|
'source' => $from,
|
||||||
'target' => $to
|
'target' => $to
|
||||||
);
|
];
|
||||||
|
|
||||||
$path = '';
|
$path = '';
|
||||||
$client = netHttp::initClient($this->api, $path);
|
$client = netHttp::initClient($this->api, $path);
|
||||||
|
@ -89,8 +88,9 @@ class googleProposalTool extends translaterProposalTool
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dec->data->translations[0]->translatedText;
|
return $dec->data->translations[0]->translatedText;
|
||||||
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
catch (Exception $e) {}
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +69,8 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->doYourFuckingJob($this->client, $this->secret, $str, $from, $to);
|
return $this->doYourFuckingJob($this->client, $this->secret, $str, $from, $to);
|
||||||
} catch (Exception $e) {}
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -87,16 +87,16 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
//Client Secret key of the application.
|
//Client Secret key of the application.
|
||||||
$clientSecret = $secret;
|
$clientSecret = $secret;
|
||||||
//OAuth Url.
|
//OAuth Url.
|
||||||
$authUrl = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
|
$authUrl = 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/';
|
||||||
//Application Scope Url
|
//Application Scope Url
|
||||||
$scopeUrl = "http://api.microsofttranslator.com";
|
$scopeUrl = 'http://api.microsofttranslator.com';
|
||||||
//Application grant type
|
//Application grant type
|
||||||
$grantType = "client_credentials";
|
$grantType = 'client_credentials';
|
||||||
|
|
||||||
//Get the Access token.
|
//Get the Access token.
|
||||||
$accessToken = $this->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
|
$accessToken = $this->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
|
||||||
//Create the authorization Header string.
|
//Create the authorization Header string.
|
||||||
$authHeader = "Authorization: Bearer " . $accessToken;
|
$authHeader = 'Authorization: Bearer ' . $accessToken;
|
||||||
|
|
||||||
//Set the params.//
|
//Set the params.//
|
||||||
$fromLanguage = $from;
|
$fromLanguage = $from;
|
||||||
|
@ -105,7 +105,7 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
$contentType = 'text/plain';
|
$contentType = 'text/plain';
|
||||||
$category = 'general';
|
$category = 'general';
|
||||||
|
|
||||||
$params = "text=" . urlencode($inputStr) . "&to=" . $toLanguage . "&from=" . $fromLanguage;
|
$params = 'text=' . urlencode($inputStr) . '&to=' . $toLanguage . '&from=' . $fromLanguage;
|
||||||
$translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?$params";
|
$translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?$params";
|
||||||
|
|
||||||
//Get the curlResponse.
|
//Get the curlResponse.
|
||||||
|
@ -148,22 +148,22 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
//Initialize the Curl Session.
|
//Initialize the Curl Session.
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
//Create the request Array.
|
//Create the request Array.
|
||||||
$paramArr = array (
|
$paramArr = [
|
||||||
'grant_type' => $grantType,
|
'grant_type' => $grantType,
|
||||||
'scope' => $scopeUrl,
|
'scope' => $scopeUrl,
|
||||||
'client_id' => $clientID,
|
'client_id' => $clientID,
|
||||||
'client_secret' => $clientSecret
|
'client_secret' => $clientSecret
|
||||||
);
|
];
|
||||||
//Create an Http Query.//
|
//Create an Http Query.//
|
||||||
$paramArr = http_build_query($paramArr);
|
$paramArr = http_build_query($paramArr);
|
||||||
//Set the Curl URL.
|
//Set the Curl URL.
|
||||||
curl_setopt($ch, CURLOPT_URL, $authUrl);
|
curl_setopt($ch, CURLOPT_URL, $authUrl);
|
||||||
//Set HTTP POST Request.
|
//Set HTTP POST Request.
|
||||||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
//Set data to POST in HTTP "POST" Operation.
|
//Set data to POST in HTTP "POST" Operation.
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArr);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArr);
|
||||||
//CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
|
//CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
|
||||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
//CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
|
//CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
//Execute the cURL session.
|
//Execute the cURL session.
|
||||||
|
@ -173,6 +173,7 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
if ($curlErrno) {
|
if ($curlErrno) {
|
||||||
$curlError = curl_error($ch);
|
$curlError = curl_error($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
throw new Exception($curlError);
|
throw new Exception($curlError);
|
||||||
}
|
}
|
||||||
//Close the Curl Session.
|
//Close the Curl Session.
|
||||||
|
@ -182,6 +183,7 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
if (@$objResponse->error) {
|
if (@$objResponse->error) {
|
||||||
throw new Exception($objResponse->error_description);
|
throw new Exception($objResponse->error_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $objResponse->access_token;
|
return $objResponse->access_token;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -198,17 +200,18 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
* @return string.
|
* @return string.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function curlRequest($url, $authHeader) {
|
private function curlRequest($url, $authHeader)
|
||||||
|
{
|
||||||
//Initialize the Curl Session.
|
//Initialize the Curl Session.
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
//Set the Curl url.
|
//Set the Curl url.
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
//Set the HTTP HEADER Fields.
|
//Set the HTTP HEADER Fields.
|
||||||
curl_setopt ($ch, CURLOPT_HTTPHEADER, array($authHeader,"Content-Type: text/xml"));
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [$authHeader,'Content-Type: text/xml']);
|
||||||
//CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
|
//CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
|
||||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
//CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
|
//CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
|
||||||
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
//Execute the cURL session.
|
//Execute the cURL session.
|
||||||
$curlResponse = curl_exec($ch);
|
$curlResponse = curl_exec($ch);
|
||||||
//Get the Error Code returned by Curl.
|
//Get the Error Code returned by Curl.
|
||||||
|
@ -216,10 +219,12 @@ class microsoftProposalTool extends translaterProposalTool
|
||||||
if ($curlErrno) {
|
if ($curlErrno) {
|
||||||
$curlError = curl_error($ch);
|
$curlError = curl_error($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
throw new Exception($curlError);
|
throw new Exception($curlError);
|
||||||
}
|
}
|
||||||
//Close a cURL session.
|
//Close a cURL session.
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
return $curlResponse;
|
return $curlResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
50
index.php
50
index.php
|
@ -10,7 +10,6 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +76,7 @@ try {
|
||||||
|
|
||||||
if ($action == 'module_restore_backup') {
|
if ($action == 'module_restore_backup') {
|
||||||
if (empty($module) || empty($_POST['files'])) {
|
if (empty($module) || empty($_POST['files'])) {
|
||||||
throw New Exception(__('Nothing to restore'));
|
throw new Exception(__('Nothing to restore'));
|
||||||
}
|
}
|
||||||
$module_backups = $module->getBackups(true);
|
$module_backups = $module->getBackups(true);
|
||||||
foreach ($module_backups as $backup_file) {
|
foreach ($module_backups as $backup_file) {
|
||||||
|
@ -91,7 +90,7 @@ try {
|
||||||
|
|
||||||
if ($action == 'module_delete_backup') {
|
if ($action == 'module_delete_backup') {
|
||||||
if (empty($module) || empty($_POST['files'])) {
|
if (empty($module) || empty($_POST['files'])) {
|
||||||
throw New Exception(__('Nothing to delete'));
|
throw new Exception(__('Nothing to delete'));
|
||||||
}
|
}
|
||||||
$module_backups = $module->getBackups(true);
|
$module_backups = $module->getBackups(true);
|
||||||
foreach ($module_backups as $backup_file) {
|
foreach ($module_backups as $backup_file) {
|
||||||
|
@ -162,9 +161,7 @@ try {
|
||||||
|
|
||||||
dcPage::addSuccessNotice(__('Language successfully updated'));
|
dcPage::addSuccessNotice(__('Language successfully updated'));
|
||||||
$core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]);
|
$core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$core->error->add($e->getMessage());
|
$core->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -246,14 +243,12 @@ if (empty($module) && $type != '') {
|
||||||
</tr>' .
|
</tr>' .
|
||||||
$res .
|
$res .
|
||||||
'</table></div>';
|
'</table></div>';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo '<tr><td colspan="6">' . __('There is no editable modules') . '</td></tr>';
|
echo '<tr><td colspan="6">' . __('There is no editable modules') . '</td></tr>';
|
||||||
}
|
}
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
|
|
||||||
dcPage::helpBlock('translater.type');
|
dcPage::helpBlock('translater.type');
|
||||||
|
|
||||||
} elseif (!empty($module) && empty($lang)) {
|
} elseif (!empty($module) && empty($lang)) {
|
||||||
$codes = $module->getUsedLangs();
|
$codes = $module->getUsedLangs();
|
||||||
$backups = $module->getBackups();
|
$backups = $module->getBackups();
|
||||||
|
@ -282,7 +277,7 @@ if (empty($module) && $type != '') {
|
||||||
'<th class="nowrap">' . __('Last backup') . '</th>' .
|
'<th class="nowrap">' . __('Last backup') . '</th>' .
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
||||||
foreach($codes AS $code_name => $code_id) {
|
foreach ($codes as $code_name => $code_id) {
|
||||||
echo
|
echo
|
||||||
'<tr class="line">' .
|
'<tr class="line">' .
|
||||||
'<td class="minimal">' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '</td>' .
|
'<td class="minimal">' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '</td>' .
|
||||||
|
@ -294,7 +289,7 @@ if (empty($module) && $type != '') {
|
||||||
'<td class="nowrap maximal"> ' . $code_id . '</td>';
|
'<td class="nowrap maximal"> ' . $code_id . '</td>';
|
||||||
|
|
||||||
if (isset($backups[$code_id])) {
|
if (isset($backups[$code_id])) {
|
||||||
foreach($backups[$code_id] AS $file => $info) {
|
foreach ($backups[$code_id] as $file => $info) {
|
||||||
$time[$code_id] = isset($time[$code_id]) && $time[$code_id] > $info['time'] ?
|
$time[$code_id] = isset($time[$code_id]) && $time[$code_id] > $info['time'] ?
|
||||||
$time[$code_id] : $info['time'];
|
$time[$code_id] : $info['time'];
|
||||||
}
|
}
|
||||||
|
@ -343,8 +338,7 @@ if (empty($module) && $type != '') {
|
||||||
'<th class="nowrap">' . __('Size') . '</th>' .
|
'<th class="nowrap">' . __('Size') . '</th>' .
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
||||||
$table_line =
|
$table_line = '<tr class="line">' .
|
||||||
'<tr class="line">' .
|
|
||||||
'<td class="minimal">%s</td>' .
|
'<td class="minimal">%s</td>' .
|
||||||
'<td class="nowrap"><label for="%s">%s</label></td>' .
|
'<td class="nowrap"><label for="%s">%s</label></td>' .
|
||||||
'<td class="nowrap maximal">%s</td>' .
|
'<td class="nowrap maximal">%s</td>' .
|
||||||
|
@ -358,9 +352,11 @@ if (empty($module) && $type != '') {
|
||||||
foreach ($backup_codes as $backup_file => $backup_code) {
|
foreach ($backup_codes as $backup_file => $backup_code) {
|
||||||
$i++;
|
$i++;
|
||||||
$form_id = 'form_file_' . $backup_code['code'] . $backup_code['time'];
|
$form_id = 'form_file_' . $backup_code['code'] . $backup_code['time'];
|
||||||
echo sprintf($table_line,
|
echo sprintf(
|
||||||
|
$table_line,
|
||||||
form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false),
|
form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false),
|
||||||
$form_id, $backup_code['name'],
|
$form_id,
|
||||||
|
$backup_code['name'],
|
||||||
$backup_code['code'],
|
$backup_code['code'],
|
||||||
dt::str(
|
dt::str(
|
||||||
$core->blog->settings->system->date_format . ' ' . $core->blog->settings->system->time_format,
|
$core->blog->settings->system->date_format . ' ' . $core->blog->settings->system->time_format,
|
||||||
|
@ -434,7 +430,6 @@ if (empty($module) && $type != '') {
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
dcPage::helpBlock('translater.module');
|
dcPage::helpBlock('translater.module');
|
||||||
|
|
||||||
} elseif (!empty($lang)) {
|
} elseif (!empty($lang)) {
|
||||||
$lines = $lang->getMessages();
|
$lines = $lang->getMessages();
|
||||||
|
|
||||||
|
@ -451,8 +446,7 @@ if (empty($module) && $type != '') {
|
||||||
'<th>' . __('File') . '</th>' .
|
'<th>' . __('File') . '</th>' .
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
||||||
$table_line =
|
$table_line = '<tr class="line%s">' .
|
||||||
'<tr class="line%s">' .
|
|
||||||
'<td class="nowrap minimal">%s</td>' .
|
'<td class="nowrap minimal">%s</td>' .
|
||||||
'<td class="nowrap minimal">%s</td>' .
|
'<td class="nowrap minimal">%s</td>' .
|
||||||
'<td>%s</td>' .
|
'<td>%s</td>' .
|
||||||
|
@ -464,7 +458,7 @@ if (empty($module) && $type != '') {
|
||||||
$table_li = '<i>%s</i><br />';
|
$table_li = '<i>%s</i><br />';
|
||||||
|
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($lines AS $msgid => $rs) {
|
foreach ($lines as $msgid => $rs) {
|
||||||
$in_dc = ($rs['in_dc'] && $translater->parse_nodc);
|
$in_dc = ($rs['in_dc'] && $translater->parse_nodc);
|
||||||
$allowed_l10n_groups = array_combine($translater::$allowed_l10n_groups, $translater::$allowed_l10n_groups);
|
$allowed_l10n_groups = array_combine($translater::$allowed_l10n_groups, $translater::$allowed_l10n_groups);
|
||||||
$t_msgstr = $t_files = $strin = [];
|
$t_msgstr = $t_files = $strin = [];
|
||||||
|
@ -491,11 +485,14 @@ if (empty($module) && $type != '') {
|
||||||
foreach ($rs['files'] as $location) {
|
foreach ($rs['files'] as $location) {
|
||||||
$res[] = sprintf($table_li, implode(' : ', $location));
|
$res[] = sprintf($table_li, implode(' : ', $location));
|
||||||
}
|
}
|
||||||
$t_files[] = sprintf($table_ul, sprintf(__('%s occurrences'), count($rs['files'])), implode('', $res));;
|
$t_files[] = sprintf($table_ul, sprintf(__('%s occurrences'), count($rs['files'])), implode('', $res));
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo sprintf($table_line, $in_dc ? ' offline' : ' translaterline',
|
echo sprintf(
|
||||||
|
$table_line,
|
||||||
|
$in_dc ? ' offline' : ' translaterline',
|
||||||
form::checkbox(['entries[' . $i . '][check]'], 1),
|
form::checkbox(['entries[' . $i . '][check]'], 1),
|
||||||
form::combo(['entries[' . $i . '][group]'], $allowed_l10n_groups, $rs['group'], '', '', $in_dc),
|
form::combo(['entries[' . $i . '][group]'], $allowed_l10n_groups, $rs['group'], '', '', $in_dc),
|
||||||
html::escapeHTML($msgid),
|
html::escapeHTML($msgid),
|
||||||
|
@ -524,7 +521,9 @@ if (empty($module) && $type != '') {
|
||||||
$t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res));
|
$t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res));
|
||||||
}
|
}
|
||||||
|
|
||||||
echo sprintf($table_line, $in_dc ? ' offline' : ' translaterline',
|
echo sprintf(
|
||||||
|
$table_line,
|
||||||
|
$in_dc ? ' offline' : ' translaterline',
|
||||||
'+',
|
'+',
|
||||||
sprintf(__('Plural "%s"'), $plural),
|
sprintf(__('Plural "%s"'), $plural),
|
||||||
sprintf(__('Plural form of "%s"'), $rs['plural']),
|
sprintf(__('Plural form of "%s"'), $rs['plural']),
|
||||||
|
@ -537,7 +536,9 @@ if (empty($module) && $type != '') {
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
echo sprintf($table_line, ' offline',
|
echo sprintf(
|
||||||
|
$table_line,
|
||||||
|
' offline',
|
||||||
form::checkbox(['entries[' . $i . '][check]'], 1),
|
form::checkbox(['entries[' . $i . '][check]'], 1),
|
||||||
form::combo(['entries[' . $i . '][group]'], $allowed_l10n_groups, 'main'),
|
form::combo(['entries[' . $i . '][group]'], $allowed_l10n_groups, 'main'),
|
||||||
form::field(['entries[' . $i . '][msgid]'], 48, 255, ''),
|
form::field(['entries[' . $i . '][msgid]'], 48, 255, ''),
|
||||||
|
@ -570,7 +571,6 @@ if (empty($module) && $type != '') {
|
||||||
'</div>';
|
'</div>';
|
||||||
|
|
||||||
dcPage::helpBlock('translater.lang');
|
dcPage::helpBlock('translater.lang');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$line = '<li><a href="%s"%s>%s</a></li>';
|
$line = '<li><a href="%s"%s>%s</a></li>';
|
||||||
echo '<h4><i>' . __('Translate your Dotclear plugins and themes') . '</i></h4>' .
|
echo '<h4><i>' . __('Translate your Dotclear plugins and themes') . '</i></h4>' .
|
||||||
|
@ -580,12 +580,14 @@ if (empty($module) && $type != '') {
|
||||||
$line,
|
$line,
|
||||||
$core->adminurl->get('translater', ['type' => 'plugin']),
|
$core->adminurl->get('translater', ['type' => 'plugin']),
|
||||||
$type == 'plugin' ? ' class="active"' : '',
|
$type == 'plugin' ? ' class="active"' : '',
|
||||||
__('Translate plugins')) .
|
__('Translate plugins')
|
||||||
|
) .
|
||||||
sprintf(
|
sprintf(
|
||||||
$line,
|
$line,
|
||||||
$core->adminurl->get('translater', ['type' => 'theme']),
|
$core->adminurl->get('translater', ['type' => 'theme']),
|
||||||
$type == 'theme' ? ' class="active"' : '',
|
$type == 'theme' ? ' class="active"' : '',
|
||||||
__('Translate themes'))
|
__('Translate themes')
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
dcPage::helpBlock('translater.index');
|
dcPage::helpBlock('translater.index');
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
/**
|
||||||
#
|
* @brief translater, a plugin for Dotclear 2
|
||||||
# This file is part of translater, a plugin for Dotclear 2.
|
*
|
||||||
#
|
* @package Dotclear
|
||||||
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
* @subpackage Plugin
|
||||||
#
|
*
|
||||||
# Licensed under the GPL version 2.0 license.
|
* @author Jean-Christian Denis & contributors
|
||||||
# A copy of this license is available in LICENSE file or at
|
*
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
* @copyright Jean-Christian Denis
|
||||||
#
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
# -- END LICENSE BLOCK ------------------------------------
|
*/
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue