I’m trying to get the resource string from viewmodels and use cases, i have six string translate resources files but i always got the default string translations, isn’t getting the established culture
My interface
interface ResourceController {
fun getString(resourceId: Int): String
}
My implementation
class ResourceControllerImpl @Inject constructor(private val context: Context
) : ResourceController {
override fun getString(resourceId: Int): String {
return context.getString(resourceId)
}
}
My module injection
@InstallIn(SingletonComponent::class)
@Module
object ConfigModule {
@Provides
@Singleton
fun resourceControllerProvider(@ApplicationContext context: Context): ResourceController {
return ResourceControllerImpl(context)
}
}
My useCase
class GetTemplateToPrint @Inject constructor(
private val resourceController: ResourceController,
private val deviceUtils: DeviceUtils
) {
fun invoke(): String {
var dataToPrint : String = ""
val terminal = deviceUtils.getDeviceSerialNumber() ?: deviceUtils.getDeviceId()
dataToPrint = "${getString(R.string.serial_number_label)}:| $terminal"
return dataToPrint
}
private fun getString(resId: Int): String {
return resourceController.getString(resId)
}
}
R.string.serial_number_label exist in six resource string files (es, en, fr, it, de, ca)
but it’s always returning the default resource string
have anyone how can i do it? thanks 🙂