setTemplateDir(dirname(__DIR__) . '/resources/views/venix'); $smarty->setCompileDir($directory); $smarty->setCacheDir($directory); foreach (['urlencode', 'number_format', 'date'] as $modifier) { $smarty->registerPlugin('modifier', $modifier, $modifier); } $smarty->assign([ 'appName' => 'Locale Test Cloud', 'config' => [ 'appName' => 'Locale Test Cloud', 'jump_delay' => 500, ], 'cdn' => '', 'backup_cdn' => '', 'seo' => '', 'user' => new PublicPageGuestForLocaleTest(), 'captch_login' => 'false', 'captch_reg' => 'false', 'captch_respass' => 'false', 'enable_invite_code' => 'false', 'enable_email_verify' => 'false', 'invite_required' => false, 'tos_reg' => 'true', 'code' => '', 'aff_code' => '', 'aff' => 0, 'aff_method' => '', 'token' => str_repeat('a', 64), ]); $pages = [ 'index.tpl' => ['public.home', '你的云资源'], 'auth/login.tpl' => ['auth.login', '登录账户'], 'auth/register.tpl' => ['auth.register', '注册新账户'], 'password/reset.tpl' => ['auth.password', '重置密码请求'], 'password/token.tpl' => ['auth.password', '输入并确认你的新密码。'], ]; $errorPages = [ '404.tpl' => '页面不存在', '405.tpl' => '请求方式不被允许', '500.tpl' => '服务暂时不可用', ]; try { foreach ([PublicLocale::ENGLISH, PublicLocale::CHINESE] as $locale) { $smarty->assign(PublicLocale::viewData($locale, '/auth/register?aff=ABCDEFGH')); foreach ($pages as $template => $copy) { (new UserCopyViewRuntime(new UserCopyRuntimeReader( $directory . '/missing-runtime', new UserCopySourceCatalog(UserCopyManifest::load()) )))->bind( $smarty, $locale, '/auth/register?aff=ABCDEFGH', $copy[0] ); $html = $smarty->fetch($template); $assert(str_contains($html, ''), $template . ' rendered the wrong HTML language for ' . $locale . '.'); $assert(str_contains($html, $copy[1]), $template . ' did not use the Chinese baseline for an unpublished locale.'); $assert(substr_count($html, 'class="landing-site-header"') === 1, $template . ' did not render exactly one shared site header.'); $assert(substr_count($html, 'class="landing-site-footer"') === 1, $template . ' did not render exactly one shared site footer.'); $assert(str_contains($html, 'lang="zh-CN" hreflang="zh-CN"') && str_contains($html, 'lang="en" hreflang="en"'), $template . ' is missing one of the language switch links.'); $assert(str_contains($html, 'aff=ABCDEFGH&lang=en') && str_contains($html, 'aff=ABCDEFGH&lang=zh-CN'), $template . ' did not preserve query parameters in language switch links.'); $assert(str_contains($html, '© 2026 Locale Test Cloud. 保留所有权利。'), $template . ' is missing the persistent dynamic copyright footer.'); $assert(!str_contains($html, 'auth-site-nav') && !str_contains($html, 'auth-copyright'), $template . ' rendered a retired authentication-only header or footer.'); } foreach ($errorPages as $template => $expected) { (new UserCopyViewRuntime(new UserCopyRuntimeReader( $directory . '/missing-runtime', new UserCopySourceCatalog(UserCopyManifest::load()) )))->bind($smarty, $locale, '/missing', 'public.error'); $html = $smarty->fetch($template); $assert(str_contains($html, '') && str_contains($html, $expected), $template . ' did not bind the public error catalog.'); } } } finally { $generatedFiles = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($generatedFiles as $generated) { if ($generated->isFile()) { unlink($generated->getPathname()); } elseif ($generated->isDir()) { rmdir($generated->getPathname()); } } rmdir($directory); } echo "Public pages bind browser locales and safely fall back to Chinese source copy.\n";