commandiron
commandiron

Reputation: 1473

What is the proper way to change Language string resource in Jetpack Compose?

I have Strings object like;

object Strings {
   object English {
      cons val EXAMPLE = "example"
   }
   object German {
      cons val EXAMPLE = "beispiel"
   }
}

This is how I call strings on screens;

Text(text = Strings.English.EXAMPLE)

How can i change language? Should i call strings from viewmodel or something else?

I dont want to use xml.

Upvotes: 0

Views: 292

Answers (1)

Nikola Despotoski
Nikola Despotoski

Reputation: 50588

(Traditional) Android Resource System should be your go-to approach for internationalization and it's totally valid to use in Jetpack Compose.

Your approach is inefficient and doesn't scale. You should do extremely tedious manual work to check for locales and what not.

Upvotes: 1

Related Questions