-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow searching locale by name or tag
- Loading branch information
Showing
5 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
core/src/main/kotlin/eu/iamgio/quarkdown/document/locale/JVMLocaleLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
package eu.iamgio.quarkdown.document.locale | ||
|
||
private typealias JLocale = java.util.Locale | ||
|
||
/** | ||
* Loader of [JVMLocale]s. | ||
*/ | ||
internal object JVMLocaleLoader : LocaleLoader { | ||
override val all: Iterable<Locale> | ||
get() = java.util.Locale.getAvailableLocales().map(::JVMLocale) | ||
get() = JLocale.getAvailableLocales().map(::JVMLocale) | ||
|
||
override fun fromTag(tag: String): Locale? = | ||
java.util.Locale.forLanguageTag(tag) | ||
?.let(::JVMLocale) | ||
private fun JLocale?.toLocale() = | ||
this?.let(::JVMLocale) | ||
?.takeIf { it.code.isNotBlank() } | ||
|
||
override fun fromTag(tag: String): Locale? = JLocale.forLanguageTag(tag)?.toLocale() | ||
|
||
override fun fromName(name: String): Locale? = | ||
JLocale.getAvailableLocales() | ||
.find { it.getDisplayName(JLocale.ENGLISH).equals(name, ignoreCase = true) } | ||
?.toLocale() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters