LanguagesHelper

Languages Management

The LanguagesHelper is a helper type to perform operations related to languages. This is a helper, which means you are not required to use it. However, if you want to install more than one language and change between them, this API manages it.

Summary

downloadLanguage Download language in local from our servers.
addLanguage Add the language to the list of languages and select it.
deleteLanguage Removes the language from the list of languages and deletes it from local.
changeLanguage Change between installed languages.
availableLanguages Get all the languages available installed.
availableResources Get all the local resources (meaning languages) that are storedlocally.

DownloadLanguage

 public static func downloadLanguage(_ language: String, onProgress: ((_ bytesCurrent: Float, _ bytesTotal: Float) -> Void)? = nil, onComplete: ((Result<Void, Error>) -> Void)?)

Simply pass the language code you want to download and you’ll be notified of:

  • The download progress via onProgress closure, which gives you the bytes that have been downloaded and the total bytes of the download.
  • The completion of the download via onComplete closure, which gives you the Result of the download.

Once a language is downloaded successfully, it will appear listed in the response of availableResources(_:). However, it won’t be added automatically to the keyboard. For that you need to install the language via addLanguage(_:)

AddLanguage

public static func addLanguage(_ keyboardLanguage: FleksyKeyboardSDK.KeyboardLanguage)

Add a downloaded language to the keyboard by applying this method. It also make the keyboard switch to the added language.

DeleteLanguage

public static func deleteLanguage(_ language: String) -> String?

Pass it the language code to be deleted and it will return a String? containing the code of the current language after the successful deletion. It returns nil if the language could not be deleted. For example, this happens when trying to delete the current language in cases where there are no other languages installed.

ChangeLanguage

public static func changeLanguage(_ keyboardLanguage: FleksyKeyboardSDK.KeyboardLanguage)

This KeyboardLanguage is just a struct wrapping the language code (locale) and the keyboard layout:

public struct KeyboardLanguage {
    public let locale: String
    public let layout: String?
    
    public init(locale: String, layout: String? = nil) {
        self.locale = locale
        self.layout = layout
    }
} 

You can pass nil layout to get the default layout of the language.

AvailableLanguages

public static func availableLanguages(_ onLanguagesLoaded: @escaping ([String : FleksyKeyboardSDK.LanguageResourceFiles]?) -> Void)

This call returns all the languages available in our backend. We keep adding new languages to this list.

In order to load all the available languages simply call this method. An internet connection is required and the languages are returned via callback in the form of dictionary [String : LanguageResourceFiles]. In this dictionary each key is the locale of the corresponding language (e.g. “en-US”).

AvailableResources

public static func availableResources(_ onResourcesLoaded: @escaping ([String : FleksyKeyboardSDK.LanguageResource]?) -> Void)

You can load the language resources that are available locally, i.e. those that have been previously downloaded or are already bundled with the FleksyKeyboardSDK. To do this, use the availableResources(_:) method.

Even though this is an asynchronous call in general, it does not need an internet connection since it only searches for local files. The SDK caches the result of availableResources(_:), which means that subsequent calls to availableResources(_:) are much more lightweight, as it simply returns the cached information.


If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on February 1, 2024