国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

nuxt使用i18n進行中英文切換

這篇具有很好參考價值的文章主要介紹了nuxt使用i18n進行中英文切換。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

中文效果圖:

nuxt使用i18n進行中英文切換,vue.js,前端,javascript

英文效果圖:

nuxt使用i18n進行中英文切換,vue.js,前端,javascript

版本:

nuxt使用i18n進行中英文切換,vue.js,前端,javascript

安裝:

 npm install --save @nuxtjs/i18n

?新建en.js與zh.js兩個文件進行切換顯示

nuxt使用i18n進行中英文切換,vue.js,前端,javascript

en.js內(nèi)容?

import globals from './../js/global_val'

export default {
  /******
   * 公共內(nèi)容開始
   * *****/
  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', //點擊報名參評-pc
  applicationOver: 'The entry channel is closed', //參評已結(jié)束-pc
  mApplication: '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: ""
    },
  ],
  
  /******
   * 公共內(nèi)容結(jié)束
   * *****/
  /******
   * 首頁開始
   * *****/

  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內(nèi)容:

// 首頁
// const globals =  require('./js/global_val.js')
import globals from './../js/global_val'

export default {
  /******
   * 公共內(nèi)容開始
   * *****/
  seeMore: "查看更多", //查看更多
  seeAgenda: "查看議程", //查看議程
  jtlRegister: '金陀螺獎報名參評/投票', //金陀螺獎報名參評/投票
  registrationChannel: '大會參會報名通道', //大會參會報名通道
  fbecland: '大會互動微站 FBEC LAND', //大會官方微站
  application: '點擊報名參評', //點擊報名參評-pc
  applicationOver: '參評已結(jié)束', //參評已結(jié)束-pc
  mApplication: '點擊報名參評/投票', //點擊報名參評/投票-手機端
  mAplicationOver: '點擊報名參評/投票', //點擊報名參評/投票-手機端
  headerData: [{
      name: "首頁",
      url: "/"
    },
    {
      name: "主會場",
      url: "main-venue"
    },
    {
      name: "分會場",
      url: "branch-venue"
    },
    {
      name: "金陀螺獎",
      url: "golden-top-award"
    },
    {
      name: "大會展區(qū)",
      url: "conference-exhibition-area"
    },
    {
      name: "更多精彩",
      url: "more-exciting-content"
    },
    {
      name: "大會動態(tài)",
      url: "conference-dynamics"
    },
    {
      name: "往屆回顧",
      url: ""
    },
  ],
  
  /******
   * 公共內(nèi)容結(jié)束
   * *****/
  /******
   * 首頁開始
   * *****/
  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: "組織機構(gòu)",
      id: "zhuzhi",
    },
    {
      label: "合作媒體",
      id: "meiti",
    },
    {
      label: "大會報道",
      id: "baodao",
    },
    {
      label: "精彩現(xiàn)場",
      id: "huigu",
    },
  ], //首頁時間軸
  part1: {
    time: '深圳·大中華喜來登酒店 2023/12/08',
    des1: '2023年,我們親歷了人工智能的蓬勃發(fā)展,AI技術(shù)的飛速演進,不僅加乘了商業(yè)模式的創(chuàng)新,也催生了市場變化。當市場泡沫退去,AI時代的新浪潮涌動,我們堅守初心,對未來互聯(lián)網(wǎng)發(fā)展形態(tài)進行探索,對新科技、新商業(yè)、新模式未來價值進行謀劃,我們堅信唯有保持百折不撓的韌性與生命力,不斷進化自身以適應市場環(huán)境變化,共榮共生,方能韌行致遠。',
    des2: '2023未來商業(yè)生態(tài)鏈接大會暨第八屆金陀螺獎頒獎典禮(簡稱“FBEC2023”)由陀螺科技主辦,以“合力共生 · 韌者行遠”為大會主題,以具有行業(yè)前瞻洞察的“航行者”為視角,破冰之旅為主線,關(guān)注AI、元宇宙、XR、游戲、電競、數(shù)字經(jīng)濟等科技與互聯(lián)網(wǎng)前沿領(lǐng)域,全方位呈現(xiàn)科技前沿成果,聚焦時代與商業(yè)熱點議題,探討新科技、新商業(yè)、新模式的未來價值,與真正的勇者共赴劇變革新下的凜冬破冰之旅!'
  }, //首頁大會簡介

}

在plugins下新建i18n.js

nuxt使用i18n進行中英文切換,vue.js,前端,javascript

i18n.js內(nèi)容:

import zh_cn from '../assets/lang/zh.js'
import en_us from '../assets/lang/en.js'
const i18n = {
  locales: ['en', 'zh'], //有多少地區(qū)的語言就添加多少種
  defaultLocale: 'zh', //默認的地區(qū)語言
  vueI18n: {
    fallbackLocale: 'en', //回退策略,指定的locale中沒有找到對應資源的情況下使用的locale
    messages: { //要渲染的信息,有多少語言就添加多少種
      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-link
            class="change-language cn-icon"
            v-if="$i18n.locale !== 'en'"
            :to="switchLocalePath('en')"
          >中文</nuxt-link>
          <nuxt-link
            class="change-language en-icon"
            v-if="$i18n.locale !== 'zh'"
            :to="switchLocalePath('zh')"
          >英文</nuxt-link>
        </div>
<!--方式二 -->
<!--html -->
        <div class="change-languag-box">
     
          <div
            class="change-language cn-icon"
            v-if="$i18n.locale !== 'en'"
            @click="changeLocale('en')"
          ></div>
          <div
            class="change-language en-icon"
            v-if="$i18n.locale !== 'zh'"
            @click="changeLocale('zh')"
          ></div>
        </div>
<!--js -->
  changeLocale(locale) {
      // 在頁面中添加 changeLocale 方法,調(diào)用 $i18n.setLocale 方法來切換語言
      this.$i18n.setLocale(locale);
    },

頁面展示

<template>
  <!-- <client-only></client-only>加這個刷新頁面才不會顯示異常 -->
  <client-only>

        <!--內(nèi)容 -->
      <div class="des">
          <div
            class="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>

有導航的需要在導航切換的時候處理一下相關(guān)內(nèi)容:文章來源地址http://www.zghlxwxcb.cn/news/detail-722053.html

  <!-- html(headerData為導航內(nèi)容) --> 
<div class="com-header-cont flex-center-start">
          <div
            class="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>
            <ul
              v-if="tabIdx == 7"
              class="dropdown-wrapper"
              v-show="dropdownActive"
            >
              <li
                class="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"時走正常的路由跳轉(zhuǎn)
      if (this.$i18n.locale == "zh") {
        this.$router.push({ path: path });
      } else {
        if (process.client) {
          let routerPath = this.$route.fullPath;
          // 如果路由中沒有包含/en/就添加,如果有則走正常的路由跳轉(zhuǎn)
          if (routerPath.indexOf("/en/") == -1) {
            this.$router.push({ path: `${this.$i18n.locale}/${path}` });
          } else {
            this.$router.push({ path: path });
          }
        }
      }
    },

到了這里,關(guān)于nuxt使用i18n進行中英文切換的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • Spring之國際化:i18n

    Spring之國際化:i18n

    學習的最大理由是想擺脫平庸,早一天就多一份人生的精彩;遲一天就多一天平庸的困擾。各位小伙伴,如果您: 想系統(tǒng)/深入學習某技術(shù)知識點… 一個人摸索學習很難堅持,想組團高效學習… 想寫博客但無從下手,急需寫作干貨注入能量… 熱愛寫作,愿意讓自己成為更好

    2024年02月03日
    瀏覽(39)
  • i18n多國語言Internationalization的實現(xiàn)

    i18n多國語言Internationalization的實現(xiàn)

    i18n?是\\\"Internationalization”的縮寫,這個術(shù)語來源于英文單詞中首尾字母“”和“n”以及中間的字符數(shù)(共計18個字符) 當我們需要開發(fā)不同語言版本時,就可以使用i18n多國語言的一個操作處理,i18n主要實現(xiàn)那一方面的內(nèi)容呢?例如: 文本內(nèi)容本地化、日期/時間格式、貨幣與度

    2024年01月16日
    瀏覽(19)
  • i18n(國際化)代碼簡單實現(xiàn)

    i18n(國際化)代碼簡單實現(xiàn)

    各個國家都有各個國家的語言,如果網(wǎng)站需要讓全世界的人使用,那就需要進行國際化功能開發(fā) 國際化我知道的一共有兩種,其中一種是不同國家不同網(wǎng)站,也就是說頁面風格都不一樣。另外一種是網(wǎng)站都是一樣的,只是里面的文字不同罷了。第一種沒啥好說了,畢竟都是兩

    2024年02月07日
    瀏覽(23)
  • vue3 i18n配置詳細教學

    npm install vue-i18n@next @next 表示安裝i18n 最新的 vue3的版本 點擊按鈕切換語言?

    2024年02月16日
    瀏覽(23)
  • Next實現(xiàn) i18n 傳遞 locales 給 getStaticPaths

    在 Next.js 中實現(xiàn)國際化( i18n )時,可以通過配置 next.config.js 文件來傳遞 locales 給 getStaticPaths 函數(shù)。下面是一個示例代碼,演示如何在 next.config.js 中配置 locales ,并在 getStaticPaths 中獲取并使用這些 locales : 1、配置 next.config.js 文件: 2、在頁面組件中使用 getStaticPaths : 在

    2024年04月24日
    瀏覽(23)
  • SpringBoot - SpringBoot整合i18n實現(xiàn)消息國際化

    SpringBoot - SpringBoot整合i18n實現(xiàn)消息國際化

    在我們開發(fā)WEB項目的時候,項目可能涉及到在國外部署或者應用,也有可能會有國外的用戶對項目進行訪問,那么在這種項目中, 為客戶展現(xiàn)的頁面或者操作的信息就需要根據(jù)客戶系統(tǒng)的環(huán)境來使用不同的語言,這就是我們所說的項目國際化。 1. MessageSource源碼 Spring中定義了

    2024年02月03日
    瀏覽(38)
  • 解決pinia中的i18n切換語言不生效的問題

    在我的項目中,使用i18n切換語言后,會進行 router.push 來刷新頁面。 但我發(fā)現(xiàn)寫在store中的選項(我把它們用作下拉框組件的 options ,例如 options=\\\"store.statusOption\\\" ),卻并沒有切換語言。它們需要我手動刷新頁面后才能夠切換語言。然而其它組件中的語言切換都很正常。 個人

    2024年02月13日
    瀏覽(15)
  • 【angular】實現(xiàn)簡單的angular國際化(i18n)

    【angular】實現(xiàn)簡單的angular國際化(i18n)

    實現(xiàn)簡單的angular國際化。本博客實現(xiàn)中文版和法語版。 將 Hello i18n! 變?yōu)?中文版:你好 i18n! 或 法語版:Bonjour l’i18n ! 。 創(chuàng)建一個項目: 在集成終端中打開。 添加本地化包: 在html中添加格式化標識: 現(xiàn)在運行一下,頁面是: 生成翻譯模板語言包: 生成了一個文件夾: l

    2024年02月08日
    瀏覽(33)
  • spring6-國際化:i18n | 數(shù)據(jù)校驗:Validation

    spring6-國際化:i18n | 數(shù)據(jù)校驗:Validation

    1.1、i18n概述 國際化也稱作i18n,其來源是英文單詞 internationalization的首末字符i和n,18為中間的字符數(shù)。由于軟件發(fā)行可能面向多個國家,對于不同國家的用戶,軟件顯示不同語言的過程就是國際化。通常來講,軟件中的國際化是通過配置文件來實現(xiàn)的,假設(shè)要支撐兩種語言,

    2024年02月08日
    瀏覽(25)
  • 微信小程序-切換語言(國際化i18n)的方法封裝

    微信小程序-切換語言(國際化i18n)的方法封裝

    最近做的一個小程序的項目, 涉及到了 多語言的切換 , 就想到了之前vue用的多語言插件i18n, 就嘗試著在微信開放社區(qū)搜了一下, 沒有具體的實現(xiàn), 但是提供了大致的實現(xiàn)思路, 如下: 又結(jié)合了很多大佬的分享經(jīng)驗, 試著去封裝了一個微信的i18n方法 首先, 我們需要明確一下需要實

    2024年02月05日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包