From 4a5c57d018241c90446e9a9bff8499a01a845376 Mon Sep 17 00:00:00 2001 From: golopupinsky Date: Sun, 15 Jan 2017 13:46:12 +0300 Subject: [PATCH] Allows using additional root urls for localization purposes --- app/Jasonette/Jason.m | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Jasonette/Jason.m b/app/Jasonette/Jason.m index a8aa1f43..53ecfb67 100644 --- a/app/Jasonette/Jason.m +++ b/app/Jasonette/Jason.m @@ -114,11 +114,10 @@ - (void)start{ **************************************************/ JasonAppDelegate *app = (JasonAppDelegate *)[[UIApplication sharedApplication] delegate]; NSDictionary *plist = [self getSettings]; - ROOT_URL = plist[@"url"]; INITIAL_LOADING = plist[@"loading"]; JasonViewController *vc = [[JasonViewController alloc] init]; - vc.url = ROOT_URL; + vc.url = [self getRootUrl]; vc.loading = INITIAL_LOADING; vc.view.backgroundColor = [UIColor whiteColor]; vc.extendedLayoutIncludesOpaqueBars = YES; @@ -850,6 +849,23 @@ - (NSArray *)getKeys{ } return [newKeys copy]; } +-(NSString*)getRootUrl{ + NSDictionary *plist = [self getSettings]; + + NSArray *preferredLocalizations = [NSLocale preferredLanguages]; + for (__strong NSString *loc in preferredLocalizations) {//try getting localized root url for one of the preferred localizations + loc = [[loc substringToIndex:2] uppercaseString]; + NSString *localizedUrl = [@"url" stringByAppendingString:loc]; + if(plist[localizedUrl]){ + ROOT_URL = plist[localizedUrl]; + break; + } + } + if(ROOT_URL == nil){//set default root url if nothing was set + ROOT_URL = plist[@"url"]; + } + return ROOT_URL; +} -(NSDictionary*)getSettings{ NSDictionary * infoPlistSettings = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"settings"]; if(infoPlistSettings != nil){//target's info.plist file contains customized settings