Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ class MessagingTopicDataSource(
)
}

/**
* Note: Indonesian language code is normalized from "in" to "id" to maintain
* consistency with backend batch messaging server which uses ISO 639-1 standard.
* Supports both "in" and "id" as input for Indonesian language.
*/
private fun getBaseLanguageCode(languageCode: String): String {
val normalizedLanguageCode = languageCode.split("_", "-").first().lowercase()

// Handle reverse mapping: if "id" is passed, treat it as Indonesian
val searchCode = when (normalizedLanguageCode) {
"id" -> "in"
else -> normalizedLanguageCode
}

val targetLanguage = supportedLanguages.find {
it.code.split("-").first().lowercase() == normalizedLanguageCode
it.code.split("-").first().lowercase() == searchCode
} ?: defaultLanguage

return targetLanguage.code.split("-").first().lowercase()
val baseCode = targetLanguage.code.split("-").first().lowercase()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰


return when (baseCode) {
"in" -> "id"
else -> baseCode
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.brainwallet.data.source

import com.brainwallet.data.model.Language
import org.junit.Before
import org.junit.Test

Expand Down Expand Up @@ -72,12 +71,45 @@ class MessagingTopicDataSourceTest {
}
}

@Test
fun `given Indonesian language code when getTopicsByLanguageCode called then it should normalize to id for backend consistency`() {
val result = dataSource.getTopicsByLanguageCode("in")

val expectedTopics = listOf("initial_id", "news_id", "promo_id", "warn_id")
assert(result == expectedTopics) {
"Expected Indonesian language code 'in' to be normalized to 'id' for backend consistency but got $result"
}
}

@Test
fun `given Indonesian locale with region when getTopicsByLanguageCode called then it should normalize to id`() {
val result = dataSource.getTopicsByLanguageCode("in_ID")

val expectedTopics = listOf("initial_id", "news_id", "promo_id", "warn_id")
assert(result == expectedTopics) {
"Expected Indonesian locale 'in_ID' to be normalized to 'id' for backend consistency but got $result"
}
}

@Test
fun `given id language code when getTopicsByLanguageCode called then it should be recognized as Indonesian`() {
val result = dataSource.getTopicsByLanguageCode("id")

val expectedTopics = listOf("initial_id", "news_id", "promo_id", "warn_id")
assert(result == expectedTopics) {
"Expected 'id' language code to be recognized as Indonesian and return Indonesian topics but got $result"
}
}

@Test
fun `given all supported languages when getTopicsByLanguageCode called then it should return correct base language topics`() {
val testCases = mapOf(
"en" to "en",
"es" to "es",
"in" to "in",
"es" to "es",
// Check All possible indonesian combination
"in" to "id",
"in_ID" to "id",
"id" to "id",
"ar" to "ar",
"uk" to "uk",
"ru" to "ru",
Expand Down