Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Translation class in base and add support lang param #134

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

wqcstrong
Copy link
Member

@wqcstrong wqcstrong commented Mar 4, 2025

Changes

之前,PageSpy 显示的语言是通过 navigator.languages 判断的,大致逻辑如下:

const isCN = () => {
  const langs = navigator.languages;
  return ['zh-CN', 'zh-HK', 'zh-TW', 'zh', 'zh-Hans-CN'].some((l) => {
    return langs.includes(l);
  });
}

if (isCN()) {
  // 显示中文
} else {
  // 显示英文
}

现在 PageSpy 支持直接或间接的方式配置显示的语言,下面配置按优先级顺序排列:

  1. 实例化的时候手动指定:
    // PageSpy
    new PageSpy({
      lang: 'zh' | 'en'
    });
    
    // O-Spy
    new OSpy({
      lang: 'zh' | 'en'
    }) 
  2. html 标签上配置:
    <html lang="en">...</html>
  3. navigator.language 读取用户浏览器首选语言,如果是下列之一,则显示中文、否则显示英文:
    ['zh-CN', 'zh-HK', 'zh-TW', 'zh', 'zh-Hans-CN']

@wqcstrong wqcstrong merged commit b7d61a4 into main Mar 4, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant