This iOS SDK is now officially deprecated and will no longer be maintained or developed further.
It is available in archived form for reference only.
We recommend all users migrate to the new version of the iOS SDK, which includes a modernized architecture, improved integration, and ongoing support.
👉 New SDK Repository: https://github.com/lingohub/ios-cdn-sdk
If you're still using the deprecated version, please plan your migration as soon as possible to ensure compatibility with future updates and platform improvements.
Master translation and connect with world leading translators. Automate and optimize your translation workflow with LingoHub.
- Over-The-Air localization update
- Language switching at runtime
- Method swizzling for easy integration
- Storyboard & XIB localization
- Localization testing using preproduction builds
- iOS 9.0
- watchOS 2.0
- tvOS 9.0
- macOS 10.11
To integrate LingoHub into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'LingoHub'To integrate LingoHub into your Xcode project using Carthage, specify it in your Cartfile:
binary "https://raw.githubusercontent.com/lingohub/lh-ios-sdk/master/LingoHub.json"
If you prefer not to integrate LingoHub manually instead of using a Dependency Manager, download the latest LingoHub.xcframwork and add it to your project.
Wherever you want to use LingoHub, import the module first
import LingoHub#import <LingoHub/LingoHub.h>Configure the LingoHub SDK in your AppDelegate with:
- API Key
- Project Id
- optional: App Version (The default is the
CFBundleShortVersionStringof the main Bundle)
The easiest way is to use our Swizzle feature, so you can use NSLocalizedString as usual.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LingoHubSDK.shared.configure(withApiKey: "YOUR-API-KEY", projectId: "YOUR-PROJECT-ID")
LingoHubSDK.shared.swizzleMainBundle()
}func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
[LingoHubSDK.shared configureWithApiKey:@"YOUR-API-KEY" projectId:@"YOUR-PROJECT-KEY"];
[LingoHubSDK.shared swizzleMainBundle];
}In order to have your localizations updated, include following code in your AppDelegate:
func applicationDidBecomeActive(_ application: UIApplication) {
LingoHubSDK.shared.update { result in
switch result {
case .success(let value):
print("Content updated: \(value)")
case .failure(let error):
print(error.localizedDescription)
}
}
}- (void)applicationDidBecomeActive:(UIApplication *)application {
[LingoHubSDK.shared updateWithCompletion:^(BOOL value, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Content updated: %d", value);
} else {
NSLog(error.localizedDescription);
}
}];
}If you do not want to use method swizzling, you can get your updated localization by asking the LingoHub SDK for it.
func localizedString(withKey key: String, tableName: String? = nil) {
if let localizedString = LingoHubSDK.shared.localizedString(forKey: key, tableName: tableName) {
return localizedString
}
return NSLocalizedString(key, tableName: tableName, comment: "")
}- (NSString * _Nonnull)localizedStringWithKey:(NSString * _Nonnull)key tableName:(NSString * _Nullable)tableName {
NSString *updatedLocalization = [LingoHubSDK.shared localizedStringForKey:key tableName:tableName];
if (updatedLocalization != nil) {
return updatedLocalization;
}
return NSLocalizedStringFromTable(key, tableName, @"");
}If LingoHub has found updated localization, it will post the LingoHubDidUpdateLocalization notification. Observe it to get notified on updates.
NotificationCenter.default.addObserver(forName: .LingoHubDidUpdateLocalization, object: nil, queue: nil) { [weak self] _ in
self?.updateLocalization()
}_weak MyViewController *weakSelf = self;
[NSNotificationCenter.defaultCenter addObserverForName:NSNotification.LingoHubDidUpdateLocalization object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
MyViewController *strongSelf = weakSelf;
[strongSelf updateLocalization];
}];If you would like to change the language of your app at runtime, you can use the LingoHub SDK for it.
LingoHubSDK.shared.setLanguage("de")[LingoHubSDK.shared setLanguage:@"de"];If you would like to test your localizations before submitting a new package, enable preproduction mode.
LingoHubSDK.shared.isPreproductionEnabled = true[LingoHubSDK.shared setIsPreproductionEnabled:true];If you are using storyboard and/or XIB localization, you have to reload the view after LingoHub did update your localizations.
For bug reports, please create a new Issue right here on Github. Otherwise have a look at our Contact options