Skip to content

Commit

Permalink
finally, add l10n support
Browse files Browse the repository at this point in the history
  • Loading branch information
hewigovens committed Jan 14, 2014
1 parent edc665d commit 51047fe
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 58 deletions.
21 changes: 21 additions & 0 deletions goagent-ios/goagent-ios.xcodeproj/project.pbxproj
Expand Up @@ -38,6 +38,7 @@
CE9128EC157B4171008C98B1 /* GViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE9128EB157B4171008C98B1 /* GViewController.m */; };
CE912963157B483F008C98B1 /* GSettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE912962157B483F008C98B1 /* GSettingViewController.m */; };
CED3CDDD15DB374500FA4742 /* GUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = CED3CDDC15DB374500FA4742 /* GUtility.m */; };
D9AC1FAE188500A000E5B563 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D9AC1FB0188500A000E5B563 /* Localizable.strings */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -97,6 +98,11 @@
CE912962157B483F008C98B1 /* GSettingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GSettingViewController.m; sourceTree = "<group>"; };
CED3CDDB15DB374500FA4742 /* GUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUtility.h; sourceTree = "<group>"; };
CED3CDDC15DB374500FA4742 /* GUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GUtility.m; sourceTree = "<group>"; };
D9AC1FA91884F9E700E5B563 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = "zh-Hans"; path = "zh-Hans.lproj/MainStoryboard_iPad.storyboard"; sourceTree = "<group>"; };
D9AC1FAA1884F9E700E5B563 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = "zh-Hans"; path = "zh-Hans.lproj/MainStoryboard_iPhone.storyboard"; sourceTree = "<group>"; };
D9AC1FAB1884F9E700E5B563 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
D9AC1FAF188500A000E5B563 /* en */ = {isa = PBXFileReference; lastKnownFileType = file; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
D9AC1FB1188500A300E5B563 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -239,6 +245,7 @@
isa = PBXGroup;
children = (
CE9128DA157B4171008C98B1 /* goagent-ios-Info.plist */,
D9AC1FB0188500A000E5B563 /* Localizable.strings */,
CE9128DB157B4171008C98B1 /* InfoPlist.strings */,
CE9128DE157B4171008C98B1 /* main.m */,
CE9128E0157B4171008C98B1 /* goagent-ios-Prefix.pch */,
Expand Down Expand Up @@ -299,6 +306,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
"zh-Hans",
);
mainGroup = CE9128C3157B4171008C98B1;
productRefGroup = CE9128CF157B4171008C98B1 /* Products */;
Expand Down Expand Up @@ -328,6 +336,7 @@
BB31118C15D782E20047E5F1 /* goagent-local in Resources */,
BB31118D15D782E20047E5F1 /* python in Resources */,
BBB609981657803800D823C3 /* Default-568h@2x.png in Resources */,
D9AC1FAE188500A000E5B563 /* Localizable.strings in Resources */,
BBBF8260167C52A6002FBED5 /* authrunner in Resources */,
BBBF8274167C9795002FBED5 /* goagent in Resources */,
);
Expand Down Expand Up @@ -391,6 +400,7 @@
isa = PBXVariantGroup;
children = (
CE0A6CF8157B5B0C00C46A20 /* en */,
D9AC1FA91884F9E700E5B563 /* zh-Hans */,
);
name = MainStoryboard_iPad.storyboard;
sourceTree = "<group>";
Expand All @@ -399,6 +409,7 @@
isa = PBXVariantGroup;
children = (
CE0A6CFA157B5B0C00C46A20 /* en */,
D9AC1FAA1884F9E700E5B563 /* zh-Hans */,
);
name = MainStoryboard_iPhone.storyboard;
sourceTree = "<group>";
Expand All @@ -407,10 +418,20 @@
isa = PBXVariantGroup;
children = (
CE9128DC157B4171008C98B1 /* en */,
D9AC1FAB1884F9E700E5B563 /* zh-Hans */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
D9AC1FB0188500A000E5B563 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
D9AC1FAF188500A000E5B563 /* en */,
D9AC1FB1188500A300E5B563 /* zh-Hans */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
Expand Down
1 change: 1 addition & 0 deletions goagent-ios/goagent-ios/GAppDelegate.m
Expand Up @@ -51,6 +51,7 @@ -(void)dealloc
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSLog(NSLocalizedString(KEY_SETTING_APPID, nil));
NSLog(@"==> GoAgent iOS finish launching, version:%@", infoDict[@"CFBundleShortVersionString"]);

#ifndef DEBUG
Expand Down
26 changes: 13 additions & 13 deletions goagent-ios/goagent-ios/GConfig.h
Expand Up @@ -24,20 +24,20 @@
#define CONTROL_CMD_STOP @"stop"
#define CONTROL_CMD_RESTART @"restart"

#define KEY_SETTING_BASIC @"Basic"
#define KEY_SETTING_CUSTOM @"Custom URL"
#define KEY_SETTING_ADVANCED @"Advanced"
#define KEY_SETTING_APPID @"AppID"
#define KEY_SETTING_PROFILE @"GAE Profile"
#define KEY_SETTING_MODE @"GAE Mode"
#define KEY_SETTING_PAC @"PAC Server"
#define KEY_SETTING_SET_SYSPROXY @"Change System Proxy"
#define KEY_SETTING_INSTALL_CERT @"Install GoAgent CA"
#define KEY_SETTING_INSTALL_APN @"Install APN proxy config"
#define KEY_SETTING_OPEN_LOCAL_LOG @"Open GoAgent iOS Log"
#define KEY_SETTING_OPEN_LOG @"Open GoAgent Log"
#define KEY_SETTING_BASIC @"KEY_SETTING_BASIC"
#define KEY_SETTING_CUSTOM @"KEY_SETTING_CUSTOM"
#define KEY_SETTING_ADVANCED @"KEY_SETTING_ADVANCED"
#define KEY_SETTING_APPID @"KEY_SETTING_APPID"
#define KEY_SETTING_PROFILE @"KEY_SETTING_PROFILE"
#define KEY_SETTING_MODE @"KEY_SETTING_MODE"
#define KEY_SETTING_PAC @"KEY_SETTING_PAC"
#define KEY_SETTING_SET_SYSPROXY @"KEY_SETTING_SET_SYSPROXY"
#define KEY_SETTING_INSTALL_CERT @"KEY_SETTING_INSTALL_CERT"
#define KEY_SETTING_INSTALL_APN @"KEY_SETTING_INSTALL_APN"
#define KEY_SETTING_OPEN_LOCAL_LOG @"KEY_SETTING_OPEN_LOCAL_LOG"
#define KEY_SETTING_OPEN_LOG @"KEY_SETTING_OPEN_LOG"
#define APPLICATION_NAME @"APPLICATION_NAME"

#define APPLICATION_NAME @"GoAgent for iOS"
#define LOCAL_CA_URL @"http://127.0.0.1:8086/CA.crt"
#define REMOTE_CA_URL @"https://github.com/goagent/goagent/raw/3.0/local/CA.crt"
#define REMOTE_APN_TELECOM @"https://github.com/goagent/goagent-ios/raw/master/extra/apns/ChinaTelecom.mobileconfig"
Expand Down
43 changes: 25 additions & 18 deletions goagent-ios/goagent-ios/GSettingViewController.m
Expand Up @@ -29,17 +29,19 @@ - (void)viewDidLoad
[super viewDidLoad];

self.BackBtn = [[UIBarButtonItem alloc] init];
self.BackBtn.title = @"Back";
self.BackBtn.title = NSLocalizedString(@"BUTTON_TITLE_BACK",nil);
self.BackBtn.target = self;
self.BackBtn.action = @selector(performBackAction:);

self.EditBtn = [[UIBarButtonItem alloc] init];
self.EditBtn.title = @"Edit File";
self.EditBtn.title = NSLocalizedString(@"BUTTON_TITLE_EDIT",nil);
self.EditBtn.target = self;
self.EditBtn.action = @selector(performEditAction:);

self.navigationItem.leftBarButtonItem = self.BackBtn;
self.navigationItem.rightBarButtonItem = self.EditBtn;

self.navigationItem.title = NSLocalizedString(@"BUTTON_TITLE_SETTING",nil);

}

Expand Down Expand Up @@ -115,7 +117,7 @@ -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSI

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return _settingSections[section];
return NSLocalizedString(_settingSections[section],nil);
}

#pragma mark UITextFieldDelegate
Expand Down Expand Up @@ -182,7 +184,7 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto
{
if (buttonIndex != alertView.cancelButtonIndex)
{
[GUtility setSystemProxy];
[GUtility setProxyForPreferences];
}
}

Expand Down Expand Up @@ -230,18 +232,19 @@ -(IBAction)performEditAction:(id)sender
-(void)performPressAciton:(id)sender
{
UIButton* button = (UIButton*)sender;
NSString* appTitle = NSLocalizedString(@"APPLICATION_NAME",nil);
switch (button.tag)
{
//change proxy
case 100:
{
NSLog(@"==> perform change system proxy action");

UIAlertView * alert = [[UIAlertView alloc] initWithTitle:APPLICATION_NAME
message:@"It won't change proxy setting for running Apps"
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:appTitle
message:NSLocalizedString(@"CHANGE_PROXY_ALERT_MESSAGE",nil)
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
cancelButtonTitle:NSLocalizedString(@"BUTTON_TITLE_CANCEL",nil)
otherButtonTitles:NSLocalizedString(@"BUTTON_TITLE_OK",nil),nil];
[alert show];

break;
Expand All @@ -258,7 +261,11 @@ -(void)performPressAciton:(id)sender
case 102:
{
NSLog(@"==> perform install APN action");
UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:APPLICATION_NAME delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"ChinaMobile", @"ChinaUnicom", @"ChinaTelecom", nil];
UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:appTitle
delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_TITLE_CANCEL",nil)
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"CARRIER_CHINA_MOBILE",nil), NSLocalizedString(@"CARRIER_CHINA_UNICOM",nil), NSLocalizedString(@"CARRIER_CHINA_TELECOM",nil), nil];
[sheet showInView:self.view];
break;
}
Expand Down Expand Up @@ -295,7 +302,7 @@ - (void)openIniFile:(NSString *)filepath
animated:YES])
{
GAppDelegate* appDelegate = [GAppDelegate getInstance];
[appDelegate showAlert:[NSString stringWithFormat:@"Sorry, No other App can open %@",filepath] withTitle:APPLICATION_NAME];
[appDelegate showAlert:[NSString stringWithFormat:NSLocalizedString(@"EDIT_FILE_ERROR",nil),filepath] withTitle:APPLICATION_NAME];
}
}
}
Expand All @@ -322,17 +329,17 @@ -(void)prepareSettingForDisplay

