Skip to content

Commit

Permalink
Reworded languages to locales
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCrossCD committed Nov 14, 2023
1 parent 758a780 commit 03098a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Converters : KoinComponent {
fun stringMapToLanguagesWithText(localesWithText: LocalesWithText): String {
val type = Types.newParameterizedType(Map::class.java, String::class.java, String::class.java)
val adapter: JsonAdapter<Map<String, String>> = moshi.adapter(type)
return adapter.toJson(localesWithText.languagesTextMap)
return adapter.toJson(localesWithText.localesTextMap)
}

@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ private fun LocaleString.toLocale(): Locale {
*/
@Parcelize
data class LocalesWithText(
val languagesTextMap: Map<LocaleString, String>
val localesTextMap: Map<LocaleString, String>
) : Parcelable {

/**
* Gets the string corresponding to the given localeString.
* @param localeString The localeString to match against
* @return The string corresponding to the given localeString.
*/
operator fun get(localeString: LocaleString): String? = languagesTextMap[localeString]
operator fun get(localeString: LocaleString): String? = localesTextMap[localeString]

/**
* Gets the string corresponding to the given locale matched against LocaleString.
* @param locale The locale to match against turned into String
*/
private operator fun get(locale: Locale): String? = languagesTextMap[locale.toString()]
private operator fun get(locale: Locale): String? = localesTextMap[locale.toString()]

/**
* Sets the string corresponding to the given localeString.
Expand All @@ -47,22 +47,22 @@ data class LocalesWithText(
* @return A new LocalesWithText with the given localeString and text added to the map
*/
operator fun set(localeString: LocaleString, text: String): LocalesWithText {
return LocalesWithText(languagesTextMap.toMutableMap().apply {
return LocalesWithText(localesTextMap.toMutableMap().apply {
this[localeString] = text
})
}

/**
* Checks if the contains the given string.
*/
fun containsValue(phraseStr: String): Boolean = languagesTextMap.containsValue(phraseStr)
fun containsValue(phraseStr: String): Boolean = localesTextMap.containsValue(phraseStr)

/**
* Gets a list of all the languages in the map
* @return A list of all the languages in the map, keys.toList()
*/
@IgnoredOnParcel
val languages: List<LocaleString> = languagesTextMap.keys.toList()
val locales: List<LocaleString> = localesTextMap.keys.toList()

/**
* Gets a TextWithLocale that contains the text to be displayed and/or spoken and the
Expand All @@ -86,7 +86,7 @@ data class LocalesWithText(
text = this[it]
}
if (text == null) {
languages.firstOrNull()?.let {
locales.firstOrNull()?.let {
locale = it.toLocale()
text = this[it]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.willowtree.vocable.presets.Category

class FakeLocalizedResourceUtility : ILocalizedResourceUtility {
override fun getTextFromCategory(category: Category?): String {
return category?.localizedName?.languagesTextMap?.entries?.first()?.value ?: ""
return category?.localizedName?.localesTextMap?.entries?.first()?.value ?: ""
}
}

0 comments on commit 03098a2

Please sign in to comment.