From fab0b79c296eda3165d6c99929addbd780f7fef9 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 6 Jun 2024 14:26:42 +0700 Subject: [PATCH] #118 added ios missing localization tests --- .../desc/AppleLocalizationBundleTests.kt | 47 +++++++++++++++++++ .../PluralFormattedStringDescStringTests.kt | 10 ++++ .../Resources/Base.lproj/Localizable.strings | 2 + .../Resources/es-US.lproj/Localizable.strings | 1 + 4 files changed, 60 insertions(+) create mode 100644 resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/AppleLocalizationBundleTests.kt create mode 100644 resources/src/iosTest/resources/tests.bundle/Contents/Resources/Base.lproj/Localizable.strings create mode 100644 resources/src/iosTest/resources/tests.bundle/Contents/Resources/es-US.lproj/Localizable.strings diff --git a/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/AppleLocalizationBundleTests.kt b/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/AppleLocalizationBundleTests.kt new file mode 100644 index 000000000..b9b0eb509 --- /dev/null +++ b/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/AppleLocalizationBundleTests.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.resources.StringResource +import platform.Foundation.NSBundle +import kotlin.test.Test +import kotlin.test.assertEquals + +class AppleLocalizationBundleTests { + + @Test + fun localizedStringWithLocalizationCaseTest() { + val resource = StringResource( + resourceId = "noResultsFound", + bundle = NSBundle.bundleWithPath(NSBundle.mainBundle.bundlePath + "/tests.bundle")!! + ) + StringDesc.localeType = StringDesc.LocaleType.Custom("es-US") + val stringDesc = ResourceStringDesc( + resource + ) + assertEquals( + expected = "No se han encontrado resultados", + actual = stringDesc.localized() + ) + StringDesc.localeType = StringDesc.LocaleType.System + } + + @Test + fun localizedStringMissingLocalizationCaseTest() { + val resource = StringResource( + resourceId = "noInternetConnection", + bundle = NSBundle.bundleWithPath(NSBundle.mainBundle.bundlePath + "/tests.bundle")!! + ) + StringDesc.localeType = StringDesc.LocaleType.Custom("es-US") + val stringDesc = ResourceStringDesc( + resource + ) + assertEquals( + expected = "No internet connection", + actual = stringDesc.localized() + ) + StringDesc.localeType = StringDesc.LocaleType.System + } +} diff --git a/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDescStringTests.kt b/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDescStringTests.kt index a6a9eb6ea..7326b2b89 100644 --- a/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDescStringTests.kt +++ b/resources/src/iosTest/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDescStringTests.kt @@ -50,6 +50,16 @@ class PluralFormattedStringDescStringTests { ) } + @Test + fun testMissingLocalizationCase() { + StringDesc.localeType = StringDesc.LocaleType.Custom("es-US") + assertEquals( + expected = "6/10 items", + actual = createPluralFormatted(6).localized() + ) + StringDesc.localeType = StringDesc.LocaleType.System + } + private fun createPluralFormatted(number: Int): PluralFormattedStringDesc { val pluralResource = PluralsResource( resourceId = "stringFormatted", diff --git a/resources/src/iosTest/resources/tests.bundle/Contents/Resources/Base.lproj/Localizable.strings b/resources/src/iosTest/resources/tests.bundle/Contents/Resources/Base.lproj/Localizable.strings new file mode 100644 index 000000000..d8a3af0a7 --- /dev/null +++ b/resources/src/iosTest/resources/tests.bundle/Contents/Resources/Base.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"noResultsFound" = "No results found"; +"noInternetConnection" = "No internet connection"; \ No newline at end of file diff --git a/resources/src/iosTest/resources/tests.bundle/Contents/Resources/es-US.lproj/Localizable.strings b/resources/src/iosTest/resources/tests.bundle/Contents/Resources/es-US.lproj/Localizable.strings new file mode 100644 index 000000000..d42e46e4a --- /dev/null +++ b/resources/src/iosTest/resources/tests.bundle/Contents/Resources/es-US.lproj/Localizable.strings @@ -0,0 +1 @@ +"noResultsFound" = "No se han encontrado resultados"; \ No newline at end of file