Skip to content

Commit

Permalink
[fix]提供当前语言环境的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
wb-lyb830048 committed Jan 5, 2024
1 parent be7913c commit 6e487db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/home/HomeIntroduce.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { useTranslations } from '@i18n/util';
import { useTranslations, isChinese } from '@i18n/util';
import Github from '../icon/Github.astro';
import Star from '../icon/Star.astro';
import Fork from '../icon/Fork.astro';
Expand All @@ -8,6 +8,7 @@ import LinkButton from '../common/LinkButton.astro';
import HomeBackground from '../home/HomeBackground.astro';
const t = useTranslations(Astro);
const ifzh = isChinese(Astro);
const data = await fetch('https://api.github.com/repos/alibaba/nacos').then(
(r) => r.json(),
Expand All @@ -20,7 +21,7 @@ const { stargazers_count: startCount = 0, forks_count: forkCount = 0 } =
<div class="top-section flex flex-col relative">
<HomeBackground />
<div class="py-6 text-gray-08 text-xs">{t('home.introduce.about')}</div>
<div class="title text-[5rem] leading-[6rem] text-gray-03 mb-4">
<div class=`title leading-[6rem] text-gray-03 mb-4 ${ifzh ? 'text-[4rem]' : 'text-[5rem]'}`>
{t('home.introduce.title')}
</div>
<div class="shortcut flex pt-6">
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ export function normalizeLangTag(tag: string) {
if (!tag.includes('-')) return tag.toLowerCase();
const [lang, region] = tag.split('-');
return lang.toLowerCase() + '-' + region.toUpperCase();
}


export function isChinese(Astro: Readonly<AstroGlobal>): boolean {
const lang = getLanguageFromURL(Astro.url.pathname) || 'zh-cn';
return lang === 'zh-cn';
}

0 comments on commit 6e487db

Please sign in to comment.