TXNative

public final class TXNative : NSObject

A static class that is the main point of entry for all the functionality of Transifex Native throughout the SDK.

  • The filename of the file that holds the translated strings and it’s bundled inside the app.

    Declaration

    Swift

    public static let STRINGS_FILENAME: String
  • The available and current locales

    Declaration

    Swift

    @objc
    public static var locales: TXLocaleState? { get }
  • Designated initializer of the TXNative SDK.

    Do not call initialize() twice without calling dispose() first to deconstruct the previous singleton instance.

    Declaration

    Swift

    @objc
    public static func initialize(
        locales: TXLocaleState,
        token: String,
        secret: String? = nil,
        cdsHost: String? = nil,
        session: URLSession? = nil,
        cache: TXCache? = nil,
        missingPolicy: TXMissingPolicy? = nil,
        errorPolicy: TXErrorPolicy? = nil,
        renderingStrategy: TXRenderingStategy = .platform
    )

    Parameters

    locales

    keeps track of the available and current locales

    token

    the Transifex token that can be used for retrieving translations from CDS

    secret

    the Transifex secret that can be used for pushing source strings to CDS

    cdsHost

    the host of the CDS service; defaults to a production CDS service hosted by Transifex

    session

    Optional URLSession to be used for all the requests made to the CDS service. If no session is provided, an ephemeral URLSession with no cache will be created and used.

    cache

    holds the available translations in various locales. If nil (default) the internal cache mechanism will be activated, otherwise the provided cache will be used.

    missingPolicy

    determines how to handle translations that are not available

    errorPolicy

    determines how to handle exceptions when rendering a problematic translation (used for ICU rendering strategy)

    renderingStrategy

    determines which strategy to be used when rendering the final string; defaults to platform strategy

  • Designated initializer of the Transifex SDK using the platform rendering strategy and only the required fields (locale state and token).

    For a more involved SDK initialization, you can use the initialize(locales:token:secret:cdsHost:session:cache:missingPolicy:errorPolicy:renderingStrategy:) method.

    Declaration

    Swift

    @objc
    public static func initialize(
        locales: TXLocaleState,
        token: String
    )

    Parameters

    locales

    keeps track of the available and current locales

    token

    the Transifex token that can be used for retrieving translations from CDS

  • Return the translation of the given source string on a certain locale.

    Declaration

    Swift

    @objc
    public static func translate(sourceString: String,
                                 localeCode: String? = nil,
                                 params: [String: Any],
                                 context: String?
    ) -> String?

    Parameters

    sourceString

    the string in the source locale

    localeCode

    an optional locale to translate to; defaults to the current app locale

    params

    a dictionary with optional parameters to use for rendering a string e.g. variable placeholders, character limit, etc

    context

    an optional context that describes the source string (comma separated strings)

    Return Value

    the final string to display to the user

  • Used by the Swift localizedString(format:arguments:) methods found in the TXExtensions.swift file.

    Declaration

    Swift

    public static func localizedString(format: String,
                                       arguments: [Any]) -> String?
  • Fetches the translations from CDS.

    Declaration

    Swift

    @objc
    public static func fetchTranslations(_ localeCode: String? = nil,
                                         tags: [String]? = nil,
                                         completionHandler: TXPullCompletionHandler? = nil)

    Parameters

    localeCode

    if not provided, it will fetch translations for all locales defined in the app configuration.

    tags

    An optional list of tags so that only strings that have all of the given tags are fetched.

    completionHandler

    The completion handler that informs the caller with the new translations and a list of possible errors that might have occured

  • Pushes the base translations to CDS.

    Declaration

    Swift

    @objc
    public static func pushTranslations(_ translations: [TXSourceString],
                                        purge: Bool = false,
                                        completionHandler: @escaping (Bool, [Error]) -> Void)

    Parameters

    translations

    A list of TXSourceString objects.

    purge

    Whether to replace the entire resource content (true) or not (false). Defaults to false.

    completionHandler

    A callback to be called when the push operation is complete with a boolean argument that informs the caller that the operation was successful (true) or not (false) and an array that may or may not contain any errors produced during the push operation.

  • Forces CDS cache invalidation.

    Declaration

    Swift

    @objc
    public static func forceCacheInvalidation(completionHandler: @escaping (Bool) -> Void)

    Parameters

    completionHandler

    A callback to be called when force cache invalidation is complete with a boolean argument that informs the caller that the operation was successful (true) or not (false).

  • Destructs the TXNative singleton instance so that another one can be used.

    Declaration

    Swift

    @objc
    public static func dispose()