
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
vue-multilang
Advanced tools
control of languages in vue2
# npm
npm install vue-multilang --save-dev
cd vue-multilang
npm install
npm run dev
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:
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
| 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为返回的值 |
FAQs
multilanguage easy support to Vue.js 2
The npm package vue-multilang receives a total of 2 weekly downloads. As such, vue-multilang popularity was classified as not popular.
We found that vue-multilang demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.