Updated on 2026-08-14
This commit is contained in:
parent
b004f8df6b
commit
1964b3cfad
22 changed files with 204 additions and 173 deletions
|
|
@ -13,7 +13,7 @@ object SupportedLanguages {
|
|||
const val CHINESE = "zh"
|
||||
const val SPANISH = "es"
|
||||
|
||||
val supportedLangugeCodes = listOf(
|
||||
val supportedLanguageCodes = listOf(
|
||||
ENGLISH,
|
||||
RUSSIAN,
|
||||
GERMAN,
|
||||
|
|
@ -25,10 +25,17 @@ object SupportedLanguages {
|
|||
SPANISH,
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns the ISO 639-1 code of the device's current language when it belongs to
|
||||
* [supportedLanguageCodes], otherwise falls back to [ENGLISH].
|
||||
*
|
||||
* Intended for callers that need a plain two-letter language code (e.g. URL path segments
|
||||
* like `tangem.com/{en|ru}/...`).
|
||||
*/
|
||||
fun getCurrentSupportedLanguageCode(): String {
|
||||
val locale = Locale.getDefault()
|
||||
|
||||
return if (supportedLangugeCodes.contains(locale.language)) {
|
||||
return if (supportedLanguageCodes.contains(locale.language)) {
|
||||
locale.language
|
||||
} else {
|
||||
ENGLISH
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
package com.tangem.utils
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
@Deprecated("Use TangemBlogUrlBuilder from common module")
|
||||
object TangemBlogUrlBuilder {
|
||||
|
||||
private const val RU_LOCALE = "ru"
|
||||
private const val EN_LOCALE = "en"
|
||||
|
||||
private const val TANGEM_MAIN = "https://tangem.com/"
|
||||
|
||||
val FEE_BLOG_LINK: String
|
||||
get(): String {
|
||||
val locale = if (Locale.getDefault().language == RU_LOCALE) RU_LOCALE else EN_LOCALE
|
||||
return buildString {
|
||||
append(TANGEM_MAIN)
|
||||
append(locale)
|
||||
append("/blog/post/what-is-a-transaction-fee-and-why-do-we-need-it/")
|
||||
}
|
||||
}
|
||||
|
||||
const val RESOURCE_TO_LEARN_ABOUT_APPROVING_IN_SWAP = "https://tangem.com/en/blog/post/give-revoke-permission/"
|
||||
|
||||
const val YIELD_SUPPLY_HOW_IT_WORKS_URL = "https://tangem.com/en/blog/post/yield-mode"
|
||||
const val YIELD_SUPPLY_TOS_URL = "https://aave.com/terms-of-service"
|
||||
const val YIELD_SUPPLY_PRIVACY_URL = "https://aave.com/privacy-policy"
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package com.tangem.utils
|
||||
|
||||
import com.google.common.truth.Truth
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.util.Locale
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class SupportedLanguagesTest {
|
||||
|
||||
private lateinit var originalLocale: Locale
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
originalLocale = Locale.getDefault()
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun tearDown() {
|
||||
Locale.setDefault(originalLocale)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getCurrentSupportedLanguageCode returns primary language when locale is supported`() {
|
||||
// Arrange
|
||||
Locale.setDefault(Locale("en", "US"))
|
||||
|
||||
// Act
|
||||
val actual = SupportedLanguages.getCurrentSupportedLanguageCode()
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEqualTo("en")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getCurrentSupportedLanguageCode drops region for supported language`() {
|
||||
// Arrange
|
||||
Locale.setDefault(Locale("zh", "CN"))
|
||||
|
||||
// Act
|
||||
val actual = SupportedLanguages.getCurrentSupportedLanguageCode()
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEqualTo("zh")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getCurrentSupportedLanguageCode returns ENGLISH when locale is not supported`() {
|
||||
// Arrange — pt (Portuguese) is not in supportedLanguageCodes
|
||||
Locale.setDefault(Locale("pt", "BR"))
|
||||
|
||||
// Act
|
||||
val actual = SupportedLanguages.getCurrentSupportedLanguageCode()
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEqualTo(SupportedLanguages.ENGLISH)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getCurrentSupportedLanguageCode returns ENGLISH for empty language`() {
|
||||
// Arrange
|
||||
Locale.setDefault(Locale("", ""))
|
||||
|
||||
// Act
|
||||
val actual = SupportedLanguages.getCurrentSupportedLanguageCode()
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEqualTo(SupportedLanguages.ENGLISH)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getCurrentSupportedLanguageCode supports every code in supportedLanguageCodes`() {
|
||||
SupportedLanguages.supportedLanguageCodes.forEach { code ->
|
||||
// Arrange
|
||||
Locale.setDefault(Locale(code))
|
||||
|
||||
// Act
|
||||
val actual = SupportedLanguages.getCurrentSupportedLanguageCode()
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEqualTo(code)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `supportedLanguageCodes contains the expected nine ISO 639-1 codes`() {
|
||||
// Assert
|
||||
Truth.assertThat(SupportedLanguages.supportedLanguageCodes)
|
||||
.containsExactly("en", "ru", "de", "fr", "it", "ja", "uk", "zh", "es")
|
||||
.inOrder()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue