LanguagesHelper

The LanguagesHelper is a helper class to perform operations related to language packs.

Notes:

  • Unless otherwise stated, methods in this class require the KeyboardService to be the current active keyboard. Performing operations related to languages without the keyboard started will fail silently, return null or invoke a callback with a null value.

Functions

StoredLocales

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>

ChangeLanguage

Requests to change the current language to the provided one.

fun changeLanguage(language: KeyboardLanguage)

UpdateLanguageLayout

Requests to change the layout of a language present in the userLanguages field of the LanguageConfiguration.

fun updateLanguageLayout(language: KeyboardLanguage)

DownloadLanguage

Requests to start downloading a language. Use a DownloadListener to get updates in the progress and completion

fun downloadLanguage(language: String, listener: DownloadListener)

AvailableLanguages

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
)

AvailableResources

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
)

LanguageResourceDetails

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)
)

DeleteLanguage

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?

AddLanguage

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)

Enums

LanguageResourceType

DICTIONARY A language resource file for a dictionary
HIGHLIGHTS A language resource file for highlights

Data classes

KeyboardLanguage

A class that represents the combination of language locale and an optional keyboard layout.

Notes:

  • When the layout is null, the default layout for the given locale is used.
data class KeyboardLanguage(val locale: String, val layout: String? = null)

LanguageResourceFiles

The resource files defined in the remote repository for a given language.

data class LanguageResourceFiles(
    val language: String,
    val files: Map<LanguageResourceType?, LanguageExternalResource>
)

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?
)

LanguageResource

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
)

LanguageResource.Highlights

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
)

Last updated on September 9, 2022