Thread
#moko
    sendoav

    sendoav

    2 years ago
    Hi all, I’ve started integrating Moko Resources in our mpp project and just wanted to know if there is any way to access a particular string providing its key. Imagine we declare the string action_go=“GO” in the strings.xml, we would like to access the resource providing the key “action_go”
    alex009

    alex009

    2 years ago
    now all access to strings only by property in
    MR
    class. what usecase can't be implemented with this way?
    sendoav

    sendoav

    2 years ago
    I have a bunch of strings with keys login_error_1, login_error_2, login_error_3. Depending on the type of error we show a different message. I just wonder if it was possible to access the string using “login_error_“+errorId
    alex009

    alex009

    2 years ago
    on android side resource can't be accessed by string key. android generate own R class with all strings and require to pass int resourceId for getting string. so string key in common code API can't be done. to support android & ios you can use function like:
    fun MR.strings.getLoginError(errorId: Int): StringResource = when(errorId) {
        1 -> login_error_1
        2 -> login_error_2
        else throw IllegalArgumentException("unknown $errorId")
    }
    sendoav

    sendoav

    2 years ago
    ok ok I’ll try that 🙂