Setup
To configure iOS SDK integration you need to:
- Upload your localization files to Crowdin. If you have existing translations, you can upload them as well. You can use one of the following options:
- Set up Distribution in Crowdin.
- Set up SDK and enable Over-The-Air Content Delivery feature.
Distribution is a CDN vault that mirrors the translated content of your project and is required for integration with iOS app.
- The download of translations happens asynchronously after the start of the application. The downloaded translations will be used the next time the app is launched, otherwise the previously cached translations will be used (or local translations if no cache exists).
- The CDN feature does not update the localization files, if you want to add new translations to the localization files, you need to do it yourself.
- Once the SDK receives the translations, they're stored on the device as application files for future sessions to minimize requests the next time the app is launched. The storage time can be configured using the
intervalUpdatesEnabled
option. - CDN will cache all translations in the release for up to 1 hour and even if new translations are released in Crowdin, CDN may return them with a delay.
Swift
Open the AppDelegate.swift file and add:
import CrowdinSDK
In the application
method add:
let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{distribution_hash}",
sourceLanguage: "{source_language}")
CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: {
// SDK is ready to use, put code to change language, etc. here
})
Objective-C
In the AppDelegate.m add:
@import CrowdinSDK
or
#import<CrowdinSDK/CrowdinSDK.h>
In the application
method add:
CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@""];
CrowdinSDKConfig *config = [[[CrowdinSDKConfig config] withCrowdinProviderConfig:crowdinProviderConfig]];
[CrowdinSDK startWithConfig:config completion:^{
// SDK is ready to use, put code to change language, etc. here
}];
If you have a pure Objective-C project, you will need to take some additional steps:
Add the following code to your Library Search Paths:
Add to Library Search Paths:
$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
Add
use_frameworks!
to your Podfile.
Alternative Setup: Info.plist
You can also configure basic SDK settings in Info.plist:
Add these keys to Info.plist:
CrowdinDistributionHash
(String) - Your Crowdin CDN hashCrowdinSourceLanguage
(String) - Source language code in ISO 639-1 format
In AppDelegate call:
- Swift:
CrowdinSDK.start()
- Objective-C:
[CrowdinSDK start]
- Swift:
Using the Info.plist
setup method, you cannot configure Screenshots and Real-Time Preview features.
Additional Features
Translations Update Interval
By default, SDK searches for new translation once per application load, but not more often than 15 minutes. You can update translations in application every defined interval. To enable this feature add pod CrowdinSDK/IntervalUpdate
to your pod file:
Add to
Podfile
:pod 'CrowdinSDK/IntervalUpdate'
Configure in SDK:
.with(intervalUpdatesEnabled: true, interval: {interval})
Where
interval
- defines translations update time interval in seconds. Minimum allowed interval is 15 minutes (900 seconds).
Change locale programmatically
By default, the SDK relies on the device locale. To change the SDK target language on the fly regardless of the device locale, use the following method:
CrowdinSDK.enableSDKLocalization(true, localization: "<language_code>")
Where <language_code>
is the target language in ISO 639-1 format.
SwiftUI Support
SwiftUI support requires explicit localization calls. Use either:
Text(NSLocalizedString("key", comment: "comment"))
or the convenience extension:
Text("key".cw_localized)
View the Swift UI Localization guide for more information.
Apple Strings Catalog Support
The Crowdin SDK supports the Apple Strings Catalog (.xcstrings
) format out of the box. It doesn't require any additional setup. Just upload your localization files to Crowdin, set up the distribution and start using the SDK.
Only the CDN Content Delivery feature is available for the Apple Strings Catalog format. The Screenshots and Real-Time Preview features are not yet supported.
Config Options Reference
Option | Description | Example Value |
---|---|---|
hashString | Distribution Hash | "7a0c1...o3b" |
sourceLanguage | Source language code (ISO 639-1) | sourceLanguage: "en" |
organizationName | Organization domain (Enterprise only) | "mycompany" |
settingsEnabled | Enable SDK Controls | true |
accessToken | Crowdin API access token | "your_token" |
OAuth Options
Option | Description | Example Value |
---|---|---|
clientId | OAuth Client ID | "gpY2yT...x3TYB" |
clientSecret | OAuth Client Secret | "Xz95t...EDx9T" |
scope | OAuth scope (e.g., "project.screenshot", "project") | "project" |
redirectURI | Custom URL scheme for your app | "crowdintest://" |