//basic settings
NSMutableDictionary* appidDic = [NSMutableDictionary new];
appidDic[[NSString stringWithFormat:@"%@_0_key",KEY_SETTING_BASIC]] = KEY_SETTING_APPID;
appidDic[[NSString stringWithFormat:@"%@_0_key",KEY_SETTING_BASIC]] = NSLocalizedString(KEY_SETTING_APPID,nil);
appidDic[[NSString stringWithFormat:@"%@_0_value",KEY_SETTING_BASIC]] = @(iniparser_getstring(iniDic, "gae:appid", NULL));


NSMutableDictionary* modeDic = [NSMutableDictionary new];
modeDic[[NSString stringWithFormat:@"%@_1_key",KEY_SETTING_BASIC]] = KEY_SETTING_MODE;
modeDic[[NSString stringWithFormat:@"%@_1_key",KEY_SETTING_BASIC]] = NSLocalizedString(KEY_SETTING_MODE,nil);
modeDic[[NSString stringWithFormat:@"%@_1_value",KEY_SETTING_BASIC]] = @(iniparser_getstring(iniDic, "gae:mode", NULL));


NSMutableDictionary* profileDic = [NSMutableDictionary new];
profileDic[[NSString stringWithFormat:@"%@_2_key",KEY_SETTING_BASIC]] = KEY_SETTING_PROFILE;
profileDic[[NSString stringWithFormat:@"%@_2_key",KEY_SETTING_BASIC]] = NSLocalizedString(KEY_SETTING_PROFILE,nil);
profileDic[[NSString stringWithFormat:@"%@_2_value",KEY_SETTING_BASIC]] = @(iniparser_getstring(iniDic, "gae:profile", NULL));

