comahe-de / i18n4k

Internationalization for Kotlin
Apache License 2.0
77 stars 9 forks source link

Get a translation through an identifier #26

Closed orelvis15 closed 1 year ago

orelvis15 commented 1 year ago

Hello, good afternoon.

I am using the lib to manage the translations of a desktop app but I need to get the translations through an identifier sent from the backend, is it possible?.

For example, the backend sends ID_SMS and has a method like MYMESSAGE.fromKey("ID_SMS") and returns me the translation.

comahe-de commented 1 year ago

@orelvis15 Now you may also have a look at the branch "messages_keys". Install the version "0.6.0-SNAPSHOT" locally via the Gradle task "publishToMavenLocal"

In this version you can get the key via the messageKey property, e.g. MyMessages.sayHello.messageKey, And the corresponding message object by MyMessages.getEntryByKey("sayHello").

Some unit tests are still missing for this. But I think I can publish a new version during the next two weeks. I will also update to the new Kotlin version.

orelvis15 commented 1 year ago

@comahe-de Perfect! I'm going to use it today! Thank you very much for this new feature, I'll let you know how it went as soon as I try it. greetings!.

orelvis15 commented 1 year ago

@comahe-de I am testing the version "0.6.0-SNAPSHOT", it is just giving me an error in the generation of the code.

The integer literal does not conform to the expected type String

It seems that the getLocalizedString0(0) method now needs another String parameter getLocalizedString0("key", 0)

comahe-de commented 1 year ago

@orelvis15 Yes, I have forgot to say, that you need to add the local Maven repository to the plugin repository list in settings.gradle.kts, so that the local build plugin is used. See here: https://github.com/comahe-de/i18n4k/blob/messages_keys/examples/example-mpp/settings.gradle.kts#L5. Don't forget also to use the "0.6.0-SNAPSHOT" version of the plugin.

Than call the Gradle task clearI18n4kFiles and than generateI18n4kFiles

comahe-de commented 1 year ago

v0.6.0 is published