moko-resources
moko-resources copied to clipboard
localized() returns resource id instead of its value
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
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
Still no luck, I will try to add moko resources to a new project and see where it goes.
@5hahryar Have you managed to deal with the issue?
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/*
rm -rf /Users/$USER/Library/Developer/Xcode/DerivedData/*
Above work around didnt work for me