NSArray* basicArray = @[appidDic,modeDic,profileDic];
Expand All @@ -342,24 +349,24 @@ -(void)prepareSettingForDisplay
//advanced settings
NSMutableDictionary* sysproxyDic = [NSMutableDictionary new];
sysproxyDic[[NSString stringWithFormat:@"%@_0_key",KEY_SETTING_ADVANCED]] = KEY_SETTING_SET_SYSPROXY;
sysproxyDic[[NSString stringWithFormat:@"%@_0_value",KEY_SETTING_ADVANCED]] = KEY_SETTING_SET_SYSPROXY;
sysproxyDic[[NSString stringWithFormat:@"%@_0_value",KEY_SETTING_ADVANCED]] = NSLocalizedString(KEY_SETTING_SET_SYSPROXY,nil);


NSMutableDictionary* installCertDic = [NSMutableDictionary new];
installCertDic[[NSString stringWithFormat:@"%@_1_key",KEY_SETTING_ADVANCED]] = KEY_SETTING_INSTALL_CERT;
installCertDic[[NSString stringWithFormat:@"%@_1_value",KEY_SETTING_ADVANCED]] = KEY_SETTING_INSTALL_CERT;
installCertDic[[NSString stringWithFormat:@"%@_1_value",KEY_SETTING_ADVANCED]] = NSLocalizedString(KEY_SETTING_INSTALL_CERT,nil);

NSMutableDictionary* installAPNDic = [NSMutableDictionary new];
installAPNDic[[NSString stringWithFormat:@"%@_2_key",KEY_SETTING_ADVANCED]] = KEY_SETTING_INSTALL_APN;
installAPNDic[[NSString stringWithFormat:@"%@_2_value",KEY_SETTING_ADVANCED]] = KEY_SETTING_INSTALL_APN;
installAPNDic[[NSString stringWithFormat:@"%@_2_value",KEY_SETTING_ADVANCED]] = NSLocalizedString(KEY_SETTING_INSTALL_APN,nil);

NSMutableDictionary* openLocalLogDic = [NSMutableDictionary new];
openLocalLogDic[[NSString stringWithFormat:@"%@_3_key",KEY_SETTING_ADVANCED]] = KEY_SETTING_OPEN_LOCAL_LOG;
openLocalLogDic[[NSString stringWithFormat:@"%@_3_value",KEY_SETTING_ADVANCED]] = KEY_SETTING_OPEN_LOCAL_LOG;
openLocalLogDic[[NSString stringWithFormat:@"%@_3_value",KEY_SETTING_ADVANCED]] = NSLocalizedString(KEY_SETTING_OPEN_LOCAL_LOG,nil);

