简体   繁体   English

支持不同语言的Android模块(无应用上下文)

[英]Android module supporting different languages (without application context)

I was trying to develop an android module with support for different languages.我试图开发一个支持不同语言的 android 模块。 I can create a strings .xml file but without appropriate context i cannot access it.我可以创建一个字符串 .xml 文件,但没有适当的上下文我无法访问它。 For the sake of simplicity and to hold on to clean architectural concepts i don't want to receive any context parameters( some parts are meant to live longer than usual ).为了简单起见并坚持干净的架构概念,我不想接收任何上下文参数(某些部分的寿命比平时更长)。 I have also tried using Kotlin data structures for the purpose, but they doesn't look like a good practice.为此,我也尝试过使用 Kotlin 数据结构,但它们看起来并不是一个好的做法。

so, Is there any recommended way of doing this?那么,有没有推荐的方法来做到这一点? or Is there anything that con be done to have asset or resource files accessible from independent modules without any application context ?或者有什么办法可以让资产或资源文件从没有任何应用程序上下文的独立模块访问?

If you want to access resource files, you have to use context.如果要访问资源文件,则必须使用上下文。 Or you can use static variables if you are determined not to use context, which is not a preferred way.或者,如果您决定不使用上下文,则可以使用静态变量,这不是首选方式。 You can pass resources as a param which can be provided by creating statically or by dependency injection.您可以将资源作为参数传递,可以通过静态创建或依赖注入来提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM