@ -14,29 +14,29 @@ function formulaires_tradlang_importer_langue_charger_dist($id_tradlang_module,
$valeurs['lang_orig'] = $lang_orig;
$valeurs['lang_cible'] = $lang;
if (!$nom_mod = sql_getfetsel('nom_mod', 'spip_tradlang_modules', 'id_tradlang_module = ' . (int) $id_tradlang_module)) {
$valeurs['message_erreur'] = _T('tradlang:erreur_import_module_inexistant', ['id'=>$id_tradlang_module]);
$valeurs['message_erreur'] = _T('tradlang:erreur_import_module_inexistant', ['id' => $id_tradlang_module]);
$valeurs['editable'] = false;
} else {
if (_request('_etape') == '2') {
$module = sql_getfetsel('module', 'spip_tradlang_modules', 'id_tradlang_module = ' . (int) $id_tradlang_module);
$fichier_module = $module.'_'.$lang.'.php';
$fichier_module_po = $module.'_'.$lang.'.po';
$fichier_module = $module . '_' . $lang . '.php';
$fichier_module_po = $module . '_' . $lang . '.po';
$dir_lang = sous_repertoire(_DIR_VAR, 'cache-tradlang');
$dest = $dir_lang.$fichier_module;
$dest_po = $dir_lang.$fichier_module_po;
$dest = $dir_lang . $fichier_module;
$dest_po = $dir_lang . $fichier_module_po;
if (file_exists($dest) || file_exists($dest_po)) {
if (file_exists($dest)) {
$modifs = $undefined = [];
$memtrad = $GLOBALS['idx_lang'] = 'i18n_'.crc32($module).'_tmp';
$memtrad = $GLOBALS['idx_lang'] = 'i18n_' . crc32($module) . '_tmp';
include $dest;
/**
* Recuperation des statuts dans le fichier
*/
$contenu=file_get_contents($dest);
$contenu = file_get_contents($dest);
$contenu = str_replace("\t", '', $contenu);
$tab=preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY);
$liste_trad=[];
$tab = preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY);
$liste_trad = [];
reset($tab);
foreach ($tab as $ligne) {
@ -45,7 +45,7 @@ function formulaires_tradlang_importer_langue_charger_dist($id_tradlang_module,
if (isset($matches[1]) & & isset($matches[3]) & & strlen(trim($matches[3])) > 0) {
[, $comm] = explode('#', $matches[3]);
if (in_array(trim($comm), ['NEW', 'MODIF', 'RELIRE'])) {
$liste_trad[$matches[1]]=trim($comm);
$liste_trad[$matches[1]] = trim($comm);
}
}
}
@ -58,7 +58,7 @@ function formulaires_tradlang_importer_langue_charger_dist($id_tradlang_module,
if (!is_array($str_lang)) {
$erreurs['fichier_langue'] = _T('tradlang:erreur_upload_fichier_php_array', ['fichier' => $file['name']]);
} else {
$langues_base = sql_allfetsel('id,str,statut', 'spip_tradlangs', 'id_tradlang_module='.(int) $id_tradlang_module.' AND lang='.sql_quote($lang));
$langues_base = sql_allfetsel('id,str,statut', 'spip_tradlangs', 'id_tradlang_module=' . (int) $id_tradlang_module . ' AND lang=' . sql_quote($lang));
foreach ($langues_base as $strings_id => $strings) {
$str_lang[$strings['id']] = preg_replace(',^(< (MODIF|NEW|RELIRE|PLUS_UTILISE)>)+,US', '', $str_lang[$strings['id']]);
if (strlen($str_lang[$strings['id']]) > 0 & & $strings['str'] != $str_lang[$strings['id']]) {
@ -66,9 +66,9 @@ function formulaires_tradlang_importer_langue_charger_dist($id_tradlang_module,
} elseif (strlen($str_lang[$strings['id']]) == 0) {
$undefined[] = $strings['id'];
} elseif (in_array($strings['id'], $keys_liste_trad) & & $strings['statut'] != $liste_trad[$strings['id']]) {
$modifs[$strings['id']] = ['orig'=>$strings['str'], 'new'=>$str_lang[$strings['id']], 'statut' => $liste_trad[$strings['id']]];
$modifs[$strings['id']] = ['orig' => $strings['str'], 'new' => $str_lang[$strings['id']], 'statut' => $liste_trad[$strings['id']]];
} elseif (!in_array($strings['id'], $keys_liste_trad) & & $strings['statut'] != 'OK') {
$modifs[$strings['id']] = ['orig'=>$strings['str'], 'new'=>$str_lang[$strings['id']], 'statut' => 'OK'];
$modifs[$strings['id']] = ['orig' => $strings['str'], 'new' => $str_lang[$strings['id']], 'statut' => 'OK'];
}
unset($langues_base[$strings_id]);
}
@ -94,15 +94,15 @@ function formulaires_tradlang_importer_langue_charger_dist($id_tradlang_module,
$statut = 'MODIF';
}
if ($str != '') {
$array_po[$matches[1]] = ['str'=>$str, 'statut'=>$statut];
$array_po[$matches[1]] = ['str' => $str, 'statut' => $statut];
}
}
$modifs = [];
$langues_base = sql_allfetsel('id,str,statut', 'spip_tradlangs', 'module = ' . sql_quote($module).' AND lang = ' . sql_quote($lang));
$langues_base = sql_allfetsel('id,str,statut', 'spip_tradlangs', 'module = ' . sql_quote($module) . ' AND lang = ' . sql_quote($lang));
foreach ($langues_base as $strings_id => $strings) {
$str_lang[$strings['id']] = tradlang_utf8(preg_replace(',^(< (MODIF|NEW|PLUS_UTILISE)>)+,US', '', $str_lang[$strings['id']]));
if (isset($array_po[$strings['id']]['str']) & & strlen(trim($array_po[$strings['id']]['str'])) > 0 & & ($strings['str'] != $array_po[$strings['id']]['str'] || $strings['statut'] != $array_po[$strings['id']]['statut'])) {
$modifs[$strings['id']] = ['orig'=>$strings['str'], 'new'=>$array_po[$strings['id']]['str'], 'statut'=>$array_po[$strings['id']]['statut']];
$modifs[$strings['id']] = ['orig' => $strings['str'], 'new' => $array_po[$strings['id']]['str'], 'statut' => $array_po[$strings['id']]['statut']];
}
unset($langues_base[$strings_id]);
}
@ -123,10 +123,10 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
$fichiers_module = [];
$modifs = [];
$erreurs = [];
if (_request('_etape')==1) {
if (_request('_etape') == 1) {
$module = sql_getfetsel('module', 'spip_tradlang_modules', 'id_tradlang_module = ' . (int) $id_tradlang_module);
$fichier_php = $module.'_'.$lang.'.php';
$fichier_po = $module.'_'.$lang.'.po';
$fichier_php = $module . '_' . $lang . '.php';
$fichier_po = $module . '_' . $lang . '.po';
$fichiers_module[] = $fichier_php;
$fichiers_module[] = $fichier_po;
$post = $_FILES ?? $GLOBALS['HTTP_POST_FILES'];
@ -136,13 +136,13 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
foreach ($post as $file) {
if ($file['error'] != 4) {
if (!in_array($file['name'], $fichiers_module)) {
$fichier_module = $fichier_php.', '.$fichier_po;
$fichier_module = $fichier_php . ', ' . $fichier_po;
$erreurs['fichier_langue'] = _T('tradlang:erreur_upload_fichier_php', ['fichier' => $file['name'], 'fichier_attendu' => $fichier_module]);
}
if (!$erreurs['fichier_langue']) {
$dir_lang = sous_repertoire(_DIR_VAR, 'cache-tradlang');
$dest = $dir_lang.$file['name'];
$dest = $dir_lang . $file['name'];
@move_uploaded_file($file['tmp_name'], $dest);
if (!file_exists($dest)) {
$erreurs['message_erreur'] = 'Fichier temporaire non créé';
@ -151,16 +151,16 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
* Gestion du cas des fichiers php
*/
if ($file['name'] == $fichier_php) {
$memtrad = $GLOBALS['idx_lang'] = 'i18n_'.crc32($module).'_tmp';
$memtrad = $GLOBALS['idx_lang'] = 'i18n_' . crc32($module) . '_tmp';
include $dest;
/**
* Recuperation des statuts dans le fichier
*/
$contenu=file_get_contents($dest);
$contenu = file_get_contents($dest);
$contenu = str_replace("\t", '', $contenu);
$tab=preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY);
$liste_trad=[];
$tab = preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY);
$liste_trad = [];
reset($tab);
foreach ($tab as $ligne) {
@ -169,7 +169,7 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
if (isset($matches[1]) & & isset($matches[3]) & & strlen(trim($matches[3])) > 0) {
[, $comm] = explode('#', $matches[3]);
if (in_array(trim($comm), ['NEW', 'MODIF', 'RELIRE'])) {
$liste_trad[$matches[1]]=trim($comm);
$liste_trad[$matches[1]] = trim($comm);
}
}
}
@ -187,11 +187,11 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
foreach ($langues_base as $strings_id => $strings) {
$str_lang[$strings['id']] = tradlang_utf8(preg_replace(',^(< (MODIF|NEW|PLUS_UTILISE)>)+,US', '', $str_lang[$strings['id']]));
if ($strings['str'] != $str_lang[$strings['id']]) {
$modifs[$strings['id']] = ['orig'=>$strings['str'], 'new'=>$str_lang[$strings['id']]];
$modifs[$strings['id']] = ['orig' => $strings['str'], 'new' => $str_lang[$strings['id']]];
break;
}
if (in_array($strings['id'], $keys_liste_trad) & & $strings['statut'] != $liste_trad[$strings['id']]) {
$modifs[$strings['id']] = ['orig'=>$strings['str'], 'new'=>$str_lang[$strings['id']]];
$modifs[$strings['id']] = ['orig' => $strings['str'], 'new' => $str_lang[$strings['id']]];
break;
}
}
@ -213,7 +213,7 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
preg_match(',\nmsgid \"(.*)\nmsgstr,Uims', $match, $matches_str_orig);
$str_orig = rtrim(trim($matches_str_orig[1]), '"');
$str_orig = trim(str_replace("\"\n\"", '', $str_orig));
$matches[1] = sql_getfetsel('id', 'spip_tradlangs', 'id_tradlang_module = ' . (int) $id_tradlang_module . ' AND str = '.sql_quote($str_orig));
$matches[1] = sql_getfetsel('id', 'spip_tradlangs', 'id_tradlang_module = ' . (int) $id_tradlang_module . ' AND str = ' . sql_quote($str_orig));
}
if (preg_match(',\#\, fuzzy\, php-format,', $match, $matches_statut)) {
$statut = 'MODIF';
@ -231,7 +231,7 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
& & strlen(trim($array_po[$strings['id']]['str'])) > 0
& & ($strings['str'] != $array_po[$strings['id']]['str'] || $strings['statut'] != $array_po[$strings['id']]['statut'])
) {
$modifs[$strings['id']] = ['orig'=>$strings['str'], 'new'=>$array_po[$strings['id']]['str'], 'statut'=>$array_po[$strings['id']]['statut']];
$modifs[$strings['id']] = ['orig' => $strings['str'], 'new' => $array_po[$strings['id']]['str'], 'statut' => $array_po[$strings['id']]['statut']];
break;
}
}
@ -253,14 +253,14 @@ function formulaires_tradlang_importer_langue_verifier_1_dist($id_tradlang_modul
function formulaires_tradlang_importer_langue_verifier_2_dist($id_tradlang_module, $lang) {
$module = sql_getfetsel('module', 'spip_tradlang_modules', 'id_tradlang_module = ' . (int) $id_tradlang_module);
$fichier_php = $module.'_'.$lang.'.php';
$fichier_po = $module.'_'.$lang.'.po';
$fichier_php = $module . '_' . $lang . '.php';
$fichier_po = $module . '_' . $lang . '.po';
$dir_lang = sous_repertoire(_DIR_VAR, 'cache-tradlang');
$dest = $dir_lang.$fichier_php;
$destpo = $dir_lang.$fichier_po;
$dest = $dir_lang . $fichier_php;
$destpo = $dir_lang . $fichier_po;
$modifs = $erreurs = [];
if (file_exists($dest)) {
$memtrad = $GLOBALS['idx_lang'] = 'i18n_'.crc32($module).'_tmp';
$memtrad = $GLOBALS['idx_lang'] = 'i18n_' . crc32($module) . '_tmp';
include $dest;
$str_lang = $GLOBALS[$memtrad]; // on a vu certains fichiers faire des betises et modifier idx_lang
@ -296,30 +296,30 @@ function formulaires_tradlang_importer_langue_traiter_dist($id_tradlang_module,
include_spip('action/editer_tradlang');
$module = sql_getfetsel('module', 'spip_tradlang_modules', 'id_tradlang_module = ' . (int) $id_tradlang_module);
$fichier_php = $module.'_'.$lang.'.php';
$fichier_po = $module.'_'.$lang.'.po';
$fichier_php = $module . '_' . $lang . '.php';
$fichier_po = $module . '_' . $lang . '.po';
$dir_lang = sous_repertoire(_DIR_VAR, 'cache-tradlang');
$count=0;
if (file_exists($dest = $dir_lang.$fichier_php)) {
$memtrad = $GLOBALS['idx_lang'] = 'i18n_'.crc32($module).'_tmp';
$count = 0;
if (file_exists($dest = $dir_lang . $fichier_php)) {
$memtrad = $GLOBALS['idx_lang'] = 'i18n_' . crc32($module) . '_tmp';
include $dest;
/**
* Recuperation des statuts dans le fichier
*/
$contenu=file_get_contents($dest);
$contenu = file_get_contents($dest);
$contenu = str_replace("\t", '', $contenu);
$tab=preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY);
$liste_trad=[];
$tab = preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY);
$liste_trad = [];
reset($tab);
foreach ($tab as $ligne) {
$ligne = str_replace("\'", '', $ligne);
if (strlen($ligne)>0 & & preg_match("/\'(.*?)\'[\s\t]*=>[\s\t]*\'(.*?)\'[\s\t]*,{0,1}[\s\t]*(#.*)?/ms", $ligne, $matches)) {
if (strlen($ligne) > 0 & & preg_match("/\'(.*?)\'[\s\t]*=>[\s\t]*\'(.*?)\'[\s\t]*,{0,1}[\s\t]*(#.*)?/ms", $ligne, $matches)) {
if (isset($matches[1]) & & isset($matches[3]) & & strlen(trim($matches[3])) > 0) {
[, $comm] = explode('#', $matches[3]);
if (in_array(trim($comm), ['NEW', 'MODIF', 'RELIRE'])) {
$liste_trad[$matches[1]]=trim($comm);
$liste_trad[$matches[1]] = trim($comm);
}
}
}
@ -333,7 +333,7 @@ function formulaires_tradlang_importer_langue_traiter_dist($id_tradlang_module,
spip_log("Erreur, fichier $module mal forme", 'tradlang');
}
$langues_base = sql_allfetsel('*', 'spip_tradlangs', 'module = ' . sql_quote($module).' AND lang = ' . sql_quote($lang));
$langues_base = sql_allfetsel('*', 'spip_tradlangs', 'module = ' . sql_quote($module) . ' AND lang = ' . sql_quote($lang));
$modifs = [];
foreach ($langues_base as $strings_id => $strings) {
if (_request($strings['id']) == 'oui') {
@ -345,7 +345,7 @@ function formulaires_tradlang_importer_langue_traiter_dist($id_tradlang_module,
}
}
spip_unlink($dest);
} else if (file_exists($dest = $dir_lang. $fichier_po)) {
} elseif (file_exists($dest = $dir_lang . $fichier_po)) {
lire_fichier($dest, $contenu_po);
preg_match_all(',(\#\, php-format|\#\, fuzzy\, php-format).*msgstr "(.*)\n(\n|\Z),Uims', $contenu_po, $matches);
$array_po = [];
@ -359,7 +359,7 @@ function formulaires_tradlang_importer_langue_traiter_dist($id_tradlang_module,
preg_match(',\nmsgid \"(.*)\nmsgstr,Uims', $match, $matches_str_orig);
$str_orig = rtrim(trim($matches_str_orig[1]), '"');
$str_orig = trim(str_replace("\"\n\"", '', $str_orig));
$matches[1] = sql_getfetsel('id', 'spip_tradlangs', 'id_tradlang_module = ' . (int) $id_tradlang_module.' AND str = ' . sql_quote($str_orig));
$matches[1] = sql_getfetsel('id', 'spip_tradlangs', 'id_tradlang_module = ' . (int) $id_tradlang_module . ' AND str = ' . sql_quote($str_orig));
}
if (preg_match(',\#\, fuzzy\, php-format,', $match, $matches_statut)) {
$statut = 'MODIF';
@ -373,7 +373,7 @@ function formulaires_tradlang_importer_langue_traiter_dist($id_tradlang_module,
$modifs_po = [];
foreach ($langues_base as $strings_id => $strings) {
if (_request($strings['id']) == 'oui') {
$set=$instit=null;
$set = $instit = null;
if (isset($array_po[$strings['id']]['str']) & & strlen(trim($array_po[$strings['id']]['str'])) > 0) {
$set = ['str' => $array_po[$strings['id']]['str']];
tradlang_set($strings['id_tradlang'], $set);