0

I am developing an app in which an user can change language at any time. I have done this in a demo app. It is working fine. But there is an issue with it, that is for localisation app I have to do following 2 tasks.

Step 1: I have to create IB outlet for every object (i.e in every class ==> buttons, labels, textFields, TextViews).

Step 2 : I have to set language for every objects for example : [myButton setTitle:[Language get:@"Language Test" alter:nil] forState:UIControlStateNormal]; OR myLabel.text=LocalizedString(@"Forgot Passoword");

I have a project which has many screens, around 60 screens (in storyboard). Unfortunately in this project there is no IB outlet for all objects. Strings are set in via storyboard. Now I have to make support this app in another language also (current language english )name Arabic language.

Conclusion : If I do above 2 steps (create IB outlet for every objects , then write code in .m file for every object). It will take very much time. Is there any other better options please ? I want do not want create IB outlet and coding in .m file. Any suggestion will be great!!

What I have done till now :

Follow these tuttorials :

(1). How to force NSLocalizedString to use a specific language

and sample projects :

(1). https://github.com/tonisalae/TSLanguageManager

(2). https://github.com/object2dot0/Advance-Localization-in-ios-apps

My code :

example calls:

[Language setLanguage:@"it"];

OR

[Language setLanguage:@"de"];


+(void)initialize {
        NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
        NSArray* languages = [defs objectForKey:@"AppleLanguages"];
        NSString *current = [languages objectAtIndex:0];
        [self setLanguage:current];

    }

        +(void)setLanguage:(NSString *)l {
        NSLog(@"\n\n\t ***** Hint Lang. selected by user: %@   ****\n\n", l);
        NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
        bundle = [NSBundle bundleWithPath:path];
    }

        +(NSString *)get:(NSString *)key alter:(NSString *)alternate {
        return [bundle localizedStringForKey:key value:alternate table:nil];
    }
Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
Ravi
  • 800
  • 2
  • 12
  • 28
  • I have solution for your question. – user3182143 Jun 08 '17 at 08:57
  • perfect solution https://stackoverflow.com/questions/44353180/why-language-change-required-app-to-restart-in-objective-c/44357868#44357868 – user3182143 Jun 08 '17 at 08:59
  • This is for Arabic - https://stackoverflow.com/questions/42465604/localizable-strings-not-working-with-arabic-string/42468015#42468015 – user3182143 Jun 08 '17 at 09:05
  • Monu singh you can get the result easily now – user3182143 Jun 08 '17 at 09:05
  • @ user3182143 I think you do not read my question carefully. In link (provided by you), we must have 2 do steps for localization. Step (1). create IB Outlet for all objects . step (2). write code in .m file like Language setLanguage:@"ar"]; **I have already done this. I want to do localization without doing above 2 steps. Thanks – Ravi Jun 08 '17 at 11:45
  • No you can't do – user3182143 Jun 08 '17 at 12:00
  • There must be something better my friend @ user3182143. I am trying again to achieve this. Apart from this it will be Great!! if any friend already had OR found some better solution for my problem, then please share to me. Thanks Guys!! – Ravi Jun 08 '17 at 12:28

1 Answers1

0

You can achieve this using User Defined Runtime Attribute. Follow this link for detail.

Harshal Shah
  • 427
  • 3
  • 5
  • @ Harshal Shah, It seems your link only works on Mac OS, not on iOS. In my case it does not work. – Ravi Jun 08 '17 at 08:19
  • https://stackoverflow.com/questions/11779881/localize-a-view-within-a-storyboard-using-user-defined-runtime-attributes – Harshal Shah Jun 08 '17 at 08:57