The LanguagesHelper is a helper class to perform operations related to language packs.
Notes:
Returns a list of stored locales in the device storage without additional information from the engine. This method can be called without an active keyboard service.
fun storedLocales(context: Context) : Set<String>
Requests to change the current language to the provided one.
fun changeLanguage(language: KeyboardLanguage)
Requests to change the layout of a language present in the userLanguages field of the LanguageConfiguration.
fun updateLanguageLayout(language: KeyboardLanguage)
Requests to start downloading a language. Use a DownloadListener to get updates in the progress and completion
fun downloadLanguage(language: String, listener: DownloadListener)
Requests to start downloading the available languages from the remote repository. Use the callback to get notified when the operation completes and obtain the results.
When the operation fails, the callback is invoked with a null value.
fun availableLanguages(
onLanguagesLoaded: (Map<String, LanguageResourceFiles>?) -> Unit
)
Requests a map of the available resources in the device storage. Use the optional callback to get notified when the operation completes and obtain the results.
When the operation fails, the callback is invoked with a null value.
fun availableResources(
callback: ((Map<String, LanguageResource>?) -> Unit)? = null
)
Requests the details of an individual locale in the device storage. Use the callback to get notified when the operation completes and obtain the result.
When the operation fails, the callback is invoked with a null value.
fun languageResourceDetails(
languageCode: String,
callback: ((LanguageResource?) -> Unit)
)
Requests to delete the language files from the device storage for the given locale.
On success, returns the locale of the current language. On failure, returns null.
The operation to delete a language can fail for the following reasons:
fun deleteLanguage(language: String) : String?
Convenience method to add a language after it has been downloaded. Requests to add the provided KeyboardLanguage to the current configuration’s userLanguages and switches to the new added language.
fun addLanguage(keyboardLanguage: KeyboardLanguage)
DICTIONARY | A language resource file for a dictionary |
HIGHLIGHTS | A language resource file for highlights |
A class that represents the combination of language locale and an optional keyboard layout.
Notes:
data class KeyboardLanguage(val locale: String, val layout: String? = null)
The resource files defined in the remote repository for a given language.
data class LanguageResourceFiles(
val language: String,
val files: Map<LanguageResourceType?, LanguageExternalResource>
)
The details of a language resource file from a remote repository.
data class LanguageExternalResource(
val language: String,
val name: String?,
val version: Float = 0f,
val key: String,
val type: LanguageResourceType?,
val url: String?,
val size: Long = 0,
val lastModified: String?
)
The details of a language stored in the device after obtaining detailed information about the language pack, like available layouts or the default layout.
data class LanguageResource(
val locale: String,
val version: Float,
val layouts: List<String>,
val defaultLayout: String,
val path: String,
val isAsset: Boolean,
val highlights: Highlights? = null
)
The details of a language highlight file stored in the device after obtaining detailed information about its contents.
data class Highlights(
val locale: String,
val version: String,
val path: String,
val isAsset: Boolean,
val hasBeenParsed: Boolean = false,
val isValid: Boolean = false,
val keywordContent: Boolean = false,
val onPopContent: Boolean = false,
val timestamp: String? = null
)