Skip to content

SupportedLocales API

Adam Ormsby edited this page Jul 3, 2024 · 1 revision

Public Functions

get tags

// @returns List of language tags configured in your project
public fun getTags(): List<String>

/*
listOf(
  "ar-XB",
  "en",
  "en-XA"
)
*/

get endonyms

// @returns Map of language tags and their written endoynms
public fun getEndonyms(): Map<String, String>

/*
mapOf(
  "ar-XB" to "العربية (لكنات تجريبية ثنائية الاتجاه)",
  "en" to "English",
  "en-XA" to "English (Pseudo-Accents)"
)
*/

get exonyms

// @param languageTag a Unicode-formatted language tag in [String] form such as "en-US"
// @returns Map of language tags and their written exoynms according to the resolved languageTag
public fun getExonyms(): Map<String, String>

/*
param "en-US"
mapOf(
  "ar-XB" to "Arabic (Pseudo-Bidi)",
  "en" to "English",
  "en-XA" to "English (Pseudo-Accents)"
)
*/
// @param a Java [Locale] object.
// @returns Map of language tags and their written exoynms according to the resolved languageTag
public fun getExonyms(): Map<String, String>

// overloaded to support preferred input

Usage

// injection use case
class YourNeatClass(
  private val supportedLocales: SupportedLocales
) {

  fun yourNeatFunc() {
    val localeList = supportedLocales.getTags()
    // do something with your new list
  }
}
Clone this wiki locally