zoukankan      html  css  js  c++  java
  • i18n的使用(1)

    既然有用到 i18n 那么,肯定需要先安装啦!

    1:安装方式

    npm install vue-i18n
    

      

    2:使用方式

    1:在main.js引入

    import VueI18n from 'vue-i18n'
    Vue.use(VueI18n)
     
    2:准备本地的翻译信息
    const messages = {
      zh: {
        message: {
          hello: '好好学习,天天向上!'
        }
      },
      en: {
        message: {
          hello: 'good good study, day day up!'
        }
      }
    }
    3:创建带有选项的 i18n实例
    const i18n = new VueI18n({
      locale: 'zh', // 语言标识
      messages
    })
    4:将i18n挂载在vue上
    new Vue({
      el: '#app',
      router,
      i18n,
      components: { App },
      template: '<App/>'
    })

    5:使用方式

        <div id="app">
          <h1 style="font-size: 16px; text-align: center;">{{ $t("message.hello") }}</h1>
        </div>

    效果

     将第三步(创建带有选项的 i18n实例)中的  ‘ locale ’ ,换成 ” en “ ,

    const i18n = new VueI18n({
      locale: 'en', // 语言标识
      messages
    })

    后的效果图

    全部代码

    //main.js
    
    import Vue from 'vue'
    import App from './App'
    import router from './router'
    import 'iview/dist/styles/iview.css' // 引入iview css样式
    import VueI18n from 'vue-i18n'
    
    Vue.config.productionTip = false
    Vue.use(iView) //使用iview组件
    Vue.use(VueI18n)
    
    const messages = {
      zh: {
        message: {
          hello: '共产主义接班人'
        }
      },
      en: {
        message: {
          hello: 'successors to the communist cause!'
        }
      }
    }
    
    const i18n = new VueI18n({
      locale: 'en', // 语言标识
      messages
    })
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      i18n,
      components: { App },
      template: '<App/>'
    })


    //vue文件
    
    <template>
      <div>
        <div id="app">
          <h1 style="font-size: 16px; text-align: center;">{{ $t("message.hello") }}</h1>
        </div>
      </div>
    </template>
    <style lang="">
      h1{
        color: skyblue;
      }
    </style>
    <script>
    export default {
      data() {
        return {
        };
      }
    };
    </script>
  • 相关阅读:
    视频编码H.264的应用
    音视频的发展与anychat的技术
    Anychat 行业内最佳的跨平台音视频解决方案
    Android移动端音视频的快速开发教程(六)
    如何快速开发跨平台音视频应用软件
    音视频通讯SDK详解(附代码包)
    Python教学课程分享10-异常处理结构
    Python教学课程分享9-面向对象编程
    Python教学课程分享8-函数
    Python教学课程分享7-文件操作
  • 原文地址:https://www.cnblogs.com/yixiongqiang/p/12217018.html
Copyright © 2011-2022 走看看