当前位置: 首页 > news >正文

关于“i18n“在vue中的使用

关于"i18n"在vue中的使用

<!-- vue2中 -->
<template><div>{{ $t("This campaign has expired.") }}}}</div>
</template>
<script>
export default {created() {this.onLoading();},methods: {onLoading () {this.$t("loading")},}
}
</script>
<!-- vue3中 -->
<template><div>{{ $t("This campaign has expired.") }}}}</div>
</template>
<script setup>
import { onMounted } from "vue";
import { useI18n } from "vue-i18n";const { t } = useI18n();
onMounted(() => {onLoading();
});
onLoading = () => {t("loading")
};
const 
</script>
/* 忽略不看
./lang文件夹下有en.json, mm.json({  ”Ok“: "Ok" })
// env.uat 文件下定义
VUE_APP_I18N_LOCALE=mm
VUE_APP_I18N_FALLBACK_LOCALE=mm
*/
import { createI18n } from "vue-i18n";function languageFunc () {const locales = require.context('./lang', true, /[A-Za-z0-9-_,\s]+\.json$/i);const messages = {};locales.keys().forEach(key => {const matched = key.match(/([A-Za-z0-9-_]+)\./i);if (matched && matched.length > 1) {const locale = matched[1]messages[locale] = locales(key)}})return messages
}export default createI18n({locale: process.env.VUE_APP_I18N_LOCALE || 'en',fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',messages:  languageFunc(),legacy: false
})
http://www.lryc.cn/news/535829.html

相关文章:

  • 前缀树算法篇:前缀信息的巧妙获取
  • DVSI使用SenseGlove为开发虚拟现实场景技能培训
  • VSCode + Continue 实现AI编程助理
  • 【PHP的static】
  • 考研操作系统----操作系统的概念定义功能和目标(仅仅作为王道哔站课程讲义作用)
  • 从360度全景照片到高质量3D场景:介绍SC-Omnigs 3D重建系统
  • 前沿技术新趋势:值得关注的创新发展
  • 算法跟练第十一弹——二叉树
  • 机器学习(李宏毅)——BERT
  • 新数据结构(7)——Object
  • 云计算基础
  • 利用kali linux 进行自动化渗透测试
  • 【Vue中BUG解决】npm error path git
  • GPT-4o微调SFT及强化学习DPO数据集构建
  • element-plus 解决el-dialog背后的页面滚动问题,及其内容有下拉框出现错位问题
  • MT6835 21位 磁编码器 SPI 平台无关通用驱动框架 STM32
  • vue REF 和 Reactive区别、特点、优势
  • Elastic Cloud Serverless 现已在 Microsoft Azure 上提供技术预览版
  • Spring Boot + MyBatis Field ‘xxx‘ doesn‘t have a default value 问题排查与解决
  • kafka的架构和工作原理
  • 游戏引擎学习第100天
  • 机器学习:朴素贝叶斯分类器
  • 打开Visual Studio Code的时候发现未检测到适用于linux的windows子系统,那么该问题要如何解决?
  • 力扣24题——两两交换链表中节点
  • android launcher拖动图标释放错位
  • window ssh免密码输入
  • 2024年博客之星年度评选—主题文章创作评审文章得分公布
  • vscode插件Remote - SSH使用教程
  • 自学人工智能大模型,满足7B模型的训练和微调以及推理,预算3万,如何选购电脑
  • github不翻墙就可以访问