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:
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:
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.
}
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:
- 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, you need to handle callback in the SceneDelegate class implement method:
- 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];
}
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 option | Description | Example |
---|---|---|
hashString | Distribution Hash | hashString: "7a0c1....97uo3b" |
sourceLanguage | Your Crowdin project source language. ISO 639-1 | sourceLanguage: "en" |
clientId , clientSecret | Crowdin OAuth Client ID and Client Secret | clientId: "gpY2yT...x3TYB" , clientSecret: "Xz95t...EDx9T" |
scope | Define the access scope for personal tokens | scope: "project.screenshot" |
redirectURI | A 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://" |
organizationName | An Organization domain name (for Crowdin Enterprise users only) | organizationName: "mycompany" |
settingsEnabled | Enable SDK Controls to easily access the features of SDK | settingsEnabled: true |
screenshotsEnabled | Enable Screenshots feature | screenshotsEnabled: true |
The Screenshots feature should not be used in a production environment. It is intended for use in development or staging only.