SuperAPI AI 工具集

cometchat-i18n

前端与建站

查看项目

更新于 10-15 16:16

技能介绍

用途:为 CometChat UI Kit 各端套件接入本地化,使界面按用户语言显示。各套件内置英语及约 15 种语言(阿拉伯语、孟加拉语、中文、德语、西班牙语、法语、印地语、印尼语、意大利语、日语、韩语、马来语、葡萄牙语、俄语、瑞典语、土耳其语,具体集合随版本变化),并支持运行时添加自定义语言。

主要能力与用法:各端 API 不同。React v6 与 Angular v5 使用对象签名 CometChatLocalize.init({ language, fallbackLanguage });React Native v5 不使用 CometChatLocalize.init,而是用 <CometChatI18nProvider> 组件配合 useCometChatTranslation 钩子;Android V5/V6 使用 CometChatLocalize.setLocale(context, "es"),参数为 Context 加语言代码字符串;iOS V5 使用 CometChatLocalize.set(locale: "es");Flutter V5/V6 没有 CometChatLocalize 类,需在 MaterialApp 注册套件的 Translations 本地化委托,并通过 Locale 驱动语言,用 Translations.of(context) 读取文案。

自定义与覆盖:React/RN/Angular 可通过 translationsForLanguage、translations 属性或 addTranslation 覆盖字符串;Android 与 iOS 无字符串覆盖 API,需用原生资源文件(values-es/strings.xml、Localizable.strings)覆盖;Flutter 通过继承 Translations 委托实现。

RTL 与回退:阿拉伯语、希伯来语、波斯语、乌尔都语为从右到左。Web 需设置 <html dir="rtl">;React Native 需 I18nManager.forceRTL(true) 且重启应用生效;Flutter 自动处理。缺失翻译时各套件回退到英语,Web/RN/Angular 可显式设置 fallbackLanguage。

限制:各端 API 差异大,使用前应核对已安装包的类型定义;Android/iOS 不支持直接覆盖字符串;Flutter 不存在 CometChatLocalize.init 符号。语言切换时重新调用 init/setLocale 即可,无需重新登录。