From d29515598d7aa894f0552f4e32c48e2b914a08ee Mon Sep 17 00:00:00 2001 From: ddrwode <34234@3来 34> Date: Tue, 10 Feb 2026 11:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=88=E5=93=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 82 ++++++++++++++++++++++++++++++++ config.py | 2 +- static/css/style.css | 25 ++++++++++ static/js/main-simple.js | 4 +- templates/admin/dashboard.html | 2 +- templates/admin/login.html | 2 +- templates/auth/login.html | 2 +- templates/auth/register.html | 2 +- templates/forum/index.html | 2 +- templates/forum/post_form.html | 2 +- templates/index.html | 86 +++++++++++++++++++--------------- 11 files changed, 165 insertions(+), 46 deletions(-) diff --git a/app.py b/app.py index f41e6e2..2390006 100644 --- a/app.py +++ b/app.py @@ -638,14 +638,96 @@ def _forum_redirect_with_msg(post_id, text_msg): return redirect(url_for("forum_post_detail", post_id=post_id, msg=text_msg)) +# 首页多语言文案(中文 / English) +I18N = { + "zh": { + "tagline": "云服务器价格一目了然", + "filter_provider": "厂商", + "filter_region": "区域", + "filter_memory": "内存 ≥", + "filter_price": "价格区间", + "filter_currency": "货币", + "search_placeholder": "搜索厂商、配置...", + "all": "全部", + "unlimited": "不限", + "btn_reset": "重置筛选", + "th_provider": "厂商", + "th_country": "国家", + "th_config": "配置", + "th_vcpu": "vCPU", + "th_memory": "内存", + "th_storage": "存储", + "th_bandwidth": "带宽", + "th_traffic": "流量", + "th_price": "月付价格", + "th_action": "操作", + "disclaimer": "* 价格仅供参考,以各厂商官网为准。部分为按量/包年折算月价。", + "footer_note": "数据仅供参考 · 请以云厂商官网实时报价为准", + "contact_label": "联系我们", + "empty_state": "未找到匹配的方案", + "load_error": "数据加载失败,请刷新页面重试", + "search_label": "搜索", + "price_under50": "< ¥50", + "price_50_100": "¥50-100", + "price_100_300": "¥100-300", + "price_300_500": "¥300-500", + "price_over500": "> ¥500", + "cny": "人民币 (¥)", + "usd": "美元 ($)", + }, + "en": { + "tagline": "VPS & cloud server prices at a glance", + "filter_provider": "Provider", + "filter_region": "Region", + "filter_memory": "Memory ≥", + "filter_price": "Price range", + "filter_currency": "Currency", + "search_placeholder": "Search provider, config...", + "all": "All", + "unlimited": "Any", + "btn_reset": "Reset", + "th_provider": "Provider", + "th_country": "Country", + "th_config": "Config", + "th_vcpu": "vCPU", + "th_memory": "Memory", + "th_storage": "Storage", + "th_bandwidth": "Bandwidth", + "th_traffic": "Traffic", + "th_price": "Monthly", + "th_action": "Action", + "disclaimer": "* Prices are indicative. See provider sites for current rates.", + "footer_note": "Data for reference only. Check provider sites for latest pricing.", + "contact_label": "Contact", + "empty_state": "No matching plans found", + "load_error": "Failed to load data. Please refresh.", + "search_label": "Search", + "price_under50": "< 50", + "price_50_100": "50-100", + "price_100_300": "100-300", + "price_300_500": "300-500", + "price_over500": "> 500", + "cny": "CNY (¥)", + "usd": "USD ($)", + }, +} + + @app.route("/") def index(): + lang = request.args.get("lang") or session.get("lang", "zh") + if lang not in ("zh", "en"): + lang = "zh" + session["lang"] = lang + t = I18N[lang] plans = VPSPlan.query.order_by(VPSPlan.provider, VPSPlan.price_cny).all() return render_template( "index.html", site_url=SITE_URL, site_name=SITE_NAME, plans_json_ld=[p.to_dict() for p in plans], + lang=lang, + t=t, ) diff --git a/config.py b/config.py index b8f021e..cf9b588 100644 --- a/config.py +++ b/config.py @@ -25,7 +25,7 @@ class Config: SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or _mysql_uri() SQLALCHEMY_TRACK_MODIFICATIONS = False SITE_URL = os.environ.get("SITE_URL") or "https://vps.ddrwode.cn" - SITE_NAME = "云服务器价格对比" + SITE_NAME = "云价眼" # 兼容直接 from config import XXX diff --git a/static/css/style.css b/static/css/style.css index 787850a..bae6c64 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -112,6 +112,31 @@ body { background: var(--accent-glow); } +.lang-switch { + display: inline-flex; + align-items: center; + gap: 0.25rem; + margin-right: 0.5rem; + font-size: 0.9rem; +} +.lang-switch a { + color: var(--accent); + text-decoration: none; + padding: 0.2rem 0.4rem; + border-radius: 4px; +} +.lang-switch a:hover { + background: var(--accent-glow); +} +.lang-switch a.active { + font-weight: 600; + color: var(--text); +} +.lang-sep { + color: var(--text-muted); + user-select: none; +} + .nav-link-with-badge { display: inline-flex; align-items: center; diff --git a/static/js/main-simple.js b/static/js/main-simple.js index 2c22c46..685b269 100644 --- a/static/js/main-simple.js +++ b/static/js/main-simple.js @@ -80,7 +80,7 @@ }) .catch(function(error) { console.error('Error fetching data:', error); - showError('数据加载失败,请刷新页面重试'); + showError((window.I18N_JS && window.I18N_JS.load_error) || '数据加载失败,请刷新页面重试'); }); } @@ -216,7 +216,7 @@ tbody.innerHTML = ''; if (sorted.length === 0) { - tbody.innerHTML = '
云服务器价格对比
+{{ t.tagline }}