Skip to content

Commit

Permalink
Merge pull request #46 from dreipol/feature/localize
Browse files Browse the repository at this point in the history
Feature/localize
  • Loading branch information
lailabecker authored Apr 15, 2024
2 parents 07286c9 + 0426a50 commit c449368
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ kotlin {
}

sourceSets["iosSimulatorArm64Main"].dependsOn(sourceSets["iosMain"])

// TODO: Remove as soon as Android Studio (Iguana) is fixed
task("testClasses")
}

android {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
systemProp.org.gradle.internal.publish.checksums.insecure=true
# -------dependency versions-------
# shared
versions_kotlin=1.9.22
versions_kotlin=1.9.23
versions_linter=12.1.0
versions_coroutines=1.7.3
datetime_version=0.5.0
Expand Down
17 changes: 13 additions & 4 deletions src/androidMain/kotlin/ch/dreipol/dreimultiplatform/Localize.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ package ch.dreipol.dreimultiplatform
import android.content.Context

fun Context.getString(identifier: String): String {
val resourceId = resources.getIdentifier(identifier, "string", packageName)
val resourceId = stringId(identifier)
return resources.getString(resourceId)
}

private fun Context.stringId(identifier: String): Int {
return resources.getIdentifier(identifier, "string", packageName)
}

fun Context.getString(identifier: String, vararg args: Any): String {
val stringId = stringId(identifier)
return resources.getString(stringId, *args)
}

class Localizer(private val context: Context) : Localize {
override fun localize(string: String): String {
return context.getString(string)
}
override fun localize(string: String): String = context.getString(string)

override fun localize(string: String, vararg args: Any): String = context.getString(string, *args)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package ch.dreipol.dreimultiplatform

interface Localize {
fun localize(string: String): String
fun localize(string: String, vararg args: Any): String

}

0 comments on commit c449368

Please sign in to comment.