NSMutableDictionary* openGoAgentLogDic = [NSMutableDictionary new];
openGoAgentLogDic[[NSString stringWithFormat:@"%@_4_key",KEY_SETTING_ADVANCED]] = KEY_SETTING_OPEN_LOG;
openGoAgentLogDic[[NSString stringWithFormat:@"%@_4_value",KEY_SETTING_ADVANCED]] = KEY_SETTING_OPEN_LOG;
openGoAgentLogDic[[NSString stringWithFormat:@"%@_4_value",KEY_SETTING_ADVANCED]] = NSLocalizedString(KEY_SETTING_OPEN_LOG,nil);

NSArray* advancedArray = @[sysproxyDic, installCertDic, installAPNDic, openLocalLogDic, openGoAgentLogDic];

Expand Down
3 changes: 2 additions & 1 deletion goagent-ios/goagent-ios/GUtility.h
Expand Up @@ -16,6 +16,7 @@ enum GTaskType{
@interface GUtility : NSObject

+(BOOL) runTaskWithArgs:(NSMutableArray*)args taskType:(enum GTaskType)type waitExit:(BOOL)waitExit;
+(BOOL) setSystemProxy;
+(BOOL) setProxyForPreferences;
+(BOOL) setProxyForDynamicStore;

@end
29 changes: 22 additions & 7 deletions goagent-ios/goagent-ios/GUtility.m
Expand Up @@ -52,11 +52,11 @@ +(BOOL) runTaskWithArgs:(NSMutableArray *)args taskType:(enum GTaskType)type wai
return YES;
}

+(BOOL) setSystemProxy
+(BOOL)setProxyForDynamicStore
{
BOOL result = NO;

NSLog(@"==> setSystemProxy");
NSLog(@"==> setProxyForDynamicStore");

void* libHandle = dlopen("/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", RTLD_LAZY);
if (!libHandle) {
Expand All @@ -65,17 +65,16 @@ +(BOOL) setSystemProxy
}

// Set dynamic store, current proxy

SCDynamicStoreRef
(*_SCDynamicStoreCreate)(CFAllocatorRef,CFStringRef,SCDynamicStoreCallBack,SCDynamicStoreContext*)
= dlsym(libHandle, "SCDynamicStoreCreate");
= dlsym(libHandle, "SCDynamicStoreCreate");
CFStringRef(*_SCDynamicStoreKeyCreateProxies)(CFAllocatorRef)
= dlsym(libHandle, "SCDynamicStoreKeyCreateProxies");
= dlsym(libHandle, "SCDynamicStoreKeyCreateProxies");
Boolean
(*_SCDynamicStoreSetValue)(SCDynamicStoreRef,CFStringRef,CFPropertyListRef)
= dlsym(libHandle, "SCDynamicStoreSetValue");
= dlsym(libHandle, "SCDynamicStoreSetValue");
CFDictionaryRef(*_SCDynamicStoreCopyProxies)(SCDynamicStoreRef)
= dlsym(libHandle, "SCDynamicStoreCopyProxies");
= dlsym(libHandle, "SCDynamicStoreCopyProxies");

SCDynamicStoreRef dynamicStore = _SCDynamicStoreCreate(NULL, CFSTR("goagent-ios"), NULL, NULL);
CFDictionaryRef dynamicProxies = _SCDynamicStoreCopyProxies(dynamicStore);
Expand Down Expand Up @@ -113,7 +112,23 @@ +(BOOL) setSystemProxy
CFRelease(dynamicProxies);
CFRelease(dynamicStore);

dlclose(libHandle);

return result;
}

+(BOOL) setProxyForPreferences
{
BOOL result = NO;

NSLog(@"==> setProxyForPreferences");

void* libHandle = dlopen("/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", RTLD_LAZY);
if (!libHandle) {
NSLog(@"<== dlopen SystemConfiguration failed");
return result;
}

//set preference file
SCPreferencesRef(*_SCPreferencesCreate)(CFAllocatorRef,CFStringRef,CFStringRef)
= dlsym(libHandle, "SCPreferencesCreate");
Expand Down

0 comments on commit 51047fe

Please sign in to comment.