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

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进行中英文切换

中文效果图&#xff1a; 英文效果图&#xff1a; 版本&#xff1a; 安装&#xff1a; npm install --save nuxtjs/i18n 新建en.js与zh.js两个文件进行切换显示 en.js内容 import globals from ./../js/global_valexport default {/******* 公共内容开始* *****/seeMore: &quo…...

机器人制作开源方案 | 行星探测车实现WiFi视频遥控功能

1. 功能描述 本文示例所实现的功能为&#xff1a;用手机APP&#xff0c;通过WiFi通信遥控R261样机行星探测车移动&#xff0c;以及打开、关闭行星探测车太阳翼。 2. 电子硬件 在这个示例中&#xff0c;我们采用了以下硬件&#xff0c;请大家参考&#xff1a; 主控板 Basra主控…...

Angular main 中的enableProdMode

enableProdMode一次深度解析 在Angular的开发过程中&#xff0c;我们经常会遇到一个名为enableProdMode的设置。这个设置位于Angular的主模块&#xff08;main module&#xff09;中&#xff0c;它的主要作用是启用生产模式。那么&#xff0c;什么是生产模式&#xff1f;为什么…...

驱动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&#xff1a;xxx2 分析方向 1.缺少依赖库 添加依赖库 shared_libs: ["libhidlbase","libhidltransport","libhwbinder","liblog","libutils","libcutils",],2.缺…...

使用EasyExcel实现Excel导入导出

介绍 EasyExcel是一个基于Java的、快速、简洁、解决大文件内存溢出的Excel处理工具。 他能让你在不用考虑性能、内存的等因素的情况下&#xff0c;快速完成Excel的读、写等功能。 快速&#xff1a;快速的读取excel中的数据。 简洁&#xff1a;映射excel和实体类&#xff0c;让…...

京东手机销售数据:2023年9月京东手机行业TOP10品牌排行榜

鲸参谋监测的京东平台9月份手机市场销售数据已出炉&#xff01; 9月份&#xff0c;手机市场销售整体呈现下滑。鲸参谋数据显示&#xff0c;今年9月&#xff0c;京东平台手机销量为300万&#xff0c;环比下降约20%&#xff0c;同比下降约18%&#xff1b;销售额为92亿&#xff0c…...

常量字符串

一、常量字符串是什么&#xff1f; 常量字符串是一个常量&#xff0c;它的值是首字符的地址 比如 "abcdefg" 或 "123456789" 就是常量字符串 二、常量字符串与普通字符串的区别 1.常量字符串不可更改&#xff0c;而普通字符串可以更改 利用memcpy内存…...

【活体检测】“深度学习驱动的人脸反欺诈检测系统:性能提升与多模型支持“

微调小视科技开源静默活体检测模型加载方式&#xff0c;性能提升8倍 I. 引言 在当今数字化时代&#xff0c;人脸反欺诈检测在各种应用中发挥着重要作用&#xff0c;从人脸识别到金融欺诈检测。为了满足不断增长的需求&#xff0c;深度学习技术已成为关键工具&#xff0c;但性…...

Howler.js HTML5声音引擎

介绍 Howler.js是一个不错的HTML5声音引擎。功能强大&#xff0c;性能不错&#xff0c;用起来也很方便。 1. 官网 https://howlerjs.com/ GitHub https://github.com/goldfire/howler.js 2. 兼容性 Howler默认使用Web Audio&#xff0c;但在IE上可以自动转为HTML 5 Audio。这…...

centos 7.9每天定期发送最新备份文件到另外一台服务器

1.需求 在本地化部署的过程中&#xff0c;为了使系统相对来说高可用&#xff0c;一般情况下&#xff0c;我们都会做一个负载&#xff0c;但是客户又会考虑成本&#xff0c;所以只有可怜巴巴的两台服务器&#xff0c;要全部服务都做负载&#xff0c;这个就实现不了。所以只能把…...

一文全面了解:一个神奇的 react-antd-admin 动态菜单

在React v18中使用React Router v6和Ant Design (antd) v5来动态生成菜单和路由,同时使用MockJS来模拟接口请求菜单数据,可以按照以下步骤进行: 创建一个React应用: 使用Create React App或您喜欢的其他方式创建一个React应用。 安装必要的依赖: 在项目目录中运行以下命令…...

二叉树,堆排序及TopK问题

要讲二叉树的概念&#xff0c;就要先讲树的概念。 树是什么呢&#xff1f; 树其实是一种储存数据的结构&#xff0c;因为他的结构倒过来和生活中的树很相似所以才被称之为树。 这是一颗多叉树&#xff0c;从最顶端的节点可以找到下边的几个节点&#xff0c;下边的节点又可以找…...

iphone xr密码错误太多次 连接itunes

itunes下载的固件在电脑在电脑的“C&#xff1a;\Users\用户名\AppData\Roaming\Apple Computer\iTunes\iPhone Software Updates”文件夹之中。 如果你忘记了 iPhone 密码 - 官方 Apple 支持 (中国) 下载和使用 Windows 10 版 iTunes - 官方 Apple 支持 (中国) 查找手机 iClo…...

