简体   繁体   English

Vue.js 如何在 i18n 语言包中获取当前语言环境

[英]Vue.js how to get current locale in i18n language package

i want to get my current locale , because i need to check if the current locale === 'en' then return true or false, how can i do this?我想获取我当前的语言环境,因为我需要检查当前语言环境 === 'en' 然后返回 true 或 false,我该怎么做? Vue.js/i18n/vee-validate Vue.js/i18n/vee-validate

main.js :主.js:

  import { createApp } from "vue";
  import { createPinia } from "pinia";
  import "./index.css";
  import App from "./App.vue";
  import router from "./router";
  import "@/config/vee-validate/rules";
  import "@/config/vee-validate/messages";

   const app = createApp(App);

   app.use(createPinia());
         app.use(router);

    app.mount("#app");

In option API use :在选项 API 中使用:

this.$i18n.locale

in composition API use the useI18n function to get the locale :在组合 API 中使用useI18n函数来获取语言环境:

const {locale}=useI18n()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue i18n - 如何在 i18n 组件选项中获取当前语言环境? - Vue i18n - How do I get the current locale inside the i18n component options? 如何在本地存储(Vue)中保存当前语言(i18n) - How to save current language (i18n) in localstorage (Vue) 在 vue.js 中,如何在 functions.js 中使用 i18n? - In vue.js, how can I use i18n in functions.js? Vue.js 使用 Vue I18n 的项目出现以下错误:“TypeError: i18n is undefined” - Vue.js project using Vue I18n has got the following error: "TypeError: i18n is undefined" NuxtJS - i18n - 使用当前语言环境初始化插件(vue-fb-customer-chat) - NuxtJS - i18n - Initialize plugin (vue-fb-customer-chat) with the current locale 在 vue.js - vue-i18n 中使用 i18n(区域设置)的值四舍五入为 3 个十进制值 - rounding off to 3 decimal values for the value that uses i18n (regional setting) in vue.js - vue-i18n 如何使用 Vue i18n 翻译 in.js 文件? - How to use Vue i18n translation in .js file? 在 i18n 中为同一语言环境使用两种语言代码 - Using two language codes for same locale in i18n 如何在 Next.js 中重新加载时强制执行 i18n 语言环境 slug 并实现 i18n 一致性? - How to enforce i18n locale slugs and achieve i18n consistency upon reload in Next.js? 在 vue.js 中使用 locale 前缀路由(使用 vue-i18n) - Prefix routes with locale in vue.js (using vue-i18n)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM