Skip to main content

Setup

To configure iOS SDK integration you need to:

Distribution is a CDN vault that mirrors the translated content of your project and is required for integration with iOS app.

info
  • 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.

Setup with AppDelegate

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:

$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)

Add use_frameworks! to your Podfile.

Setup with Info.plist

Open Info.plist file and add:

CrowdinDistributionHash - Crowdin CDN hash value for current project (String value).

CrowdinSourceLanguage - Source language code of your Crowdin project in the (ISO 639-1) format (String value).

In AppDelegate you should call start method: CrowdinSDK.start() for Swift, and [CrowdinSDK start] for Objective-C.

caution

Using this setup method, you will not be able to set up additional Screenshots and Real-Time Preview project 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:

pod 'CrowdinSDK/IntervalUpdate'

Then enable this option in CrowdinSDKConfig:

.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> - target language code in ISO 639-1 format.

Config options

Config optionDescriptionExample
hashStringDistribution HashhashString: "7a0c1...o3b"
sourceLanguageSource language code in your Crowdin project. ISO 639-1sourceLanguage: "en"

SwiftUI support

SwiftUI doesn't have automatic support yet. It will work only when you pass localised string using NSLocalizedString("key", comment: "comment"). It means that you will need to update all localised strings in SwiftUI application. For more comfortable usage you can use out String extension for localisation: "key".cw_localized.

Example:

Text(NSLocalizedString("key", comment: "comment"))

or

Text("key".cw_localized)

After we add SwiftUI support, you will just need to remove the cw_localized method call.