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

localized() returns resource id instead of its value

Open 5hahryar opened this issue 3 years ago • 5 comments

Hey, I'm having some trouble reading string resources in swift. The problem is that .localized() returns the resource id and not the value. what seems to be the main issue here?

// Code below shows "send_message" which is the resource id and not its value
Text(MR.strings().send_message.desc().localized())

Below are my gradle files:

// build.gradle (shared module)
plugins {
    ...
    kotlin("native.cocoapods")
    id("dev.icerock.mobile.multiplatform-resources")
}
multiplatformResources {
    multiplatformResourcesPackage = "com.shahryar.shared"
}

kotlin {
    ios()
    iosSimulatorArm64()
    android()
    
    targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).all {
        binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework::class.java).all {
            export("dev.icerock.moko:resources:0.20.1")
        }
    }

    cocoapods {
        ...
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                ...
                api("dev.icerock.moko:resources:0.20.1")
                api("dev.icerock.moko:parcelize:0.4.0")
                api("dev.icerock.moko:graphics:0.4.0")
            }
        }
       
        val androidMain by getting {
            dependencies {
                ...
                api("dev.icerock.moko:resources-compose:0.20.1")
            }
        }

        val iosSimulatorArm64Main by getting
        val iosMain by getting {
            dependsOn(commonMain)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                // Other dependencies
            }
        }
        ...
    }
    ...
// build.gradle (root project)

buildscript {
    ext.gradlePluginVersion = '3.4.0'

    repositories {
        maven { url 'https://jitpack.io' }
        google()
        mavenCentral()
        jcenter()
        gradlePluginPortal()
    }

    dependencies {
        ...
        classpath "dev.icerock.moko:resources-generator:0.20.1"
    }
}
// Added build phase script in Xcode

"$SRCROOT/../gradlew" -p "$SRCROOT/../" :shared:copyFrameworkResourcesToApp \
    -Pmoko.resources.PLATFORM_NAME=$PLATFORM_NAME \
    -Pmoko.resources.CONFIGURATION=$CONFIGURATION \
    -Pmoko.resources.BUILT_PRODUCTS_DIR=$BUILT_PRODUCTS_DIR \
    -Pmoko.resources.CONTENTS_FOLDER_PATH=$CONTENTS_FOLDER_PATH\
    -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
    -Pkotlin.native.cocoapods.archs="$ARCHS" \
    -Pkotlin.native.cocoapods.configuration=$CONFIGURATION 

5hahryar avatar Jul 09 '22 10:07 5hahryar

ios by default returns key instead text if can't find this key in localization files. maybe build phase with copyFrameworkResourcesToApp is invalid, maybe this key not have value for your localization, maybe you not setup localizations in xcode project as described in readme

Alex009 avatar Jul 10 '22 16:07 Alex009

Still no luck, I will try to add moko resources to a new project and see where it goes.

5hahryar avatar Jul 11 '22 16:07 5hahryar

@5hahryar Have you managed to deal with the issue?

arowierzbowskispoton avatar Feb 03 '23 11:02 arowierzbowskispoton

I've encountered this problem working on a multiplatform iOS/Android app. The shared/common module contains the strings and virtually all of the presentation logic (choosing which StringDesc passes to the UI). Both apps consume the same value. The Android app displays the correct string resource content, but the iOS app displays the raw string resource ID.

In this case, I had added some new strings to the project. The contents of the strings were pretty simple, just words and some spaces. The string names were all lowercase words separated by underscores. Nothing out of the ordinary for our project.

I was able to work around the problem by deleting the iOS derived data folder contents and rebuilding the app. rm -rf /Users/$USER/Library/Developer/Xcode/DerivedData/*

carltonwhitehead avatar Mar 28 '23 19:03 carltonwhitehead

rm -rf /Users/$USER/Library/Developer/Xcode/DerivedData/*

Above work around didnt work for me

JagadishaIncture avatar Feb 29 '24 13:02 JagadishaIncture