Skip to main content

Real-Time Preview

Experience instant preview of translations directly in your app with real-time sync from the Crowdin Editor. Watch your translations appear live as you type, and review existing translations in context within your application. This immediate feedback helps ensure translations fit perfectly in your app's interface and maintain the intended meaning.

caution

The Real-Time Preview feature is designed for development and staging environments only. Using this feature in production can expose untested translations and impact app stability. For production builds, disable Real-Time Preview and use the standard over-the-air translation updates.

Setup

Swift

Add the code below to your Podfile:

Podfile
use_frameworks!
target 'your-app' do
pod 'CrowdinSDK'
pod 'CrowdinSDK/LoginFeature' // Required for Real-Time Preview
pod 'CrowdinSDK/RealtimeUpdate' // Required for Real-Time Preview
pod 'CrowdinSDK/Settings' // Optional. To add 'settings' floating button
end

Authorization

The Real-Time Preview feature requires authorization to leverage Crowdin's API for real-time updates.

Choose from two authorization methods based on your needs:

  • OAuth-based Authorization: Uses clientId and clientSecret for web-based authorization. This method implements a secure OAuth flow that opens a dialog for users to authorize the application. Best suited for development environments and when user interaction is acceptable.
  • API Token Authorization: Uses the accessToken to pass the API Personal Access Token directly. This streamlined method is ideal for automated workflows, CI/CD pipelines, or scenarios where user interaction is not desired.

If both methods are configured, access token authentication takes priority.

OAuth-based Authorization

Implements a secure web-based authorization flow using clientId and clientSecret. This method:

  • Opens a dialog for user authorization
  • Provides a secure authentication process
  • Is ideal for development and testing environments

To enable OAuth-based authorisation, add the following configuration to your AppDelegate' class in the application' method:

AppDelegate.swift
let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}",
sourceLanguage: "{source_language}",
organizationName: "{organization_name}") // Optional. Required for Enterprise only

var loginConfig: CrowdinLoginConfig
do {
loginConfig = try CrowdinLoginConfig(clientId: "{client_id}",
clientSecret: "{client_secret}",
scope: "project",
redirectURI: "{redirectURI}")
} catch {
print(error)
// CrowdinLoginConfig initialization error handling
}

let crowdinSDKConfig = CrowdinSDKConfig.config()
.with(crowdinProviderConfig: crowdinProviderConfig)
.with(realtimeUpdatesEnabled: true)
.with(loginConfig: loginConfig)
.with(settingsEnabled: true)

CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: {
// SDK is ready to use, put code to change language, etc. here
})

For OAuth authentication, you need to handle authorization callbacks in your application:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
CrowdinSDK.handle(url: url)
}

If you are using SceneDelegate, implement the callback in the SceneDelegate class:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else { return }
CrowdinSDK.handle(url: url)
}

API Token Authorization

A streamlined approach using the accessToken option that bypasses OAuth authentication. This method:

  • Allows direct API token integration
  • Requires no user interaction
  • Is perfect for CI/CD pipelines and automated workflows
AppDelegate.swift
let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}",
sourceLanguage: "{source_language}",
organizationName: "{organization_name}") // Optional. Required for Enterprise only

let crowdinSDKConfig = CrowdinSDKConfig.config()
.with(crowdinProviderConfig: crowdinProviderConfig)
.with(realtimeUpdatesEnabled: true)
.with(accessToken: "your_access_token")
.with(settingsEnabled: true)

Config Options Reference

OptionDescriptionRequiredExample Value
hashStringDistribution HashYes"7a0c1...o3b"
sourceLanguageSource language code (ISO 639-1)YessourceLanguage: "en"
organizationNameOrganization domain (Enterprise only)No"mycompany"
settingsEnabledEnable SDK ControlsNotrue
realtimeUpdatesEnabledEnable Real-Time Preview featureYestrue
accessTokenCrowdin API access tokenNo*"your_token"
  • Either accessToken or OAuth configuration is required.

OAuth Options

OptionDescriptionRequiredExample Value
clientIdOAuth Client IDYes*"gpY2yT...x3TYB"
clientSecretOAuth Client SecretYes*"Xz95t...EDx9T"
scopeOAuth scope (must include "project")Yes*"project"
redirectURICustom URL scheme for your appNo"crowdintest://"

*Required only if using OAuth authentication instead of access token.