Skip to content

Internationalization

SeeYouUI provides a built-in lightweight internationalization solution supporting Chinese, English, and any other languages.

It is fully compatible with all uni-app platforms (H5, App, Mini Program), has zero external dependencies, and is deeply integrated with the component library — all component text updates automatically when the language switches.

Quick Start

Zero Configuration

If you only need Chinese or English, no configuration is required.

Components will automatically switch based on the system language:

  • When the system language is Chinese, components display Chinese text
  • Otherwise, components default to English text
vue
<template>
  <!-- Button text follows system language automatically -->
  <see-calendar />
  <see-picker />
  <see-pagination />
</template>

Set Default Language

In your entry file (main.js or main.ts), create an i18n instance and pass it via app.use():

js
// main.js
import { createI18n } from 'see-u-ui'
import SeeYouUI from 'see-u-ui'

// Create i18n instance
const i18n = createI18n({
  locale: 'en',              // Default language
  fallbackLocale: 'zh-CN',   // Fallback language when key is missing
})

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  // Pass i18n instance
  app.use(SeeYouUI, { i18n })
  return { app }
}
// #endif

Switch Language Dynamically

vue
<template>
  <view>
    <see-calendar />
    <button @click="switchToEn">English</button>
    <button @click="switchToZh">中文</button>
  </view>
</template>

<script setup>
import { useI18n } from 'see-u-ui'

const { setLocale } = useI18n()

const switchToEn = () => setLocale('en')
const switchToZh = () => setLocale('zh-CN')
</script>

Custom Language Pack

You can override built-in text or add entirely new languages.

js
import { createI18n } from 'see-u-ui'

const i18n = createI18n({
  locale: 'ja',             // Use Japanese
  fallbackLocale: 'zh-CN',  // Fallback to Chinese for missing Japanese keys
  messages: {
    // Fully customize English text
    'en': {
      cancel: 'Go Back',
      confirm: 'OK',
      'calendar.week.sunday': 'Sunday',
      // ... override other keys
    },
    // Add a new language
    'ja': {
      cancel: 'キャンセル',
      confirm: '確認',
      'calendar.week.sunday': '日',
      'calendar.week.monday': '月',
      // ...
    },
  },
})

export function createApp() {
  const app = createSSRApp(App)
  app.use(SeeYouUI, { i18n })
  return { app }
}

Using Translation in Business Code

The t() function returned by useI18n() can also translate your own text:

vue
<template>
  <view>
    <h1>{{ t('greeting', { name: userName }) }}</h1>
    <button @click="toggleLang">Switch Language</button>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { useI18n } from 'see-u-ui'

const { t, locale } = useI18n()
const userName = ref('Buddy')

const toggleLang = () => {
  locale.value = locale.value === 'zh-CN' ? 'en' : 'zh-CN'
}
</script>

Define your own translation keys in createI18n:

js
const i18n = createI18n({
  messages: {
    'zh-CN': {
      greeting: '你好,{name}!',
      // ... other component keys will auto-merge with built-in locales
    },
    'en': {
      greeting: 'Hello, {name}!',
    },
  },
})

Using <see-config>

If you use the <see-config> component as the root node, you can also set the language on it:

vue
<!-- App.vue -->
<template>
  <see-config locale="en">
    <!-- All child components switch to English -->
    <router-view />
  </see-config>
</template>

Built-in Locale Keys

The following are all translation keys built into SeeYouUI components. You can override any of them.

Common

KeyEnglishChinese
cancelCancel取消
confirmOK确定
closeClose关闭
loadingLoading...加载中...
noDataNo Data暂无数据
loadMoreLoad More加载更多
pullRefreshPull to Refresh下拉刷新
retryRetry重试
searchSearch搜索
resetReset重置

Calendar

KeyEnglishChinese
calendar.week.sundaySu
calendar.week.mondayMo
calendar.week.tuesdayTu
calendar.week.wednesdayWe
calendar.week.thursdayTh
calendar.week.fridayFr
calendar.week.saturdaySa
calendar.todayToday今天
calendar.month.januaryJan1月
calendar.month.februaryFeb2月
calendar.month.marchMar3月
calendar.month.aprilApr4月
calendar.month.mayMay5月
calendar.month.juneJun6月
calendar.month.julyJul7月
calendar.month.augustAug8月
calendar.month.septemberSep9月
calendar.month.octoberOct10月
calendar.month.novemberNov11月
calendar.month.decemberDec12月

Picker / DatetimePicker

KeyEnglishChinese
picker.cancelCancel取消
picker.confirmConfirm确定
picker.yearYear
picker.monthMonth
picker.dayDay
picker.hourHour
picker.minuteMin
picker.secondSec
picker.startDateStart开始日期
picker.endDateEnd结束日期

Upload

KeyEnglishChinese
upload.selectFileSelect File选择文件
upload.uploadingUploading...上传中...
upload.successUploaded上传成功
upload.failUpload Failed上传失败
upload.exceedSizeFile size exceeded文件大小超出限制
upload.exceedCountFile count exceeded文件数量超出限制

Pagination

KeyEnglishChinese
pagination.total{total} items共 {total} 条
pagination.prevPrev上一页
pagination.nextNext下一页

Table

KeyEnglishChinese
table.emptyNo Data暂无数据
table.sortAscAscending升序
table.sortDescDescending降序

Empty

KeyEnglishChinese
empty.defaultNo Data暂无数据
empty.networkNetwork Error网络不给力
empty.searchNo Results Found没有找到相关内容
KeyEnglishChinese
modal.cancelCancel取消
modal.confirmConfirm确定

ActionSheet

KeyEnglishChinese
actionSheet.cancelCancel取消
KeyEnglishChinese
search.placeholderPlease enter keywords请输入搜索内容
search.cancelCancel取消

CountDown

KeyEnglishChinese
countdown.dayd
countdown.hourh
countdown.minutem
countdown.seconds

Keyboard

KeyEnglishChinese
keyboard.doneDone完成

Cascader

KeyEnglishChinese
cascader.placeholderPlease select请选择

NoticeBar

KeyEnglishChinese
noticeBar.closeClose关闭
noticeBar.moreDetails详情

SwipeAction

KeyEnglishChinese
swipeAction.confirmConfirm delete?确认删除?

NoNetwork

KeyEnglishChinese
noNetwork.titleNetwork Error网络不给力
noNetwork.retryTap to retry点击重试

LoadingPage

KeyEnglishChinese
loadingPage.loadingLoading...加载中...

About vue-i18n

SeeYouUI's built-in i18n is completely independent of vue-i18n.

If you use vue-i18n in your project, the two can coexist without interfering with each other. However, you will need to manually sync language state between the two i18n instances if needed.

Recommended practice: Use SeeYouUI's built-in i18n to manage component library text, and for your business text you can use either SeeYouUI's i18n (useI18n) or vue-i18n — they don't conflict.

API Reference

See useI18n API Documentation.

Liao ICP No. 2025070134