1

I have tried to follow the below link to achieve localization .

Tutorial

It seems not working ( only English text appears )

My requirement is to change the label/button texts etc. to be changed from English to Arabic language and vice-versa on a button click inside the App. I have already have a translated Arabic strings available from the client so I dont have to use a translation ( import/export - xliff) . Created 2 string files for English and Arabic separately and calling it ViewDidload() event checking the User had opted for Arabic/English Version.

Please note that I'm trying load the languages dynamically when user clicks button inside my app . Not by changing the device language .

For ex: Localizable.string ( en)

"Details" = "Details";

Localizable.string(ar)

"Details" = "التفاصيل " ;

retrieval:

btnDetail.setTitle(NSLocalizedString("Details", comment: "More      Details"), forState: .Normal)

But its showing only english but not Arabic when I call in buttonclick event to change to Arabic.

Please help. I m new to IOS and Swift.

user2695433
  • 2,013
  • 4
  • 25
  • 44
  • 1
    What are you doing to try to get it to Arabic? Localization only changes the language if the device is set to use another language. This means that you have to set your phone language to Arabic to see the Arabic version. _However_, you _can_ change the language in-app without changing the phone language. Is that what you want? – Arc676 Jan 15 '16 at 12:50
  • Thanks for repying. Oh no... was not knowing that part. I'm looking to change the texts and layouts only to different language on User clicking ( in-app ) only. Not when the Phone Language settings changed. Can you please direct me on how it shall be done? – user2695433 Jan 15 '16 at 12:59
  • See [this answer](http://stackoverflow.com/a/6150635/2773311). You have to restart your app after changing the language though. – Arc676 Jan 15 '16 at 13:03
  • Possible duplicate of [Change iOS app's language on the fly](http://stackoverflow.com/questions/6150576/change-ios-apps-language-on-the-fly) – Arc676 Jan 15 '16 at 13:04
  • Thanks a lot . I will give it a try. The screen can be also flipped ( rtl ) ? – user2695433 Jan 15 '16 at 13:10
  • I'm not sure, I don't speak Arabic and I've never deployed apps to regions that speak it, so I've never tried :P See the official [Apple documentation on localization](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/Introduction/Introduction.html#//apple_ref/doc/uid/10000171i-CH1-SW1). I'm not sure which page it's on, but there is something about RTL somewhere in there – Arc676 Jan 15 '16 at 13:11
  • And me using swift 2.0 and AutoLayout instead of Objective C, will that have any effect ? – user2695433 Jan 15 '16 at 13:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100767/discussion-between-arc676-and-user2695433). – Arc676 Jan 15 '16 at 13:13
  • Yes, me too have no idea, my client have supplied translated strings which I m supposed to use :). Checked the Apple documentation , but there also they have mentioned about using Localization ( the device language settings to be changed instead of changing it on the fly programmatically ) – user2695433 Jan 15 '16 at 13:14
  • @Arc676 I do not agree that statement "However, you can change the language in-app without changing the phone language". I still haven't found a success story with a maintainable way to do that. For instance if you integrate mapkit and show a map, even if you change in-app language using those tricks, information on map are still shown in phone language, other example is reverse geocoding. If you have evidence of the opposite please share. I'd would love to be wrong :-) – Andrea Jan 15 '16 at 14:14
  • @Andrea My solution (let's call it a workaround) hasn't been tested on any sort of map. It only helps to retrieve the correct language with `NSLocalizedString`. If you like, we could discuss it in chat. I'm not familiar with the standard process here. Should we continue with the already created chat room or create a new one? – Arc676 Jan 15 '16 at 14:16
  • @Arc676 don't worry I'm at work can't chat. I always tried to find a solution for a full language change in-app and still looking for it since I never found one. No big deal. – Andrea Jan 15 '16 at 14:19
  • @Andrea The workaround still requires a restart of the application. My way of doing this without intruding on UX is opening the settings page and closing my app during the transition. On iOS 9, the "back" button at the top left makes this quite seamless. An alert that warns the user of the loss of any temporary data in the view makes sure there are no "surprises". However, this is getting off topic. If you want, you could propose a time when you aren't at work. Specify a time zone though :) – Arc676 Jan 15 '16 at 14:25
  • Hi, yes, please use official localization APIs, and yes, the screen will also be flipped. Language changes in-app are not recommended, problem-ridden, and are not 100% supported. You will always run into issues like formatters not obeying your custom-set language setting. – wakachamo Jan 15 '16 at 17:20

0 Answers0