赞
踩
npm install vue-i18n
en.ts
zh.ts
index.ts
- import zh from "./zh";
- import en from "./en";
-
- export default {
- zh,
- en,
- };
- import { createI18n } from "vue-i18n";
- import { getLocale } from "@/utils/init"; // 这个方案是获取当前浏览器的语言环境,代码见下面
- import messages from "@/locales";
-
- const i18n = createI18n({
- legacy: false,
- locale: getLocale(),
- fallbackLocale: "zh",
- messages,
- });
-
- export default i18n;
- export function getLocale() {
- const language = navigator.language;
- if (language.includes("zh")) {
- return "zh";
- }
- return "en";
- }
- import { createApp } from "vue";
- import { createPinia } from "pinia";
- import vant from "vant";
- import "vant/lib/index.css";
- import svgIcon from "@/icons/index.vue";
- import "@/assets/styles/main.scss";
- import { initAPlus } from "@/utils/aplus";
- import "@/assets/iconpark.js";
- import App from "./App.vue";
- import router from "./router";
- import i18n from "./i18n";
-
- if (import.meta.env.MODE !== "production") {
- import("vconsole").then(({ default: VConsole }) => {
- new VConsole();
- });
- }
-
- function main() {
- const pinia = createPinia();
- const app = createApp(App);
- app.component("svg-icon", svgIcon);
- app.use(vant).use(router).use(i18n).use(pinia).mount("#app");
-
- initAPlus();
- }
-
- main();
- <script setup lang="ts">
- import { useI18n } from "vue-i18n";
- const { t, locale } = useI18n();
- const zlLengedTxtOne = ref([t("overview.vehicleAudit"), t("overview.target")]);
- </script>
- // 在template中使用
- <template>
- <div class="lt-title samll-grey-text">
- {{ $t("overview.overallDelivery") }}
- </div>
- </template>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。