Android IMKit 多语言

IMKit 的多语言分为两部分:可翻译文案(键值资源)与格式化结果(时间分割、未读角标、已读人数、发送状态)。IDL 只约束组件行为,本页给出跨端一致的键名约定与格式化函数映射。

键名约定

IDL 不定义 i18n 资源;为保证多端一致,建议统一使用 imkit.<component>.<key> 命名,并以内置 zh-CN / en-US 为基线。

资源键约定​

键(建议)中文基线说明
conversationList.empty暂无会话可由宿主资源覆盖
conversationList.loading加载中可由宿主资源覆盖
chatView.inputPlaceholder输入消息可由宿主资源覆盖
chatView.noMore没有更多消息可由宿主资源覆盖
chatView.recalled消息已撤回可由宿主资源覆盖
messageStatus.sending发送中可由宿主资源覆盖
messageStatus.sent已发送可由宿主资源覆盖
messageStatus.delivered已送达可由宿主资源覆盖
messageStatus.read已读可由宿主资源覆盖
messageStatus.failed发送失败可由宿主资源覆盖
common.retry重试可由宿主资源覆盖
common.cancel取消可由宿主资源覆盖
common.confirm确定可由宿主资源覆盖

格式化函数(跨端一致)​

能力WebFlutterAndroidNative规则
时间分割formatTime(timestamp, now, locale)TimeSeparator.formatTime(ts, nowMs:)IMKitTimeFormatter.format(context, ts, now)im_kit_format_time(ts, now, out, len)当天 HH:mm;昨天;7 天内周X;更早日期
未读角标unreadBadgeText(count)UnreadBadge.formatCount(count)UnreadBadgeFormatter.format(unread, mention)im_kit_unread_badge_text(count, out, len)0 隐藏;>99 显示 99+;免打扰灰点
已读文案messageStatusText(...)MessageStatusIndicator.readText(...)ReadCountFormatter.format(read, total)im_kit_message_status_text(json, read, total, out, len)单聊 已读/未读;群聊 n/m
发送状态messageStatusText(status)MessageStatusIndicator 状态常量SendState 枚举im_kit_message_status_text(...)发送中 / 已发送 / 已送达 / 已读 / 失败

按端接入​

平台locale 入口资源覆盖
Androidres/values/strings.xml / values-en/XML 资源覆盖;IMKitTimeFormatter 可注入
WebIMKit.setup({ locale: "en-US" })文案键可通过宿主 i18n 框架注入;格式化函数支持 locale 参数
Electron宿主 React i18n(如 i18next)组件 props 传入已翻译文案 / 格式化后的时间
FlutterMaterialApp(locale: ...) + localizationsDelegates使用 Flutter 本地化体系;格式化函数提供静态方法
Nativeim_kit_set_utc_offset_minutes + 宿主资源C ABI 输出格式化后的文案,翻译由宿主完成
iOSIMPTimeSeparator.formattedText() / NSLocalizedStringBundle 本地化资源,随系统区域
HarmonyOSTimeSeparator.formattedText(),见 HarmonyOS 分区ArkUI 资源

格式化示例​

Kotlin
// 时间分隔(context 提供语言与时区)
val label = IMKitTimeFormatter.format(context, timestampMs, nowMs)
// 未读角标:0 隐藏,>99 显示 99+
val badge = UnreadBadgeFormatter.format(128, 2)   // "99+" / "@"
// 已读文案:单聊 已读/未读;群聊 n/m
val readText = ReadCountFormatter.format(8, 12)

提示:时间格式化函数均支持注入 now / now_ms,便于单元测试与固定时区。

相关文档​