Using supplangs; other, minor changes

This commit is contained in:
pezcurrel 2023-11-02 08:09:50 +01:00
parent 41182ecb5b
commit c45e8058c2

View file

@ -16,18 +16,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('N',"\n");
const N="\n";
define('SNAME',basename(__FILE__));
define('LIBDP','/../site/mustard/include');
const LIBDP='/../site/mustard/include';
require(__DIR__.LIBDP.'/parsetime.php');
require(__DIR__.LIBDP.'/gurl.php');
require(__DIR__.LIBDP.'/tables.php');
require(__DIR__.LIBDP.'/mb_ucfirst.php');
require(__DIR__.LIBDP.'/mb_lcfirst.php');
require(__DIR__.LIBDP.'/ghs.php');
require(__DIR__.LIBDP.'/ght.php');
require(__DIR__.'/lib/vendor/autoload.php');
require __DIR__.LIBDP.'/parsetime.php';
require __DIR__.LIBDP.'/gurl.php';
require __DIR__.LIBDP.'/tables.php';
require __DIR__.LIBDP.'/mb_ucfirst.php';
require __DIR__.LIBDP.'/mb_lcfirst.php';
require __DIR__.LIBDP.'/ghs.php';
require __DIR__.LIBDP.'/ght.php';
require __DIR__.'/../site/lib/supplangs.php';
require __DIR__.'/lib/vendor/autoload.php';
use LanguageDetection\Language;
use function mysqli_real_escape_string as myesc;
@ -624,7 +625,7 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages'])
eecho(1,'«'.$opts['hostname'].'»: declared languages: '.implode(', ',$idata['languages']).N);
if (!$opts['dryrun']) {
myq($link,'DELETE FROM InstLangs WHERE InstID='.$instid,__LINE__);
$langids=getlangsidsarr($idata['languages'],$link,$opts['hostname'],$opts['dryrun'],__LINE__);
$langids=getlangsidsarr($idata['languages'],$supplangs,$link,$opts['hostname'],$opts['dryrun'],__LINE__);
$pos=0;
foreach ($langids as $langid) {
$pos++;
@ -652,7 +653,7 @@ if ($instanswered && isset($idata['languages']) && is_array($idata['languages'])
}
if (!$opts['dryrun']) {
myq($link,'DELETE FROM InstOurLangs WHERE InstID='.$instid,__LINE__);
$langids=getlangsidsarr($idata['ourlanguages'],$link,$opts['hostname'],$opts['dryrun'],__LINE__);
$langids=getlangsidsarr($idata['ourlanguages'],$supplangs,$link,$opts['hostname'],$opts['dryrun'],__LINE__);
$pos=0;
foreach ($langids as $langid) {
$pos++;
@ -1197,7 +1198,7 @@ function get_instance_langs($host) {
return $languages;
}
function getlangid(&$link,$lang,$hostname,$dryrun,$line) {
function getlangid(&$link,$lang,&$supplangs,$hostname,$dryrun,$line) {
$code=locale_canonicalize($lang);
if (preg_match('/^\s*$/',$lang)===1 || preg_match('/__/',$code)===1) {
notify('«'.$hostname.'»: «'.$lang.'» is not a valid language code, falling back to default «en».',2,true);
@ -1205,10 +1206,13 @@ function getlangid(&$link,$lang,$hostname,$dryrun,$line) {
}
$res=myq($link,'SELECT * FROM Languages WHERE Code=\''.myesc($link,$code).'\'',$line);
$nrows=mysqli_num_rows($res);
$langs=[];
if ($nrows==0) {
$code=myesc($link,truncs($code,'Languages','Code','«'.$hostname.'»'));
$NameOrig=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,$code)),'Languages','NameOrig','«'.$hostname.'»'));
$NamePt_BR=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'pt_BR')),'Languages','NamePT_BR','«'.$hostname.'»'));
foreach ($supplangs as $key=>$val)
$langs[$key]=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,$key)),'Languages','Name'.strtoupper($key),'«'.$hostname.'»'));
/*$NamePt_BR=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'pt_BR')),'Languages','NamePT_BR','«'.$hostname.'»'));
$NameDe=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'de')),'Languages','NameDE','«'.$hostname.'»'));
$NameUk=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'uk')),'Languages','NameUK','«'.$hostname.'»'));
$NameCa=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'ca')),'Languages','NameCA','«'.$hostname.'»'));
@ -1217,7 +1221,14 @@ function getlangid(&$link,$lang,$hostname,$dryrun,$line) {
$NameFr=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'fr')),'Languages','NameFR','«'.$hostname.'»'));
$NameGl=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'gl')),'Languages','NameGL','«'.$hostname.'»'));
$NameIt=myesc($link,truncs(mb_ucfirst(locale_get_display_name($code,'it')),'Languages','NameIT','«'.$hostname.'»'));
$q='INSERT INTO Languages (ID, Code, NameOrig, NamePT_BR, NameDE, NameUK, NameCA, NameEN, NameES, NameFR, NameGL, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NamePt_BR.'\', \''.$NameDe.'\', \''.$NameUk.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameGl.'\', \''.$NameIt.'\')';
$q='INSERT INTO Languages (ID, Code, NameOrig, NamePT_BR, NameDE, NameUK, NameCA, NameEN, NameES, NameFR, NameGL, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NamePt_BR.'\', \''.$NameDe.'\', \''.$NameUk.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameGl.'\', \''.$NameIt.'\')';*/
$q='INSERT INTO Languages (ID, Code, NameOrig, ';
foreach ($langs as $key=>$val)
$q.='Name'.strtoupper($key).', ';
$q=substr($q,0,-2).') VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', ';
foreach ($langs as $key=>$val)
$q.='\''.$val.'\', ';
$q=substr($q,0,-2).')';
if (!$dryrun) {
myq($link,$q,$line);
$langid=mysqli_insert_id($link);
@ -1232,10 +1243,10 @@ function getlangid(&$link,$lang,$hostname,$dryrun,$line) {
return($langid);
}
function getlangsidsarr(&$langs,&$link,$hostname,$dryrun,$line) {
function getlangsidsarr(&$langs,&$supplangs,&$link,$hostname,$dryrun,$line) {
$langids=[];
foreach ($langs as $lang) {
$langid=getlangid($link,$lang,$hostname,$dryrun,$line);
$langid=getlangid($link,$lang,$supplangs,$hostname,$dryrun,$line);
$langids[]=$langid;
}
$langids=array_unique($langids);