'English','it'=>'Italiano','nl'=>'Nederlands','cs'=>'Čeština','es'=>'Español','tr'=>'Türkçe','de'=>'Deutsch','fr'=>'Français'];
$raw=parse_url($_SERVER['REQUEST_URI']??'/',PHP_URL_PATH) ?: '/'; $parts=explode('/',trim($raw,'/')); $locale='en'; if(isset($parts[0])&&in_array($parts[0],$locales,true)){$locale=array_shift($parts);} $path=implode('/',$parts); $base=$locale==='en'?'':'/'.$locale;
$config=json_decode((string)file_get_contents(__DIR__."/data/$locale/config.json"),true)?:[]; $payload=json_decode((string)file_get_contents(__DIR__."/data/$locale/posts.json"),true)?:[]; $posts=$payload['data']??[]; $site=$config['site']??['name'=>'Genify Next','description'=>'AI news and practical guides.']; $cats=$config['categories']??[]; $catMap=[]; foreach($cats as $c)$catMap[$c['slug']]=$c; $tr=$config['translations']??[]; $ui=$tr['ui']??[]; $home=$tr['homepage']??[];
function e($v):string{return htmlspecialchars((string)$v,ENT_QUOTES|ENT_SUBSTITUTE,'UTF-8');} function href(string $p):string{global $base; return $base.'/'.ltrim($p,'/');} function val($a,$k,$d=''){return $a[$k]??$d;} function post_by_slug(array $ps,string $s):?array{foreach($ps as $p)if(($p['slug']??'')===$s)return $p;return null;} function img(array $p):string{$u=$p['featured_image_url']??$p['featured_image']??'';return is_string($u)&&str_starts_with($u,'/img/')?$u:'';}
function blocks(array $bs):string{$h='';foreach($bs as $b){if(!is_array($b))continue;$t=$b['type']??'paragraph';$c=$b['content']??'';if($t==='image'){$u=$b['image_url']??$b['src']??'';if(is_string($u)&&str_starts_with($u,'/img/'))$h.='
'.nl2br(e(trim($p))).'
';}}return $h;} function header_html(string $title):string{global $site,$cats,$names,$locales,$locale,$ui; $homeLabel=val($ui['nav']??[],'home','Home');$nav=''.e($homeLabel).'';foreach($cats as $c)$nav.=''.e($c['name']).'';$langs='';foreach($locales as $l)$langs.=''.e($names[$l]).''; $langs.='';return 'GENIFY NEXT
'.e(val($home['hero']??[],'subtitle',$site['description']??'' )).'
CATEGORY
'.e($cat['description']??'').'
'.e($site['description']??'').'
'.e($p['category']??'AI').'
'.e($p['excerpt']??'').'
';if($u=img($p))$body.='