有没有办法通过检测父文件夹名称来知道当前的语言?
src
└── pages
├── fr <-- THIS IS THE PARENT FOLDER
| └── index.astro
└── index.astro
我尝试过的事情:
我也想从子组件访问语言
最简单的方法可能是查看页面或组件中的
Astro.url
:
---
// The pathname of the current page, e.g. '/fr/'.
const { pathname } = Astro.url;
// The language (parent folder name) will be the second
// item if we split the path at every forward slash.
const lang = pathname.split('/')[1];
---
<p>Language is {lang}.</p>