APP-PUSH和纯色小组件

This commit is contained in:
吕新雨
2026-02-05 01:14:13 +08:00
parent c1c2c6197d
commit 4c03fce720
28 changed files with 258 additions and 156 deletions

View File

@@ -20,10 +20,15 @@ describe('legalApi.buildAcceptLanguage', () => {
expect(buildAcceptLanguage()).toBe('en');
});
it('任意 zh* 归一为 tc', () => {
it('简中/其他中文不支持时回退为 en', () => {
setLang('zh-CN');
expect(buildAcceptLanguage()).toBe('tc');
expect(buildAcceptLanguage()).toBe('en');
setLang('zh');
expect(buildAcceptLanguage()).toBe('en');
});
it('繁体中文归一为 tc', () => {
setLang('zh-TW');
expect(buildAcceptLanguage()).toBe('tc');
});

View File

@@ -1,6 +1,7 @@
import i18n from 'i18next';
import { httpJson } from '../utils/http';
import { toBackendLocaleFromLanguageTag } from '../i18n/locale';
export type LegalLinks = {
privacyPolicyUrl: string;
@@ -9,17 +10,8 @@ export type LegalLinks = {
};
export function buildAcceptLanguage(): 'en' | 'tc' {
const lang = (i18n.language || '').trim();
const lower = lang.toLowerCase();
// 当前多语言仅支持 EN / TC与 reco 链路一致);其他语言统一回退到 en
if (lower.startsWith('zh')) {
return 'tc';
}
if (lower.includes('tc') || lower.includes('hant') || lower.includes('hk') || lower.includes('mo') || lower.includes('tw')) {
return 'tc';
}
return 'en';
// 当前多语言仅支持 EN / TC其他语言统一回退到 en
return toBackendLocaleFromLanguageTag(i18n.language);
}
export async function fetchLegalLinks(): Promise<LegalLinks> {

View File

@@ -7,6 +7,7 @@ import { httpJson } from '../utils/http';
import { APP_ENV } from '../constants/env';
import { getDailyReminderSettings, getOrCreateClientUserId, getUserProfileScoring } from '../storage/appStorage';
import type { UserProfileScoring } from '../storage/appStorage';
import { toBackendLocaleFromLanguageTag } from '../i18n/locale';
export type PushEnv = 'dev' | 'prod';
@@ -44,11 +45,7 @@ export type PushPreferencesResponse = PushPreferencesRequest & {
};
export function buildAcceptLanguage(): 'en' | 'tc' {
const lang = (i18n.language || '').trim();
const lower = lang.toLowerCase();
if (lower.startsWith('zh')) return 'tc';
if (lower.includes('tc') || lower.includes('hant') || lower.includes('hk') || lower.includes('mo') || lower.includes('tw')) return 'tc';
return 'en';
return toBackendLocaleFromLanguageTag(i18n.language);
}
function toPushEnv(appEnv: typeof APP_ENV): PushEnv {

View File

@@ -1,6 +1,7 @@
import i18n from 'i18next';
import type { UserProfileV1_2 } from '../features/userProfileScoring';
import { toBackendLocaleFromLanguageTag } from '../i18n/locale';
import { httpJson } from '../utils/http';
export type RecommendedItem = {
@@ -27,7 +28,7 @@ export type RecoRequest = {
};
export async function fetchRecoFeed(req: RecoRequest): Promise<RecoEngineResult> {
const acceptLanguage = i18n.language?.toLowerCase().startsWith('zh') ? 'tc' : 'en';
const acceptLanguage = toBackendLocaleFromLanguageTag(i18n.language);
const headers: Record<string, string> = {
// 让后端做 locale 选择(目前后端只区分 en/tc
@@ -52,7 +53,7 @@ export async function fetchRecoFeed(req: RecoRequest): Promise<RecoEngineResult>
}
export async function fetchRecoWidget(req: RecoRequest): Promise<RecoEngineResult> {
const acceptLanguage = i18n.language?.toLowerCase().startsWith('zh') ? 'tc' : 'en';
const acceptLanguage = toBackendLocaleFromLanguageTag(i18n.language);
const headers: Record<string, string> = {
// 让后端做 locale 选择(目前后端只区分 en/tc