final class LanguagesHelper
Use the static methods in this class to do all language-related operations.
Methods | |
---|---|
Result<[RemoteLanguage], LanguagesHelper.Error> |
fun availableLanguages() Downloads the list of available languages. |
Void |
fun availableLanguages( completion: @escaping (Result<[RemoteLanguage], LanguagesHelper.Error>) Downloads the list of available languages. |
AsyncStream<DownloadStatus<Result<Void, LanguagesHelper.Error>>> |
fun downloadLanguageFile( locale: String, fileURL: URL ) Downloads the file containing the specified language. |
Void |
fun downloadLanguageFile( locale: String, fileURL: URL detailedProgress: ((_ bytesCurrent: Float, _ bytesTotal: Float) -> Void)?, completion: @escaping (_ result: Result<Void, LanguagesHelper.Error>)) Downloads the file containing the specified language. |
LocalLanguage? | fun getMetadataFromLanguage(at fileURL: URL) Creates the language metadata object from the language file at the specified path. |
Enumerations | |
---|---|
Error | The error type used by the methods in LanguagesHelper. |
static func availableLanguages() async -> Result<[RemoteLanguage], LanguagesHelper.Error>
Downloads the list of available languages.
Returns | |
---|---|
Result<[RemoteLanguage], LanguagesHelper.Error> | The result of the download. Contains the array of available languages in case of success. |
static func availableLanguages(completion: @escaping (Result<[RemoteLanguage], LanguagesHelper.Error>) -> Void)
Downloads the list of available languages.
Parameters | |
---|---|
completion: @escaping (Result<[RemoteLanguage] | A closure that gets executed when the download finishes. This closure always gets executed in the main thread. |
static func downloadLanguageFile(locale: String, fileURL: URL) -> AsyncStream<DownloadStatus<Result<Void, LanguagesHelper.Error>>>
Downloads the file containing the specified language.
Parameters | |
---|---|
locale: String | The locale to download. |
fileURL: URL | The URL in which the downloaded file should be stored. |
Returns | |
---|---|
AsyncStream<DownloadStatus<Result<Void, LanguagesHelper.Error>>> | The status of the download. |
static func downloadLanguageFile(locale: String, fileURL: URL, detailedProgress: ((_ bytesCurrent: Float, _ bytesTotal: Float) -> Void)?, completion: @escaping (_ result: Result<Void, LanguagesHelper.Error>) -> Void)
Downloads the file containing the specified language.
Parameters | |
---|---|
locale: String | The locale to download. |
fileURL: URL | The URL in which the downloaded file should be stored. |
detailedProgress: ((_ bytesCurrent: Float, _ bytesTotal: Float) -> Void)? | A closure that executes repeatedly and contains the language download progress. This closure always gets executed in the main thread. |
completion: @escaping (_ result: Result<Void, LanguagesHelper.Error>) | A closure that executes once the download has finished. This closure always gets executed in the main thread. |
static func getMetadataFromLanguageFile(at fileURL: URL) -> LocalLanguage?
Creates the language metadata object from the language file at the specified path.
Parameters | |
---|---|
fileURL: URL | The URL of the language file. |
Returns | |
---|---|
LocalLanguage? | The LanguageResourceMetadata extracted from the local language file. Returns nil if there’s no file at the specified URL or if the file is not a valid language file. |
enum Error
The error type used by the methods in LanguagesHelper.
Enumeration Cases | |
---|---|
downloadError(Swift.Error) |
This error means that something failed when making the download. It includes the associated Error object containing the actual error. |
fileError(Swift.Error) |
This error is returned when there’s an issue when moving a downloaded language file into the specified fileURL. This could happen, for example, if there is an error removing the existing item in the specified fileURL. The associated error contains the actual error raised by the FileManager. |
internalError(Swift.Error) |
This error means that something failed internally in the languages helper when making a download. This could happen, for example, when the downloaded file has an invalid format or when there’s an error when writing files to disk. |
localeNotFound |
This error is returned when trying to download a language that is not available. |
validationError |
This error is returned when the validation of the downloaded language file fails. This could happen when the downloaded file gets corrupted. |