Softlation的libSoftlation是一个预编译的通用库,提供了一种简单的方式来实现本地化更新,并提高您的应用的质量保证和A/B测试过程。如果您想在您的应用中使用Softlation Sync和Softlation QA,则需要将库包含在您的应用中。请使用Pods或下载最新的SoftlationSDK.dmg,这些压缩文件包含支持armv7/armv7s/arm64/i386/x86_64版本的预编译通用库,并可与iOS6+一起使用。
Podfile
并添加您的依赖项pod 'Softlation', '~> 1.0'
下载并解压最新的libSoftlation版本。将“SoftlationSDK”目录复制到您的项目中
cp -r SoftlationSDK /YourProject/
此外,您需要在源文件中包含Softlation.h
。
在开始之前,您必须执行上述步骤。
要启用Softlation Sync通知,您需要按照以下简单步骤操作
AppDelegate.m
文件。#import "Softlation.h"
didFinishLaunchingWithOptions
函数中。- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Your other application code.....
// We've recommend to implement Softlation Library right before the end of the method.
// Set YES to enable QA Mode. Default is NO
// Please read below how to enable QA Mode for all your controllers with NSLocalizedString
[Softlation setQAMode:NO];
// Optionally, you can specify custom Launch Image that will be presented right after system launch Image.
// The second variable holds existed Launch Image during Softlation Sync which make Sync process smooth.
[Softlation setCustomLaunchImage:(nil) holdLaunchImageWhileLoading:YES];
// Here you should set up your API KEY of the app on Softlation Service.
[Softlation configureWithToken:@"API_KEY" completionHandler:nil];
return YES;
}
API_KEY
如果您在其应用程序代理中设置 [Softlation setQAMode:YES];
来使 QA 模式 工作的话,您还需要实现所有控制器中的额外方法,并使用 NSLocalizedString
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleTranslationUpdated:)
name:kSoftlationTranslationUpdatedNotification object:nil];
}
return self;
}
- (void)handleTranslationUpdated:(NSNotification *)notification {
// Update view texts, for details see below
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
如果您在控制器中有一个表格,请简单修改以下方法
- (void)handleTranslationUpdated:(NSNotification *)notification {
// This line you need only if your controller consist Table View with NSLocalizedString,
// Add it for all your Table View using their names
// By default you can set it to tableView
[self.TABLEVIEWNAME reloadData];
}
NSLocalizedString
,您需要在 handleTranslationUpdated
中调用 [self.view setNeedsLayout]
,并在 viewWillLayoutSubviews
中简单地重置值。- (void)handleTranslationUpdated:(NSNotification *)notification {
[self.view setNeedsLayout];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.label1.text = NSLocalizedString(@"StringNameKey", nil);
self.label2.text = NSLocalizedString(@"StringName2Key", nil);
}
如果您在 @properties
中没有存储子视图的引用,您应该单独处理这些情况,可能需要重新创建这样的子视图以重置文本。
Softlation © 2014-2016 版权所有
未经授权的复制或使用是违反适用法律的。