Skip to content

Commit

Permalink
fix: fix initial lang
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen committed Nov 23, 2023
1 parent 18a2341 commit e4d49bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .github/workflows/guide-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,16 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2

- name: Get the date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
shell: bash

- name: Webhook message
uses: joelwmale/webhook-action@master
with:
url: ${{ secrets.WEBHOOK_URL }}
headers: '{"Content-Type": "application/json"}'
body: '{"msgtype":"markdown","markdown":{"content":"# ${{ steps.date.outputs.date }} \n\nLabelU [用户文档站点](${{ steps.deployment.outputs.page_url }})已更新 🎉"}}'

15 changes: 14 additions & 1 deletion src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@ const resources = {
},
};

const validEnLangs = ['en-US', 'en', 'en-GB', 'en-AU', 'en-CA', 'en-NZ'];
const validZhLangs = ['zh-CN', 'zh', 'zh-TW', 'zh-HK'];

let initialLang = localStorage.getItem('i18nextLng') || navigator.language;

if (validEnLangs.includes(initialLang)) {
initialLang = 'en-US';
} else if (validZhLangs.includes(initialLang)) {
initialLang = 'zh-CN';
} else {
initialLang = 'en-US';
}

i18n
.use(LanguageDetector)
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources,
lng: localStorage.getItem('i18nextLng') || navigator.language || 'zh-CN',
lng: initialLang,
interpolation: {
escapeValue: false, // react already safes from xss
},
Expand Down

0 comments on commit e4d49bf

Please sign in to comment.