npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-multilang

v1.0.4

Published

multilanguage easy support to Vue.js 2

Downloads

6

Readme

vue-multilang: 前端多语言加载器

control of languages in vue2

Installation

# npm
npm install vue-multilang --save-dev

Example

cd vue-multilang
npm install
npm run dev

Get Started

in main.js

import Vue from 'vue'
import App from './App.vue'
import VueMultiLang from "vue-multilang"

Vue.use(VueMultiLang)

let multiLang = new VueMultiLang({
    path: './example/lang',
    version: 1,
    lang: ['ar', 'vi', 'th', 'id']
})
new Vue({
    el: '#app',
    multiLang, // 实例名约定 必须multiLang 参考router(vue-router)、store(vuex)
    render: h => h(App)
})

in HTML

<script src="/assets/js/vue.min.js"></script>
<script src="/assets/js/vue-multilang.js"></script>

let multiLang = new VueMultiLang({
    path: './example/lang',
    version: 1,
    lang: ['ar', 'vi', 'th', 'id']
})
new Vue({
    el: '#app',
    multiLang, // 实例名约定 必须multiLang 参考router(vue-router)、store(vuex)
    render: h => h(App)
})

More details:

  • langCode: 语言码
  • countryCode: 国家码
  • langObj: 语言包数据
  • onReady: 语言包加载完毕后的回调函数 可写多个
    • @param fn(data): data是语言包数据
  • template: 模板内容替换 动态替换语言包的内容 匹配规则为%s
    • @param key: 语言包字段
    • @param args: 动态参数列表

use in components - this.$lang inside of any component

export default {
    ...,
    data() {
        return {
            langObj: {},
            lang: ''
        }
    },
    computed: {
        text() {
            /**
             * {'rank': 'my name is %s'} from langObj 
             */
             
            // result: 'my name is dongshaohan'
            return this.$lang.template('rank', ['dongshaohan'])
        }
    },
    created() {
        this.$lang.onReady(() => {
            this.langObj = this.$lang.langObj
            this.langCode = this.$lang.langCode
            this.countryCode = this.$lang.countryCode
        });
    },
    ...
}

use in window - window.$multiLang

window.$multiLang.langCode
window.$multiLang.countryCode
window.$multiLang.langObj
window.$multiLang.onReady
window.$multiLang.template

Config

|name|required|type|introduction| |----|----|----|----| |lang|yes|array|项目需要配置的语言码集合,写成数组形式['en', 'th', 'id']| |path|no|string|语言包路径,默认是空字符串| |defaultLang|no|string|设置默认语言,防止匹配不到语言包出错| |version|no|string|语言包文件版本号,去缓存| |langUrlRegExp|no|string|URL语言码匹配规则,默认/\blang=(.+?)\b/i| |langUaRegExp|no|string|UA语言码匹配规则,默认/\blang/(.+?)\b/i| |locationUrlRegExp|no|string|URL国家码匹配规则,默认/\blocation=(.+?)\b/i| |locationUaRegExp|no|string|UA国家码匹配规则,默认/\blocation/(.+?)\b/i| |rtlList|no|array|阅读习惯从右到左的语言码集合| |dataType|no|string|语言包文件类型,默认json| |callback|no|function|语言包加载成功后回调,参数data为返回的值|