mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Locale): add useCurrentLang method (#11517)
This commit is contained in:
parent
769f16169e
commit
816acf7886
@ -79,3 +79,23 @@ Current supported languages:
|
|||||||
### Add new language
|
### Add new language
|
||||||
|
|
||||||
If you can’t find the language you need, please send us a Pull Request to add the new language pack, you can refer to [Add German language pack](https://github.com/vant-ui/vant/pull/7245) PR.
|
If you can’t find the language you need, please send us a Pull Request to add the new language pack, you can refer to [Add German language pack](https://github.com/vant-ui/vant/pull/7245) PR.
|
||||||
|
|
||||||
|
### Get Current Lang
|
||||||
|
|
||||||
|
You can get the current language using `useCurrentLang` method.
|
||||||
|
|
||||||
|
- **Type:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function useCurrentLang(): Ref<string>;
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Example:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { useCurrentLang } from 'vant';
|
||||||
|
|
||||||
|
const currentLang = useCurrentLang();
|
||||||
|
|
||||||
|
console.log(currentLang.value); // --> 'en-US'
|
||||||
|
```
|
||||||
|
@ -77,6 +77,26 @@ Locale.add(messages);
|
|||||||
|
|
||||||
> 在 [这里](https://github.com/vant-ui/vant/tree/main/packages/vant/src/locale/lang) 查看所有的语言包源文件。
|
> 在 [这里](https://github.com/vant-ui/vant/tree/main/packages/vant/src/locale/lang) 查看所有的语言包源文件。
|
||||||
|
|
||||||
|
### 获取当前语言
|
||||||
|
|
||||||
|
你可以通过 `useCurrentLang` 方法来获取当前使用的语言。
|
||||||
|
|
||||||
|
- **类型:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function useCurrentLang(): Ref<string>;
|
||||||
|
```
|
||||||
|
|
||||||
|
- **示例:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { useCurrentLang } from 'vant';
|
||||||
|
|
||||||
|
const currentLang = useCurrentLang();
|
||||||
|
|
||||||
|
console.log(currentLang.value); // --> 'zh-CN'
|
||||||
|
```
|
||||||
|
|
||||||
## 常见问题
|
## 常见问题
|
||||||
|
|
||||||
### 找不到所需的语言包?
|
### 找不到所需的语言包?
|
||||||
|
@ -25,4 +25,6 @@ export const Locale = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useCurrentLang = () => lang;
|
||||||
|
|
||||||
export default Locale;
|
export default Locale;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user