设置RabbitMQ超时时间

RabbitMQ默认的超时时间是30分钟&#xff0c;在消息消费超过30分钟后&#xff0c;rabbitMQ会发生错误&#xff0c;导致整个channel被销毁&#xff0c;无法继续消费 在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仓库 一、概念 官方概念&#xff1a;Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器。 我们平时拉去镜像都是从线上仓库拉去&#xff0c;但是企业内部的镜像一般都不会随意传到网上&#xff0c;而是保存在自己公…...

0基础学习PyFlink——模拟Hadoop流程

学习大数据还是绕不开始祖级别的技术hadoop。我们不用了解其太多&#xff0c;只要理解其大体流程&#xff0c;然后用python代码模拟主要流程来熟悉其思想。 还是以单词统计为例&#xff0c;如果使用hadoop流程实现&#xff0c;则如下图。 为什么要搞这么复杂呢&#xff1f; 顾…...

【无人机】太阳能伪卫星VoLTE无人机设计(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&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…...

Python爬虫实战:研究MechanicalSoup库相关技术

一、MechanicalSoup 库概述 1.1 库简介 MechanicalSoup 是一个 Python 库,专为自动化交互网站而设计。它结合了 requests 的 HTTP 请求能力和 BeautifulSoup 的 HTML 解析能力,提供了直观的 API,让我们可以像人类用户一样浏览网页、填写表单和提交请求。 1.2 主要功能特点…...

(十)学生端搭建

本次旨在将之前的已完成的部分功能进行拼装到学生端&#xff0c;同时完善学生端的构建。本次工作主要包括&#xff1a; 1.学生端整体界面布局 2.模拟考场与部分个人画像流程的串联 3.整体学生端逻辑 一、学生端 在主界面可以选择自己的用户角色 选择学生则进入学生登录界面…...

K8S认证|CKS题库+答案| 11. AppArmor

目录 11. AppArmor 免费获取并激活 CKA_v1.31_模拟系统 题目 开始操作&#xff1a; 1&#xff09;、切换集群 2&#xff09;、切换节点 3&#xff09;、切换到 apparmor 的目录 4&#xff09;、执行 apparmor 策略模块 5&#xff09;、修改 pod 文件 6&#xff09;、…...

深入浅出:JavaScript 中的 `window.crypto.getRandomValues()` 方法

深入浅出&#xff1a;JavaScript 中的 window.crypto.getRandomValues() 方法 在现代 Web 开发中&#xff0c;随机数的生成看似简单&#xff0c;却隐藏着许多玄机。无论是生成密码、加密密钥&#xff0c;还是创建安全令牌&#xff0c;随机数的质量直接关系到系统的安全性。Jav…...

渗透实战PortSwigger靶场-XSS Lab 14:大多数标签和属性被阻止

<script>标签被拦截 我们需要把全部可用的 tag 和 event 进行暴力破解 XSS cheat sheet&#xff1a; https://portswigger.net/web-security/cross-site-scripting/cheat-sheet 通过爆破发现body可以用 再把全部 events 放进去爆破 这些 event 全部可用 <body onres…...

Objective-C常用命名规范总结

【OC】常用命名规范总结 文章目录 【OC】常用命名规范总结1.类名&#xff08;Class Name)2.协议名&#xff08;Protocol Name)3.方法名&#xff08;Method Name)4.属性名&#xff08;Property Name&#xff09;5.局部变量/实例变量&#xff08;Local / Instance Variables&…...

linux 错误码总结

1,错误码的概念与作用 在Linux系统中,错误码是系统调用或库函数在执行失败时返回的特定数值,用于指示具体的错误类型。这些错误码通过全局变量errno来存储和传递,errno由操作系统维护,保存最近一次发生的错误信息。值得注意的是,errno的值在每次系统调用或函数调用失败时…...

ElasticSearch搜索引擎之倒排索引及其底层算法

文章目录 一、搜索引擎1、什么是搜索引擎?2、搜索引擎的分类3、常用的搜索引擎4、搜索引擎的特点二、倒排索引1、简介2、为什么倒排索引不用B+树1.创建时间长,文件大。2.其次,树深,IO次数可怕。3.索引可能会失效。4.精准度差。三. 倒排索引四、算法1、Term Index的算法2、 …...

涂鸦T5AI手搓语音、emoji、otto机器人从入门到实战

“&#x1f916;手搓TuyaAI语音指令 &#x1f60d;秒变表情包大师&#xff0c;让萌系Otto机器人&#x1f525;玩出智能新花样&#xff01;开整&#xff01;” &#x1f916; Otto机器人 → 直接点明主体 手搓TuyaAI语音 → 强调 自主编程/自定义 语音控制&#xff08;TuyaAI…...

稳定币的深度剖析与展望

一、引言 在当今数字化浪潮席卷全球的时代&#xff0c;加密货币作为一种新兴的金融现象&#xff0c;正以前所未有的速度改变着我们对传统货币和金融体系的认知。然而&#xff0c;加密货币市场的高度波动性却成为了其广泛应用和普及的一大障碍。在这样的背景下&#xff0c;稳定…...