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

taro-vue-i18n-lite

v0.1.3

Published

轻量级国际化插件 Taro Vue3 版本

Downloads

4

Readme

taro-vue-i18n-lite

轻量级国际化插件 Taro Vue3 版本

安装

在 Taro 项目根目录下安装

npm i taro-vue-i18n-lite
# 或使用yarn
yarn add taro-vue-i18n-lite
# 或使用pnpm
pnpm add taro-vue-i18n-lite

快速上手

Typescript 支持

修改tsconfig.json

{
  "include": ["node_modules/taro-vue-i18n-lite/typings"]
}

安装插件

import { createApp } from "vue"
import i18n from "taro-vue-i18n-lite"

// 定义国际化文本
const messages = {
  "zh-CN": {
    say: {
      hi: "嗨~",
    },
  },
  "en-US": {
    say: {
      hi: "Hi~",
    },
  },
}

// 通过 `App.use()` 安装 `Vue` 插件:`taro-vue-i18n-lite`
const App = createApp({})
App.use(i18n, {
  locale: "zh-CN",
  messages,
})

视图中使用

<template>
  <div>{{ $t("say.hi") }}</div>
</template>
<script setup></script>

输出

<div>嗨~</div>

更多用法

动态切换语言

<template>
  <div>{{ $t("say.hi") }}</div>
  <button @click="changeLocale">点我切换语言</button>
</template>
<script setup>
  import { useI18n } from "taro-vue-i18n-lite"

  const i18n = useI18n()

  const changeLocale = () => {
    const currentLocale = i18n.getCurrentLocale()
    i18n.changeLocale(currentLocale === "zh-CN" ? "en-US" : "zh-CN")
  }
</script>

JS/TS 中翻译文本

<template>
  <div>{{ hi }}</div>
  <button @click="translate">点我翻译</button>
</template>
<script setup>
  import { ref } from "vue"
  import { useI18n } from "taro-vue-i18n-lite"

  const i18n = useI18n()

  const hi = ref("say.hi")

  const translate = () => {
    hi.value = i18n.t("say.hi")
  }
</script>

输出由

<div>say.hi</div>

变为

<div>嗨~</div>

动态参数

// 定义国际化文本
const messages = {
  "zh-CN": {
    say: {
      hi: "嗨~ {name}",
    },
  },
  "en-US": {
    say: {
      hi: "Hi~ {name}",
    },
  },
}
<div>{{ $t("say.hi", { name: 'i18n' }) }}</div>

输出

<div>嗨~ i18n</div>

配合 UI 组件

NutUI 为例,配合 taro-vue-i18n-lite 使用:

安装 NutUI 参考指南 快速上手

import { createApp } from "vue"
import { Locale } from "@nutui/nutui-taro"
import i18n from "taro-vue-i18n-lite"

import enUS from "@nutui/nutui-taro/dist/packages/locale/lang/en-US"
import zhCN from "@nutui/nutui-taro/dist/packages/locale/lang/zh-CN"

const App = createApp({})

const messages = {
  "zh-CN": {
    say: {
      hi: "嗨~ {name}",
      goodbye: "再见!",
    },
  },
  "en-US": {
    say: {
      hi: "Hi~ {name}",
      goodbye: "Goodbye!",
    },
  },
}

App.use(i18n, {
  locale: "zh-CN",
  messages,
  onInstall: (locale: string) => {
    Locale.use(locale, locale === "zh-CN" ? zhCN : enUS)
  },
  onChange: (locale: string) => {
    Locale.use(locale, locale === "zh-CN" ? zhCN : enUS)
  },
})

交流

如果你有新的功能需求或者想参与到这个国际化插件的开发中,欢迎提 Issue或添加我的好友

QQ: 543456277