File size: 1,081 Bytes
1187856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export type Language = "en" | "zh";

export interface LocalizedText {
  en: string;
  zh: string;
}

export const EMPTY_CONTENT_MARKER = "#empty#";

export function isEmptyContentMarker(value: string | null | undefined): boolean {
  if (typeof value !== "string") return false;
  const normalized = value.trim().toLowerCase();
  return normalized === EMPTY_CONTENT_MARKER || /^#empty#[。..!!??,,;;::、…]*$/i.test(normalized);
}

export function contentValue(value: string | null | undefined): string {
  if (!value || isEmptyContentMarker(value) || !value.trim()) return "";
  return value;
}

export function hasLocalizedText(text: LocalizedText | null | undefined): boolean {
  return Boolean(contentValue(text?.en) || contentValue(text?.zh));
}

export function localized(en: string | null | undefined, zh?: string | null): LocalizedText {
  const english = contentValue(en);
  const chineseIsEmptyMarker = isEmptyContentMarker(zh);
  const chinese = contentValue(zh);
  return {
    en: english,
    zh: chinese || (chineseIsEmptyMarker ? "" : english),
  };
}