在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):crowdin/mobile-sdk-ios开源软件地址(OpenSource Url):https://github.com/crowdin/mobile-sdk-ios开源编程语言(OpenSource Language):Swift 98.3%开源软件介绍(OpenSource Introduction):Crowdin iOS SDKCrowdin iOS SDK delivers all new translations from Crowdin project to the application immediately. So there is no need to update this application via App Store to get the new version with the localization. The SDK provides:
Table of Contents
Requirements
Dependencies
InstallationCocoapods
After you've added CrowdinSDK to your Podfile, run Swift Package ManagerOnce you have your Swift package set up, adding CrowdinSDK as a dependency is as easy as adding it to the dependencies value of your Package.swift. dependencies: [
.package(url: "https://github.com/crowdin/mobile-sdk-ios.git", from:"1.4.0")
] SetupTo 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. To manage distributions open the needed project and go to Over-The-Air Content Delivery. You can create as many distributions as you need and choose different files for each. You’ll need to click the Release button next to the necessary distribution every time you want to send new translations to the app.
Notes:
Setup with AppDelegateOpen AppDelegate.swift file and add: import CrowdinSDK In let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}",
sourceLanguage: "{source_language}")
CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: {
// SDK is ready to use, put code to change language, etc. here
})
Objective-CIn AppDelegate.m add: @import CrowdinSDK or #import<CrowdinSDK/CrowdinSDK.h> In 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 pure Objective-C project, then you will need to do some additional steps: Add the following code to your Library Search Paths: $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) Add Setup with Info.plistOpen Info.plist file and add:
In AppDelegate you should call start method: Note! Using this setup method you will unable to set up additional Screenshots and Real-Time Preview project features. SwiftUI supportSwiftUI doesn’t have automatic support for now. It will work only when you pass localised string using Example:
or
After we add SwiftUI support you will need just simply remove call of Advanced FeaturesReal-Time PreviewAll the translations that are done in the Editor can be shown in the application in real-time. View the translations already made and the ones you're currently typing in. Add the code below to your Podfile: use_frameworks!
target 'your-app' do
pod 'CrowdinSDK'
pod 'CrowdinSDK/LoginFeature' // Required for Real-Time Preview
pod 'CrowdinSDK/RealtimeUpdate' // Required for Real-Time Preview
pod 'CrowdinSDK/Settings' // Optional. To add 'settings' floating button
end Open AppDelegate.swift file and in let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}",
sourceLanguage: "{source_language}")
var loginConfig: CrowdinLoginConfig
do {
loginConfig = try CrowdinLoginConfig(clientId: "{client_id}",
clientSecret: "{client_secret}",
scope: "project",
redirectURI: "{redirectURI}",
organizationName: "{organization_name}")
} 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(loginConfig: loginConfig)
.with(settingsEnabled: true)
.with(realtimeUpdatesEnabled: true)
CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: {
// SDK is ready to use, put code to change language, etc. here
}) Objective-CCrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@""];
NSError *error;
CrowdinLoginConfig *loginConfig = [[CrowdinLoginConfig alloc] initWithClientId:@"{client_id}" clientSecret:@"{client_secter}" scope:@"project" organizationName:@"{organization_name}" 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.
}
The last step is to handle authorization callback in your application: func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
CrowdinSDK.handle(url: url)
} Objective-C- (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: func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else { return }
CrowdinSDK.handle(url: url)
} Objective-C- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
return [CrowdinSDK handleWithUrl:url];
} ScreenshotsEnable if you want all the screenshots made in the application to be automatically sent to your Crowdin project with tagged strings. This will provide additional context for translators. 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 let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}",
sourceLanguage: "{source_language}")
var loginConfig: CrowdinLoginConfig
do {
loginConfig = try CrowdinLoginConfig(clientId: "{client_id}",
clientSecret: "{client_secret}",
scope: "project.screenshot",
redirectURI: "{redirectURI}",
organizationName: "{organization_name}")
} 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-CCrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@""];
NSError *error;
CrowdinLoginConfig *loginConfig = [[CrowdinLoginConfig alloc] initWithClientId:@"{client_id}" clientSecret:@"{client_secter}" scope:@"project.screenshot" organizationName:@"{organization_name}" 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.
}
The last step is to handle authorization callback in your application: func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
CrowdinSDK.handle(url: url)
} Objective-C- (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: func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else { return }
CrowdinSDK.handle(url: url)
} Objective-C- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
return [CrowdinSDK handleWithUrl:url];
} You could also define (optional) your own handler to take a screenshot (for example, clicking on some button in your application): let feature = ScreenshotFeature.shared {
feature.captureScreenshot(name: String(Date().timeIntervalSince1970), success: {
CrowdinLogsCollector.shared.add(log: CrowdinLog(type: .info, message: message))
self?.showToast(message)
}, errorHandler: { (error) in
let message = "Error while capturing screenshot - \(error?.localizedDescription ?? "Unknown")"
CrowdinLogsCollector.shared.add(log: CrowdinLog(type: .error, message: message))
self?.showToast(message)
})
} or even capture screenshots of a separate UIView. Notes
File Export PatternsYou can set file export patterns and check existing ones using File |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论