Skip to main content

Real-Time Preview

All translations done in the Crowdin Editor can be displayed in your version of the application in real-time. See the translations that have already been done and the ones you're typing.

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

Open AppDelegate.swift file and in the application method add:

AppDelegate.swift
let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}",
sourceLanguage: "{source_language}",
organizationName: "{organization_name}")

var loginConfig: CrowdinLoginConfig
do {
loginConfig = try CrowdinLoginConfig(clientId: "{client_id}",
clientSecret: "{client_secret}",
scope: "project",
redirectURI: "{redirectURI}")
} catch {
print(error)
// CrowdinLoginConfig initialization error handling, typically for empty values and for wrong redirect URI value.
}

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

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

Objective-C

CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@"" 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] 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, typically for empty values and for wrong redirect URI value.
}

Authorization

Crowdin Authorization is required for Real-Time Preview feature. So you need to handle authorization callback in your application:

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

If you are using SceneDelegate, you need to handle callback in the SceneDelegate class implement method:

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

Config options

Config optionDescriptionExample
hashStringDistribution HashhashString: "7a0c1e...297uo3b"
sourceLanguageSource language code in your Crowdin project. ISO 639-1sourceLanguage: "en"
clientId, clientSecretCrowdin OAuth Client ID and Client SecretclientId: "gpY...3TYB", clientSecret: "Xz95...EDx9T"
scopeDefine the access scope for personal tokensscope: "project"
redirectURIA custom URL for your app. Read more in the article. It's an optional value. You should set it in case you want to use a specific URL scheme. In case you set a scheme which is not supported by your application init method will throw an exception.redirectURI: "crowdintest://"
organizationNameAn Organization domain name (for Crowdin Enterprise users only)organizationName: "mycompany"
settingsEnabledEnable SDK Controls to easily access the SDK featuressettingsEnabled: true
realtimeUpdatesEnabledEnable Real-Time Preview featurerealtimeUpdatesEnabled: true
caution

The Real-Time Preview feature should not be used in a production environment. It is intended for use in development or staging only.