Transifex

  • Documentation
  • iOS SDK
  • Quickstart: Transifex Native and iOS

Quickstart: Transifex Native and iOS

Note

You can start using Transifex Native by creating a Transifex Native project.

This is a quick start guide to get you through the whole Transifex Native experience on iOS. Follow the steps below to start testing Transifex Native on your iOS application. The SDK allows you to keep using the same localization hooks that the iOS framework provides.

You can read all details on how the iOS SDK works in this GitHub documentation.

Setup iOS SDK

The iOS Native SDK is supported on Swift 5.3, Xcode 12.3, and iOS 10.0+.

Here is an overview video of the installation process.

To complete the setup you will need to:

  • Add "Transifex" as a package dependency in Xcode, by selecting your project, heading over to the 'Swift Packages' section, tapping on the '+' button, and entering the public repository URL in the search field.
  • Initialize the SDK in your application using the transifex_token provided by your Transifex Native project.

Here is a configuration example in Swift:

import Transifex

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
                    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let locales = TXLocaleState(sourceLocale: "en",
                                    appLocales: ["en", "el", "fr"])

        TXNative.initialize(
            locales: locales,
            token: "<transifex_token>"
        )

        return true
    }
}

For Swift projects, you will also need to copy the TXNativeExtensions.swift file in your project and include it in all of the targets that call any of the following Swift methods:

  • String.localizedStringWithFormat(format:...)
  • NSString.localizedStringWithFormat(format:...)

If none of your application targets call any of the above methods, then you don’t need to add this file to your project.

If you are interested in setting up the SDK for your application extensions as well, you can look into the related section in the documentation. The documentation also covers more special cases, such as providing a custom NSURLSession or configuring logging.

Internationalize your code

The SDK allows you to keep using the same localization hooks that the iOS framework provides, such as NSLocalizedString, String.localizedStringWithFormat(format:...), etc, while at the same time taking advantage of the features that Transifex Native offers, such as OTA translations.

Push source content to Content Delivery Service

Use the Transifex CLI-swift to collect all your app content and send it to Transifex for translation. To perform this action you will need the transifex_secret token that you created in your Transifex Native project.

txios-cli push --token <transifex_token> --secret <transifex_secret> --project MyApp.xcodeproj

Checkout a video on pushing strings for iOS.

Display translated content

By default, the iOS Native SDK uses the current locale set on the iOS device and also listens for changes to the current locale.

Here is a video on previewing translations in your app.

Developers can override this setting by providing a custom class that conforms to the TXCurrentLocaleProvider protocol and return a specific locale code in the currentLocale() method.

This custom locale provider can then be provided during the initialization of the TXLocaleState object as its final argument (currentLocaleProvider):

class CustomLocaleProvider : TXCurrentLocaleProvider {
    func currentLocale() -> String {
        return "el"
    }
}

let locales = TXLocaleState(sourceLocale: "en",
                            appLocales: ["en", "el"],
                            currentLocaleProvider: CustomLocaleProvider())

TXNative.initialize(locales: locales,
                    token: "<token>")

It is worth noting that the iOS SDK manages an internal cache of translations in the file system of the translations fetched over-the-air. Checkout the video on bundling translations to your iOS application.

You can find more about caching in the documentation.

Check out the detailed iOS Native GitHub documentation for all the details on setting up and managing your iOS application using Native SDK.

For a quick overview of iOS supported Native features checkout the Feature Matrix.