当前位置: 首页 > 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…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

第19节 Node.js Express 框架

Express 是一个为Node.js设计的web开发框架&#xff0c;它基于nodejs平台。 Express 简介 Express是一个简洁而灵活的node.js Web应用框架, 提供了一系列强大特性帮助你创建各种Web应用&#xff0c;和丰富的HTTP工具。 使用Express可以快速地搭建一个完整功能的网站。 Expre…...

五年级数学知识边界总结思考-下册

目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解&#xff1a;由来、作用与意义**一、知识点核心内容****二、知识点的由来&#xff1a;从生活实践到数学抽象****三、知识的作用&#xff1a;解决实际问题的工具****四、学习的意义&#xff1a;培养核心素养…...

在四层代理中还原真实客户端ngx_stream_realip_module

一、模块原理与价值 PROXY Protocol 回溯 第三方负载均衡&#xff08;如 HAProxy、AWS NLB、阿里 SLB&#xff09;发起上游连接时&#xff0c;将真实客户端 IP/Port 写入 PROXY Protocol v1/v2 头。Stream 层接收到头部后&#xff0c;ngx_stream_realip_module 从中提取原始信息…...

CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云

目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...

爬虫基础学习day2

# 爬虫设计领域 工商&#xff1a;企查查、天眼查短视频&#xff1a;抖音、快手、西瓜 ---> 飞瓜电商&#xff1a;京东、淘宝、聚美优品、亚马逊 ---> 分析店铺经营决策标题、排名航空&#xff1a;抓取所有航空公司价格 ---> 去哪儿自媒体&#xff1a;采集自媒体数据进…...

OPENCV形态学基础之二腐蚀

一.腐蚀的原理 (图1) 数学表达式&#xff1a;dst(x,y) erode(src(x,y)) min(x,y)src(xx,yy) 腐蚀也是图像形态学的基本功能之一&#xff0c;腐蚀跟膨胀属于反向操作&#xff0c;膨胀是把图像图像变大&#xff0c;而腐蚀就是把图像变小。腐蚀后的图像变小变暗淡。 腐蚀…...

听写流程自动化实践,轻量级教育辅助

随着智能教育工具的发展&#xff0c;越来越多的传统学习方式正在被数字化、自动化所优化。听写作为语文、英语等学科中重要的基础训练形式&#xff0c;也迎来了更高效的解决方案。 这是一款轻量但功能强大的听写辅助工具。它是基于本地词库与可选在线语音引擎构建&#xff0c;…...

Python 包管理器 uv 介绍

Python 包管理器 uv 全面介绍 uv 是由 Astral&#xff08;热门工具 Ruff 的开发者&#xff09;推出的下一代高性能 Python 包管理器和构建工具&#xff0c;用 Rust 编写。它旨在解决传统工具&#xff08;如 pip、virtualenv、pip-tools&#xff09;的性能瓶颈&#xff0c;同时…...

GitHub 趋势日报 (2025年06月06日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 590 cognee 551 onlook 399 project-based-learning 348 build-your-own-x 320 ne…...