Internationalization (i18n)
captcha-pro provides bilingual support (Chinese/English) for all platforms, with automatic browser language detection on web.
Supported Languages
| Language | Code | Default |
|---|---|---|
| 简体中文 | zh-CN | ✅ Yes |
| English | en-US | No |
Message Keys
captcha-pro uses a 15-key message set shared across all platforms (Web, mini-programs, Flutter, Android, iOS):
| Key | Chinese (zh-CN) | English (en-US) | Context |
|---|---|---|---|
loading | 加载中... | Loading... | Loading state |
slider_slide | 请拖动滑块完成验证 | Please slide to verify | Slider prompt |
slider_hint | → 按住滑块,拖动完成验证 | → Hold and drag the slider to verify | Slider hint |
slider_success | 验证成功 | Verification successful | Slider success |
slider_fail | 验证失败 | Verification failed | Slider failure |
click_prompt | 请依次点击: | Please click in order: | Click prompt |
click_success | 验证成功 | Verification successful | Click success |
click_fail | 验证失败 | Verification failed | Click failure |
popup_title | 请完成安全验证 | Please complete security verification | Popup title |
popup_close | 关闭 | Close | Popup close button |
refresh | 刷新 | Refresh | Refresh button (a11y) |
error_network | 网络错误 | Network error | Network error |
error_expired | 验证码已过期 | Captcha expired | Captcha expired |
error_invalid | 验证失败 | Verification failed | Invalid verification |
error_not_found | 验证码不存在 | Captcha not found | Captcha not found |
Platform Usage
Web (Vanilla JS / Vue / React)
The web platform automatically detects browser language via navigator.language:
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
<!-- WXML -->
<captcha-slider locale="{{locale}}" bind:success="onSuccess" />// JS
Page({
data: {
locale: 'en-US' // Force English
}
})Taro / uni-app
<template>
<SliderCaptcha :locale="locale" @success="onSuccess" />
</template>
<script setup>
import { ref } from 'vue'
const locale = ref('en-US')
</script>Flutter
import 'package:captcha_pro/captcha_pro.dart';
SliderCaptcha(
locale: LocaleMessages.enUS, // Force English
onSuccess: () => print('Passed!'),
)Android (Kotlin)
import com.captcha.pro.sdk.SliderCaptchaView
val captcha = SliderCaptchaView(context).apply {
setLocale("en-US") // Force English
}iOS (Swift)
import CaptchaPro
let captcha = SliderCaptchaView(frame: .zero)
captcha.locale = .enUS // Force EnglishCustomizing Messages
Web Platform
Override messages globally:
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:
Directionalitywidget - 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:
| Platform | Implementation |
|---|---|
| Web | aria-label={messages.refresh} |
| Flutter | Semantics(label: messages.refresh) |
| Android | contentDescription = messages.refresh |
| iOS | accessibilityLabel = messages.refresh |
This ensures screen readers announce localized labels, not raw glyphs (⟳ → "刷新" / "Refresh").
Adding a New Language
- Web: Call
setLocaleMessages('xx-XX', { ... })with all 15 keys - Flutter: Create a
LocaleMessagessubclass - Android: Extend
LocaleMessagesin Kotlin - iOS: Add a new
Localeenum case with messages
Testing
Verify i18n in your integration:
- Switch browser language to the target locale
- Check all 15 keys appear in the UI (slider, click, popup, errors)
- Test screen readers (VoiceOver / TalkBack) with the new locale
- Verify RTL layout if adding an RTL language
Related
- Accessibility Guide - WCAG 2.2 conformance
- API Reference -
localeoption details