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.
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:
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
andclientSecret
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:
- Swift
- Objective-C
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
})
CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc]
initWithHashString:@"{your_distribution_hash}"
sourceLanguage:@"{source_language}"
organizationName:@"{organization_name}"];
NSError *error;
CrowdinLoginConfig *loginConfig = [[CrowdinLoginConfig alloc]
initWithClientId:@"{client_id}"
clientSecret:@"{client_secret}"
scope:@"project"
error:&error];
if (!error) {
CrowdinSDKConfig *config = [[[[CrowdinSDKConfig config]
withCrowdinProviderConfig:crowdinProviderConfig]
withRealtimeUpdatesEnabled:YES]
withLoginConfig:loginConfig];
[CrowdinSDK startWithConfig:config completion:^{
// SDK is ready to use, put code to change language, etc. here
}];
} else {
NSLog(@"%@", error.localizedDescription);
// CrowdinLoginConfig initialization error handling
}
For OAuth authentication, you need to handle authorization callbacks in your application:
- Swift
- Objective-C
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
CrowdinSDK.handle(url: url)
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [CrowdinSDK handleWithUrl:url];
}
If you are using SceneDelegate, implement the callback in the SceneDelegate class:
- Swift
- Objective-C
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else { return }
CrowdinSDK.handle(url: url)
}
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
return [CrowdinSDK handleWithUrl: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
- Swift
- Objective-C
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)
CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc]
initWithHashString:@"{your_distribution_hash}"
sourceLanguage:@"{source_language}"
organizationName:@"{organization_name}"];
CrowdinSDKConfig *config = [[[[CrowdinSDKConfig config]
withCrowdinProviderConfig:crowdinProviderConfig]
withRealtimeUpdatesEnabled:YES]
withAccessToken:@"your_access_token"];
Config Options Reference
Option | Description | Required | Example Value |
---|---|---|---|
hashString | Distribution Hash | Yes | "7a0c1...o3b" |
sourceLanguage | Source language code (ISO 639-1) | Yes | sourceLanguage: "en" |
organizationName | Organization domain (Enterprise only) | No | "mycompany" |
settingsEnabled | Enable SDK Controls | No | true |
realtimeUpdatesEnabled | Enable Real-Time Preview feature | Yes | true |
accessToken | Crowdin API access token | No* | "your_token" |
- Either
accessToken
or OAuth configuration is required.
OAuth Options
Option | Description | Required | Example Value |
---|---|---|---|
clientId | OAuth Client ID | Yes* | "gpY2yT...x3TYB" |
clientSecret | OAuth Client Secret | Yes* | "Xz95t...EDx9T" |
scope | OAuth scope (must include "project") | Yes* | "project" |
redirectURI | Custom URL scheme for your app | No | "crowdintest://" |
*Required only if using OAuth authentication instead of access token.