moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Access translated string by key

Open Syer10 opened this issue 2 years ago • 5 comments

Similar to https://github.com/icerockdev/moko-resources/issues/218, I feel it would be good to have a way to dynamically access strings by string key. I need this for my application due to some dynamically loaded strings, and I cannot use a giant when statement to get the translated value.

Currently what I have done to move around this issue is by using reflection to get the MR.stringsBundle key, and directly using that to get the resource bundle for that specific locale, and then using the string key to get the translated string.

An example api that may work

fun ResourceContainer<StringResource>.getStringByKey(key: String): StringResource? {
    // get StringResource by key
}

Syer10 avatar May 19 '23 17:05 Syer10

This would be nice and would facilitate the use of moko-resources on the server.

ScottPierce avatar May 19 '23 18:05 ScottPierce

@Syer10 did you manage to use reflection in the common code? I made it work for android but sadly I can not do it for iOS. Anyway, hoping to see it soon in the library.

enoler avatar Aug 29 '23 08:08 enoler

Kindly inform us of any developments related to this matter. Implementing this feature would greatly enhance our multiplatform project, enabling the seamless transmission of string resources from the server to client platforms.

pitampoudel avatar Nov 17 '23 11:11 pitampoudel

I agree, that would be great. We also have the use case where the server sends the translation key and we need to select the translation at runtime

rs-georg avatar Dec 06 '23 10:12 rs-georg

Hello Team, Can you please share what's going on?

pitampoudel avatar Feb 21 '24 10:02 pitampoudel