问题描述
我正在开发一个具有动态功能模块的模块化项目。
项目结构如下:
应用模块
FeatureModule -> 包含功能说 Feature1
LibraryModule -> 包含包含 BaseActivity 的 baseModule 和包含 En、Fr 和 DE 语言字符串的 UI 模块。
当应用程序在应用程序模块中启动时,我收到语言作为输入,基于该语言应该为整个应用程序设置语言
。我遵循以下方法:
当我在 Appmodule 中收到语言时,我已经为 baseModule 提供了该语言。
基本模块包含 BaseActivity ,我在其中添加了以下代码:
abstract class BaseActivity : AppCompatActivity() {
override fun attachBaseContext(newBase: Context) {
colruyt.android.util.logging.Log.writeInfo("$LOG_TAG attachBaseContext ${userProfileLanguage}")
val localetoSwitchTo = Locale(userProfileLanguage)
val localeUpdatedContext: Contextwrapper = ContextUtils.updateLocale(newBase,localetoSwitchTo)
super.attachBaseContext(localeUpdatedContext)
}
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
if (overrideConfiguration != null) {
val uiMode = overrideConfiguration.uiMode
overrideConfiguration.setTo(baseContext.resources.configuration)
overrideConfiguration.uiMode = uiMode
}
super.applyOverrideConfiguration(overrideConfiguration)
}}
功能模块中存在的活动扩展了 BaseActivity :
我观察到当收到的语言是 "fr" 时,应用程序仍然只显示与字符串相关的默认语言环境,只有英语。
我已经从应用程序包生成了通用 apk,当语言改变时,功能模块不会从该语言的相应 Strings.xml 中获取字符串。
需要有关此问题的宝贵帮助;
提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)