Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

EdgeChat 从 `2.1.2` 起正式采用语义化版本。更早的版本号依据已经完成的主要里程碑补记,用于说明项目演进,不对应历史 Git 标签。

## 2.7.3 - 2026-09-19

- 网页首次访问继续只依据浏览器首选语言,不使用 IP 或地理定位:`Hant`/旧式 `CHT` 使用繁体,`Hans`/旧式 `CHS` 使用简体;未声明脚本时,台湾、香港、澳门使用繁体,其余中文地区与裸 `zh` 使用简体,非中文继续使用英文。
- 明确脚本优先于地区,例如香港用户选择 `zh-Hans-HK` 时使用简体、中国大陆用户选择 `zh-Hant-CN` 时使用繁体;用户在语言菜单中的手动选择仍持久化并优先于自动识别。
- 使用当前 demo 重新截取 README 的聊天界面与管理后台预览图,Telegram 桥接演示图保持不变。
- 本次调整网页语言检测、测试与 README 预览图,不改动 Android、GitHub Actions、数据库结构或云资源。

## 2.7.2 - 2026-09-16

- 修复 D1 UTC 时间缺少时区标记时被浏览器误当成本地时间的问题,网页消息时间及其他服务端日期现在会按客户端浏览器时区正确显示。
- 本次仅调整网页共享日期解析与测试,不改动 Android、GitHub Actions、数据库结构或云资源。

## 2.7.1 - 2026-09-15

- 修复 Capacitor Android CI 初始化阶段请求已下架 Android SDK `tools` 包的问题,显式仅安装仍可用的 `platform-tools` 后再安装既有 SDK 36;不改动 Android 源码或功能。
Expand Down
Binary file modified assets/previews/admin-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/previews/chat-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 24 additions & 4 deletions frontend/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const LOCALE_OPTIONS = Object.freeze([
]);

const STORAGE_KEY = 'edgechat.locale';
const TRADITIONAL_CHINESE_REGIONS = new Set(['tw', 'hk', 'mo']);
const localeLoaders = {
[SIMPLIFIED_CHINESE_LOCALE]: () => import('./locales/zh-CN.js'),
[TRADITIONAL_CHINESE_LOCALE]: () => import('./locales/zh-TW.js'),
Expand All @@ -25,7 +26,14 @@ function normalizeLocale(value) {
export function detectBrowserLocale(value) {
const language = String(value || '').replaceAll('_', '-');
if (!/^zh(?:-|$)/i.test(language)) return ENGLISH_LOCALE;
return /(?:^|-)Hant(?:-|$)|(?:^|-)(?:TW|HK|MO)(?:-|$)/i.test(language)
const subtags = language.toLowerCase().split('-').slice(1);

// 脚本标签代表用户明确选择的字形,优先级高于设备地区;CHT/CHS 兼容旧版浏览器标签。
if (subtags.includes('hant') || subtags.includes('cht')) return TRADITIONAL_CHINESE_LOCALE;
if (subtags.includes('hans') || subtags.includes('chs')) return SIMPLIFIED_CHINESE_LOCALE;

// 未声明脚本时,台湾、香港、澳门使用繁体,其余中文地区与裸 zh 默认简体。
return subtags.some((subtag) => TRADITIONAL_CHINESE_REGIONS.has(subtag))
? TRADITIONAL_CHINESE_LOCALE
: SIMPLIFIED_CHINESE_LOCALE;
}
Expand Down Expand Up @@ -84,18 +92,30 @@ export function initializeI18n() {
return setLocale(locale.value, { persist: false });
}

const SQLITE_UTC_DATE_TIME_PATTERN = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?$/;

export function parseDateValue(value) {
if (value instanceof Date) return value;
// D1 的 CURRENT_TIMESTAMP 是 UTC,但返回值没有时区标记;补成 ISO UTC 后才能按浏览器时区正确展示。
const normalizedValue =
typeof value === 'string' && SQLITE_UTC_DATE_TIME_PATTERN.test(value)
? `${value.replace(' ', 'T')}Z`
: value;
return new Date(normalizedValue);
}

export function formatDateTime(value, options = { dateStyle: 'medium', timeStyle: 'short' }) {
const date = value instanceof Date ? value : new Date(value);
const date = parseDateValue(value);
return Number.isNaN(date.getTime()) ? '' : new Intl.DateTimeFormat(locale.value, options).format(date);
}

export function formatDate(value, options = { dateStyle: 'medium' }) {
const date = value instanceof Date ? value : new Date(value);
const date = parseDateValue(value);
return Number.isNaN(date.getTime()) ? '' : new Intl.DateTimeFormat(locale.value, options).format(date);
}

export function formatTime(value, options = { hour: '2-digit', minute: '2-digit' }) {
const date = value instanceof Date ? value : new Date(value);
const date = parseDateValue(value);
return Number.isNaN(date.getTime()) ? '' : new Intl.DateTimeFormat(locale.value, options).format(date);
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edgechat",
"version": "2.7.1",
"version": "2.7.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
27 changes: 24 additions & 3 deletions test/i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
detectBrowserLocale,
ENGLISH_LOCALE,
formatDate,
formatDateTime,
getLocale,
parseDateValue,
setLocale,
t,
TRADITIONAL_CHINESE_LOCALE
Expand Down Expand Up @@ -38,11 +40,19 @@ test('简繁中文界面支持插值与未知键回退', async () => {
assert.equal(t('missing.translation.key'), 'missing.translation.key');
});

test('浏览器语言会区分简繁中文,其余语言默认英文', () => {
for (const language of ['zh', 'zh-CN', 'zh-Hans-SG', 'zh-MY']) {
test('浏览器中文语言按脚本和地区区分简繁,其余语言默认英文', () => {
for (const language of ['zh', 'zh-CN', 'zh-SG', 'zh-MY', 'zh-Hans', 'zh-Hans-HK', 'zh-CHS']) {
assert.equal(detectBrowserLocale(language), CHINESE_LOCALE);
}
for (const language of ['zh-TW', 'zh-Hant-HK', 'zh-MO', 'ZH_hant_tw']) {
for (const language of [
'zh-TW',
'zh-HK',
'zh-MO',
'zh-Hant',
'zh-Hant-CN',
'zh-CHT',
'ZH_hant_tw'
]) {
assert.equal(detectBrowserLocale(language), TRADITIONAL_CHINESE_LOCALE);
}

Expand Down Expand Up @@ -86,6 +96,17 @@ test('日期格式跟随当前语言', async () => {
await setLocale(CHINESE_LOCALE);
});

test('D1 时间按 UTC 解析并转换为客户端时区', async () => {
const d1Value = '2026-09-16 12:34:56';
const isoValue = '2026-09-16T12:34:56.000Z';
const options = { dateStyle: 'medium', timeStyle: 'short', timeZone: 'Asia/Shanghai' };

assert.equal(parseDateValue(d1Value).toISOString(), isoValue);
assert.equal(parseDateValue(isoValue).toISOString(), isoValue);
assert.equal(formatDateTime(d1Value, options), formatDateTime(isoValue, options));
assert.equal(formatDateTime('not-a-date', options), '');
});

test('服务端固定与动态错误会按当前语言本地化', async () => {
await setLocale(ENGLISH_LOCALE);
assert.equal(localizeErrorMessage('账号或密码错误'), 'Incorrect username or password');
Expand Down
Loading