nuxt使用i18n进行中英文切换
中文效果图:

英文效果图:

版本:

安装:
npm install --save @nuxtjs/i18n
新建en.js与zh.js两个文件进行切换显示

en.js内容
import globals from './../js/global_val'export default {/******* 公共内容开始* *****/seeMore: "More Information", //查看更多seeAgenda: "View the conference schedule", //查看议程jtlRegister: 'Register for the Golden Gyro Award', //金陀螺奖报名参评/投票registrationChannel: 'FBEC Registration channel', //大会参会报名通道fbecland: 'FBEC LAND', //大会官方微站application: 'Click to register for the selection', //点击报名参评-pcapplicationOver: 'The entry channel is closed', //参评已结束-pcmApplication: 'Click Register to vote', //点击报名参评/投票-手机端mAplicationOver: 'Registration is closed', //点击报名参评/投票-手机端headerData: [{name: "Main page",url: "/"},{name: "Main-venue ",url: "main-venue"},{name: "Sub-venue",url: "branch-venue"},{name: "Golden Gyro Award",url: "golden-top-award"},{name: "Conference Exhibition Zone",url: "conference-exhibition-area"},{name: "More Exciting Content",url: "more-exciting-content"},{name: "Conference dynamics",url: "conference-dynamics"},{name: "Review of previous Conference",url: ""},],/******* 公共内容结束* *****//******* 首页开始* *****/asideNav: [{label: "Conference Main Keyvisual",id: "zhuk",},{label: "FBEC2023",id: "2022",},{label: "Conference Agenda",id: "yicheng",},{label: "Conference Guests",id: "jiabin",},// {// label: "大会展商",// id: "zhanshang",// },{label: "Great Video",id: "shipin",},{label: "Conference Distribution Map",id: "fenbutu",},{label: "Organization",id: "zhuzhi",},{label: "Conference Media",id: "meiti",},{label: "Conference Coverage",id: "baodao",},{label: "Conference Photo",id: "huigu",},], //首页时间轴part1: {time: 'Sheraton Shenzhen Futian Hotel · 8th Dec 2023',des1: 'In2023, we have experienced the booming development of artificial intelligence in the early stage, and the rapid evolution of AI technology has not only multiplied the innovation of business models, but also given rise to market changes. When the market bubble recedes and the new wave of the AI era surges, we stick to our original intention, explore the future development pattern of science and technology and the Internet, and plan for the future value of new technology, new business, and new models. We insist that the only way to make progress is to maintain indomitable resilience and vitality. It is only when we work together that we can go farther.',des2: 'The Future Business Ecology Link Conference 2023 and the 8th Golden Gyro Award Ceremony (“FBEC2023”) is organized by Gyro Technology, with the theme of “Collaboration Brings Mutual Benefits·Perseverance Leads to Success”, taking the perspective of “navigators” with industry foresight and the main line of “ice-breaking” journey, focusing on the frontier fields of Internet such as AI、metaverse、 XR、games、e-sports and digital economy, presenting the frontier achievements of science and technology, discussing the times and business issues, planning the future value of new technology, new business and new models, and going on an ice-breaking journey with the real courageous people in the winter under the drastic changes and innovations!'}, //首页大会简介}
zh.js内容:
// 首页
// const globals = require('./js/global_val.js')
import globals from './../js/global_val'export default {/******* 公共内容开始* *****/seeMore: "查看更多", //查看更多seeAgenda: "查看议程", //查看议程jtlRegister: '金陀螺奖报名参评/投票', //金陀螺奖报名参评/投票registrationChannel: '大会参会报名通道', //大会参会报名通道fbecland: '大会互动微站 FBEC LAND', //大会官方微站application: '点击报名参评', //点击报名参评-pcapplicationOver: '参评已结束', //参评已结束-pcmApplication: '点击报名参评/投票', //点击报名参评/投票-手机端mAplicationOver: '点击报名参评/投票', //点击报名参评/投票-手机端headerData: [{name: "首页",url: "/"},{name: "主会场",url: "main-venue"},{name: "分会场",url: "branch-venue"},{name: "金陀螺奖",url: "golden-top-award"},{name: "大会展区",url: "conference-exhibition-area"},{name: "更多精彩",url: "more-exciting-content"},{name: "大会动态",url: "conference-dynamics"},{name: "往届回顾",url: ""},],/******* 公共内容结束* *****//******* 首页开始* *****/asideNav: [{label: "大会主K",id: "zhuk",},{label: "FBEC2023",id: "2022",},{label: "大会议程",id: "yicheng",},{label: "大会嘉宾",id: "jiabin",},// {// label: "大会展商",// id: "zhanshang",// },{label: "精彩视频",id: "shipin",},{label: "会场分布图",id: "fenbutu",},{label: "组织机构",id: "zhuzhi",},{label: "合作媒体",id: "meiti",},{label: "大会报道",id: "baodao",},{label: "精彩现场",id: "huigu",},], //首页时间轴part1: {time: '深圳·大中华喜来登酒店 2023/12/08',des1: '2023年,我们亲历了人工智能的蓬勃发展,AI技术的飞速演进,不仅加乘了商业模式的创新,也催生了市场变化。当市场泡沫退去,AI时代的新浪潮涌动,我们坚守初心,对未来互联网发展形态进行探索,对新科技、新商业、新模式未来价值进行谋划,我们坚信唯有保持百折不挠的韧性与生命力,不断进化自身以适应市场环境变化,共荣共生,方能韧行致远。',des2: '2023未来商业生态链接大会暨第八届金陀螺奖颁奖典礼(简称“FBEC2023”)由陀螺科技主办,以“合力共生 · 韧者行远”为大会主题,以具有行业前瞻洞察的“航行者”为视角,破冰之旅为主线,关注AI、元宇宙、XR、游戏、电竞、数字经济等科技与互联网前沿领域,全方位呈现科技前沿成果,聚焦时代与商业热点议题,探讨新科技、新商业、新模式的未来价值,与真正的勇者共赴剧变革新下的凛冬破冰之旅!'}, //首页大会简介}
在plugins下新建i18n.js

i18n.js内容:
import zh_cn from '../assets/lang/zh.js'
import en_us from '../assets/lang/en.js'
const i18n = {locales: ['en', 'zh'], //有多少地区的语言就添加多少种defaultLocale: 'zh', //默认的地区语言vueI18n: {fallbackLocale: 'en', //回退策略,指定的locale中没有找到对应资源的情况下使用的localemessages: { //要渲染的信息,有多少语言就添加多少种en:en_us,zh:zh_cn}}}export default i18n
在nuxt.config.js引入i18n.js
import i18n from './plugins/i18n'
export default {modules: ['@nuxtjs/axios',['@nuxtjs/i18n',i18n]],
}
切换按钮(两种切换方式选择一种即可)
<!--方式一 --><div class="change-languag-box"><nuxt-linkclass="change-language cn-icon"v-if="$i18n.locale !== 'en'":to="switchLocalePath('en')">中文</nuxt-link><nuxt-linkclass="change-language en-icon"v-if="$i18n.locale !== 'zh'":to="switchLocalePath('zh')">英文</nuxt-link></div>
<!--方式二 -->
<!--html --><div class="change-languag-box"><divclass="change-language cn-icon"v-if="$i18n.locale !== 'en'"@click="changeLocale('en')"></div><divclass="change-language en-icon"v-if="$i18n.locale !== 'zh'"@click="changeLocale('zh')"></div></div>
<!--js -->changeLocale(locale) {// 在页面中添加 changeLocale 方法,调用 $i18n.setLocale 方法来切换语言this.$i18n.setLocale(locale);},
页面展示
<template><!-- <client-only></client-only>加这个刷新页面才不会显示异常 --><client-only><!--内容 --><div class="des"><divclass="time":class="$i18n.locale == 'en' ? 'time-en' : ''"v-html="$t('part1.time')"></div><div class="detail" v-html="$t('part1.des1')"></div><div class="hr default-bg"></div><div class="detail">{{$t('part1.des2')}}</div></div></client-only>
</template>
有导航的需要在导航切换的时候处理一下相关内容:
<!-- html(headerData为导航内容) -->
<div class="com-header-cont flex-center-start"><divclass="com-header-item"v-for="(tabItem, tabIdx) in $t('headerData')":key="tabIdx"@click="changeHeader(tabIdx, tabItem.url)":class="[tabIdx == headerIdx ? 'headerActive' : '',$i18n.locale == 'en' ? 'com-header-item-en' : '',]"><span :class="{ dropdownBtn: tabIdx == 7 }" @click="dropdown">{{tabItem.name}}</span><ulv-if="tabIdx == 7"class="dropdown-wrapper"v-show="dropdownActive"><liclass="dropdown-wrapper-li"v-for="(item, index) in dropParams":key="index"@click="closeDropdown"><a target="_blank" :href="item.path">{{ item.name }}</a></li></ul></div></div><!-- js --> // 导航切换changeHeader(index, path) {this.headerIdx = index;// 默认中文,所以this.$i18n.locale == "zh"时走正常的路由跳转if (this.$i18n.locale == "zh") {this.$router.push({ path: path });} else {if (process.client) {let routerPath = this.$route.fullPath;// 如果路由中没有包含/en/就添加,如果有则走正常的路由跳转if (routerPath.indexOf("/en/") == -1) {this.$router.push({ path: `${this.$i18n.locale}/${path}` });} else {this.$router.push({ path: path });}}}},
相关文章:
nuxt使用i18n进行中英文切换
中文效果图: 英文效果图: 版本: 安装: npm install --save nuxtjs/i18n 新建en.js与zh.js两个文件进行切换显示 en.js内容 import globals from ./../js/global_valexport default {/******* 公共内容开始* *****/seeMore: &quo…...
机器人制作开源方案 | 行星探测车实现WiFi视频遥控功能
1. 功能描述 本文示例所实现的功能为:用手机APP,通过WiFi通信遥控R261样机行星探测车移动,以及打开、关闭行星探测车太阳翼。 2. 电子硬件 在这个示例中,我们采用了以下硬件,请大家参考: 主控板 Basra主控…...
Angular main 中的enableProdMode
enableProdMode一次深度解析 在Angular的开发过程中,我们经常会遇到一个名为enableProdMode的设置。这个设置位于Angular的主模块(main module)中,它的主要作用是启用生产模式。那么,什么是生产模式?为什么…...
驱动day2:LED灯实现三盏灯的亮灭
head.h #ifndef __HEAD_H__ #define __HEAD_H__ #define PHY_PE_MODER 0x50006000 #define PHY_PF_MODER 0x50007000 #define PHY_PE_ODR 0x50006014 #define PHY_PF_ODR 0x50007014 #define PHY_RCC 0x50000A28#endif 应用程序 #include <stdio.h> #include <sys/…...
Android 编译错误:module xxx1 missing dependencies:xxx2
编译错误log module xxx1 missing dependencies:xxx2 分析方向 1.缺少依赖库 添加依赖库 shared_libs: ["libhidlbase","libhidltransport","libhwbinder","liblog","libutils","libcutils",],2.缺…...
使用EasyExcel实现Excel导入导出
介绍 EasyExcel是一个基于Java的、快速、简洁、解决大文件内存溢出的Excel处理工具。 他能让你在不用考虑性能、内存的等因素的情况下,快速完成Excel的读、写等功能。 快速:快速的读取excel中的数据。 简洁:映射excel和实体类,让…...
京东手机销售数据:2023年9月京东手机行业TOP10品牌排行榜
鲸参谋监测的京东平台9月份手机市场销售数据已出炉! 9月份,手机市场销售整体呈现下滑。鲸参谋数据显示,今年9月,京东平台手机销量为300万,环比下降约20%,同比下降约18%;销售额为92亿,…...
常量字符串
一、常量字符串是什么? 常量字符串是一个常量,它的值是首字符的地址 比如 "abcdefg" 或 "123456789" 就是常量字符串 二、常量字符串与普通字符串的区别 1.常量字符串不可更改,而普通字符串可以更改 利用memcpy内存…...
【活体检测】“深度学习驱动的人脸反欺诈检测系统:性能提升与多模型支持“
微调小视科技开源静默活体检测模型加载方式,性能提升8倍 I. 引言 在当今数字化时代,人脸反欺诈检测在各种应用中发挥着重要作用,从人脸识别到金融欺诈检测。为了满足不断增长的需求,深度学习技术已成为关键工具,但性…...
Howler.js HTML5声音引擎
介绍 Howler.js是一个不错的HTML5声音引擎。功能强大,性能不错,用起来也很方便。 1. 官网 https://howlerjs.com/ GitHub https://github.com/goldfire/howler.js 2. 兼容性 Howler默认使用Web Audio,但在IE上可以自动转为HTML 5 Audio。这…...
centos 7.9每天定期发送最新备份文件到另外一台服务器
1.需求 在本地化部署的过程中,为了使系统相对来说高可用,一般情况下,我们都会做一个负载,但是客户又会考虑成本,所以只有可怜巴巴的两台服务器,要全部服务都做负载,这个就实现不了。所以只能把…...
一文全面了解:一个神奇的 react-antd-admin 动态菜单
在React v18中使用React Router v6和Ant Design (antd) v5来动态生成菜单和路由,同时使用MockJS来模拟接口请求菜单数据,可以按照以下步骤进行: 创建一个React应用: 使用Create React App或您喜欢的其他方式创建一个React应用。 安装必要的依赖: 在项目目录中运行以下命令…...
二叉树,堆排序及TopK问题
要讲二叉树的概念,就要先讲树的概念。 树是什么呢? 树其实是一种储存数据的结构,因为他的结构倒过来和生活中的树很相似所以才被称之为树。 这是一颗多叉树,从最顶端的节点可以找到下边的几个节点,下边的节点又可以找…...
iphone xr密码错误太多次 连接itunes
itunes下载的固件在电脑在电脑的“C:\Users\用户名\AppData\Roaming\Apple Computer\iTunes\iPhone Software Updates”文件夹之中。 如果你忘记了 iPhone 密码 - 官方 Apple 支持 (中国) 下载和使用 Windows 10 版 iTunes - 官方 Apple 支持 (中国) 查找手机 iClo…...
设置RabbitMQ超时时间
RabbitMQ默认的超时时间是30分钟,在消息消费超过30分钟后,rabbitMQ会发生错误,导致整个channel被销毁,无法继续消费 在RabbitMQ安装的终端执行 rabbitmqctl eval application:set_env(rabbit,consumer_timeout,180000000). 命令…...
QT计时器
widget.h #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QTimerEvent> //计时器类 #include <QTime> //时间类 QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass Widget : public QWidget {Q_OBJECTpublic:Widg…...
3-k8s-镜像仓库harbor搭建
文章目录 一、概念二、安装harbor三、使用harbor仓库 一、概念 官方概念:Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器。 我们平时拉去镜像都是从线上仓库拉去,但是企业内部的镜像一般都不会随意传到网上,而是保存在自己公…...
0基础学习PyFlink——模拟Hadoop流程
学习大数据还是绕不开始祖级别的技术hadoop。我们不用了解其太多,只要理解其大体流程,然后用python代码模拟主要流程来熟悉其思想。 还是以单词统计为例,如果使用hadoop流程实现,则如下图。 为什么要搞这么复杂呢? 顾…...
【无人机】太阳能伪卫星VoLTE无人机设计(Matlab代码实现)
💥💥💞💞欢迎来到本博客❤️❤️💥💥 🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。 ⛳️座右铭&a…...
2023.10.20 LED驱动
驱动程序 #include<linux/init.h> #include<linux/module.h> #include<linux/fs.h> #include<linux/uaccess.h> #include<linux/io.h> #include"head.h"unsigned int major; unsigned int *vir_moder; unsigned int *vir_odr; unsign…...
从Rancher Server到Node Agent:一张图看懂Rancher 2.8架构,搞懂它如何“遥控”你的K8s
Rancher 2.8架构深度解析:从UI点击到Pod创建的完整链路追踪 当你点击Rancher UI上的"创建工作负载"按钮时,这个看似简单的操作背后究竟发生了什么?本文将带你穿透表象,沿着请求链路逐层拆解Rancher 2.8的完整架构体系。…...
如何快速打造个性化机械键盘:开源项目的完整DIY指南
如何快速打造个性化机械键盘:开源项目的完整DIY指南 【免费下载链接】HelloWord-Keyboard 项目地址: https://gitcode.com/gh_mirrors/he/HelloWord-Keyboard 你是否厌倦了市面上千篇一律的机械键盘?是否渴望拥有一把完全按照自己需求定制的输入…...
AI革命:Gemini如何重塑CI/CD自动化
引言:AI在DevOps中的崛起简要介绍AI工具(如Gemini)如何改变传统CI/CD流程,强调自动化脚本生成的优势和行业趋势。Gemini与CI/CD的结合点分析Gemini在理解YAML、Bash等脚本语言上的能力,举例说明其如何通过自然语言描述…...
如何为你的ESP32 AI助手添加“眼睛“:xiaozhi-esp32摄像头集成终极指南
如何为你的ESP32 AI助手添加"眼睛":xiaozhi-esp32摄像头集成终极指南 【免费下载链接】xiaozhi-esp32 An MCP-based chatbot | 一个基于MCP的聊天机器人 项目地址: https://gitcode.com/GitHub_Trending/xia/xiaozhi-esp32 想象一下,你…...
深度解析Fusion 360 3D打印螺纹优化方案:Fusion-360-FDM-threads实战指南
深度解析Fusion 360 3D打印螺纹优化方案:Fusion-360-FDM-threads实战指南 【免费下载链接】Fusion-360-FDM-threads 项目地址: https://gitcode.com/gh_mirrors/fu/Fusion-360-FDM-threads Fusion-360-FDM-threads 是一款专为3D打印螺纹设计优化的开源工具&…...
【课题介绍】 多智能体协同围捕仿真,MATLAB运动仿真
文章目录课题介绍研究背景课题研究内容仿真系统组成运行结果主界面运行结果运动轨迹显示结果距离误差显示结果角度均匀性显示结果性能统计结果课题介绍 研究背景 随着无人机集群、移动机器人系统和多智能体协同控制技术的发展,多个智能体之间的协同运动逐渐成为无…...
大语言模型混合架构:显式记录与最大熵方法优化
1. 大语言模型的学习困境与人类启发在自然语言处理领域,大型语言模型(LLM)已经展现出惊人的能力,从代码生成到创意写作,从技术问答到逻辑推理。然而,当我们把这些模型部署到真实世界的专业场景时——比如诊断一台特定型号的工业设…...
OBS模糊插件终极指南:5分钟掌握专业视频模糊特效
OBS模糊插件终极指南:5分钟掌握专业视频模糊特效 【免费下载链接】obs-composite-blur A comprehensive blur plugin for OBS that provides several different blur algorithms, and proper compositing. 项目地址: https://gitcode.com/gh_mirrors/ob/obs-compo…...
SageMath在数论研究中的应用:从素数判定到椭圆曲线
SageMath在数论研究中的应用:从素数判定到椭圆曲线 【免费下载链接】sage Main repository of SageMath 项目地址: https://gitcode.com/gh_mirrors/sag/sage SageMath是一个功能强大的开源数学软件系统,广泛应用于数论研究领域。它集成了众多数学…...
重构网盘资源获取工作流:baidupankey的智能解析方法论
重构网盘资源获取工作流:baidupankey的智能解析方法论 【免费下载链接】baidupankey 项目地址: https://gitcode.com/gh_mirrors/ba/baidupankey 在数字资源分享的日常场景中,百度网盘链接的提取码查询已成为一个普遍存在的效率瓶颈。当面对海量…...
