2

I want to change localization on the press of a button in my app

i have read this and this

I am changing my locale from english to hebrew and vice versa (LTR language to RTL language)

my layout is designed in such a way that it uses constraints from interface builder to determine the direction of the text and text fields.

If i do what these posts say, i get localized strings, but the constraints dont change, because the app needs a reboot to update the view direction

how do i make it update the view direction as well ?

Community
  • 1
  • 1
Lena Bru
  • 13,521
  • 11
  • 61
  • 126

1 Answers1

0

I was struggling with this issue myself once, however I couldn't find any solutions to change the locale without restarting the app.

What I did was, I had a setupUIForLocaleChange method in every UIViewController. I call this method from viewDidLoad and I also send a notification everytime the locale changes and call this method. By "local change" I mean I had a manager with a property locale. In my strings file, the strings have prefixes like "en.myString" and "es.myString", and I crated a macro like LocalizedStringForKey(@"myString") which returns myString with the current locale. So I setup all my labels for the current local in these setupUIForLocaleChange methods, and you could do the same for your constraints as well, programmatically.

Hope this helps

Levi
  • 7,313
  • 2
  • 32
  • 44