Skip to content

Internationalization (i18n) ​

captcha-pro provides bilingual support (Chinese/English) for all platforms, with automatic browser language detection on web.

Supported Languages ​

LanguageCodeDefault
Simplified Chinesezh-CN✅ Yes
Englishen-USNo

Message Keys ​

captcha-pro uses a 15-key message set shared across all platforms (Web, mini-programs, Flutter, Android, iOS):

KeyChinese (zh-CN)English (en-US)Context
loading加载中...Loading...Loading state
slider_slide请拖动滑块完成验证Please slide to verifySlider prompt
slider_hint→ 按住滑块,拖动完成验证→ Hold and drag the slider to verifySlider hint
slider_success验证成功Verification successfulSlider success
slider_fail验证失败Verification failedSlider failure
click_prompt请依次点击:Please click in order:Click prompt
click_success验证成功Verification successfulClick success
click_fail验证失败Verification failedClick failure
popup_title请完成安全验证Please complete security verificationPopup title
popup_close关闭ClosePopup close button
refresh刷新RefreshRefresh button (a11y)
error_network网络错误Network errorNetwork error
error_expired验证码已过期Captcha expiredCaptcha expired
error_invalid验证失败Verification failedInvalid verification
error_not_found验证码不存在Captcha not foundCaptcha not found

Platform Usage ​

Web (Vanilla JS / Vue / React) ​

The web platform automatically detects browser language via navigator.language:

javascript
import { SliderCaptcha } from '@captcha-pro/core'

// Auto-detect (default)
new SliderCaptcha({ el: '#captcha' })

// Explicit locale
new SliderCaptcha({ 
  el: '#captcha',
  locale: 'en-US'  // Force English
})

WeChat Mini-Program ​

xml
<!-- WXML -->
<captcha-slider locale="{{locale}}" bind:success="onSuccess" />
javascript
// JS
Page({
  data: {
    locale: 'en-US'  // Force English
  }
})

Taro / uni-app ​

vue
<template>
  <SliderCaptcha :locale="locale" @success="onSuccess" />
</template>

<script setup>
import { ref } from 'vue'
const locale = ref('en-US')
</script>

Flutter ​

dart
import 'package:captcha_pro/captcha_pro.dart';

SliderCaptcha(
  locale: LocaleMessages.enUS,  // Force English
  onSuccess: () => print('Passed!'),
)

Android (Kotlin) ​

kotlin
import com.captcha.pro.sdk.SliderCaptchaView

val captcha = SliderCaptchaView(context).apply {
  setLocale("en-US")  // Force English
}

iOS (Swift) ​

swift
import CaptchaPro

let captcha = SliderCaptchaView(frame: .zero)
captcha.locale = .enUS  // Force English

Customizing Messages ​

Web Platform ​

Override messages globally:

javascript
import { setLocaleMessages } from '@captcha-pro/core'

// Add a new language
setLocaleMessages('ja-JP', {
  loading: '読み込み中...',
  slider_hint: 'スライダーをドラッグして認証',
  // ... all 15 keys
})

Native Platforms ​

Extend the LocaleMessages class (Flutter / Android) or create a custom struct (iOS) with translated strings.

Right-to-Left (RTL) Support ​

The UI automatically mirrors in RTL locales (e.g., Arabic ar-SA). The slider thumb, refresh button, and click markers all honor the text direction:

  • Web: CSS direction: rtl + logical properties
  • Flutter: Directionality widget
  • Android: ViewCompat.setLayoutDirection
  • iOS: SemanticContentAttribute

Accessibility Labels ​

All accessibility labels reuse the i18n keys. For example, the refresh button's accessible name comes from the refresh key:

PlatformImplementation
Webaria-label={messages.refresh}
FlutterSemantics(label: messages.refresh)
AndroidcontentDescription = messages.refresh
iOSaccessibilityLabel = messages.refresh

This ensures screen readers announce localized labels, not raw glyphs (⟳ → "刷新" / "Refresh").

Adding a New Language ​

  1. Web: Call setLocaleMessages('xx-XX', { ... }) with all 15 keys
  2. Flutter: Create a LocaleMessages subclass
  3. Android: Extend LocaleMessages in Kotlin
  4. iOS: Add a new Locale enum case with messages

Testing ​

Verify i18n in your integration:

  1. Switch browser language to the target locale
  2. Check all 15 keys appear in the UI (slider, click, popup, errors)
  3. Test screen readers (VoiceOver / TalkBack) with the new locale
  4. Verify RTL layout if adding an RTL language

Released under the MIT License.