Skip to main content

Screenshots

Enable this option if you want all screenshots taken in the application to be automatically sent to your Crowdin project with tagged strings. This provides additional context for translators.

Setup

Swift

Add the code below to your Podfile:

Podfile
use_frameworks!
target 'your-app' do
pod 'CrowdinSDK'
pod 'CrowdinSDK/LoginFeature' // Required for Screenshots
pod 'CrowdinSDK/Screenshots' // Required for Screenshots
pod 'CrowdinSDK/Settings' // Optional. To add 'settings' 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.screenshot",
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(screenshotsEnabled: true)
.with(loginConfig: loginConfig)
.with(settingsEnabled: 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.screenshot" 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.
}
caution

If you get the Error while capturing screenshot - The operation couldn’t be completed. (There are no localized strings detected on current screen. error 99999.) when sending screenshots, please make sure that your current locale is your project source (default) language.

Authorization

Crowdin Authorization is required for Screenshots 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)
}

Own handler

You can also (optionally) define your own handler to take a screenshot (e.g. by clicking a button in your application):

CrowdinSDK.captureScreenshot(name: String(Date().timeIntervalSince1970)) {
print("Screenshot captured")
} errorHandler: { error in
print("Screenshot capture failed with error - " + error?.localizedDescription)
}

or even capture screenshots of a separate UIView.

Config options

Config optionDescriptionExample
hashStringDistribution HashhashString: "7a0c1....97uo3b"
sourceLanguageYour Crowdin project source language. ISO 639-1sourceLanguage: "en"
clientId, clientSecretCrowdin OAuth Client ID and Client SecretclientId: "gpY2yT...x3TYB", clientSecret: "Xz95t...EDx9T"
scopeDefine the access scope for personal tokensscope: "project.screenshot"
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 features of SDKsettingsEnabled: true
screenshotsEnabledEnable Screenshots featurescreenshotsEnabled: true
caution

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