Skip to main content

Screenshots

The Screenshots feature enhances the localization workflow by automatically capturing and uploading tagged screenshots from your application to your Crowdin project. This provides translators with valuable visual context, ensuring more accurate and contextually appropriate translations.

caution

The Screenshots feature is intended for development and staging environments only. Enabling this feature in production builds could expose sensitive UI information and impact app performance. For production releases, ensure the Screenshots feature is disabled to maintain security and optimal performance.

Overview

You can capture and upload tagged screenshots to Crowdin in two ways:

  1. SDK Controls Widget: Use the built-in SDK Controls UI widget for easy management
  2. Custom Handler: Implement your own screenshot trigger (e.g., an in-app button or gesture, or an automated workflow)

Setup

Swift

To enable the Screenshots feature in your application, add the following configuration 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

Authorization

The Screenshots feature requires authorization to transmit screenshots to your Crowdin project. 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 authorization, add the following configuration to your AppDelegate class:

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.screenshot",
redirectURI: "{redirectURI}")
} catch {
print(error)
// CrowdinLoginConfig initialization error handling
}

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
})

For OAuth authentication, 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)
}

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(screenshotsEnabled: true)
.with(accessToken: "your_access_token")
.with(settingsEnabled: true)

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

Custom Screenshot Handler

You can use one of two methods to take screenshots programmatically:

  1. Basic screenshot capture:

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


    CrowdinSDK.captureAndUpdateScreenshot(name: "{screenshot_name}") { result in
    switch result {
    case .new: print("New screenshot captured")
    case .udpated: print("Screenshot updated")
    }
    } errorHandler: { error in
    print("Error: \(error)")
    }

The captureAndUpdateScreenshot method is useful when you want to update an existing screenshot in your Crowdin project. This can help maintain screenshot organization by updating existing screenshots rather than creating new ones each time.

You can also capture screenshots of specific UIView instances with either method.

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
screenshotsEnabledEnable Screenshots featureYestrue
accessTokenCrowdin API access tokenNo*"your_token"

OAuth Options

The CrowdinLoginConfig class provides OAuth configuration options:

OptionDescriptionRequiredExample
clientIdOAuth Client IDYes*"gpY2yT...x3TYB"
clientSecretOAuth Client SecretYes*"Xz95t...EDx9T"
scopeOAuth scope (must include "project.screenshot")Yes*"project.screenshot"
redirectURICustom URL scheme for your appNo"crowdintest://"
  • Required only if using OAuth authentication instead of access token.

Troubleshooting

If you get the error:

Error while capturing screenshot - The operation couldn't be completed. (There are no localized strings detected on current screen. error 99999.)

Make sure that your current locale matches your project's source (default) language.