iOS — Localization (In App — without Re-Launch)

Localization is present in most of the iOS apps now a days. In this story, I am going to cover specific scenario where —

  • App has “Localization” option in itself
  • And App Content should be updated instantly without asking user to Re-Launch manually
  • If you are developing a framework and want to allow app developers to override strings used in framework

We will be using Swizzling for this.

Lets start with LocaleHelper class first.

Download LocaleHelper from GitHub

Add this class into your project and move to AppDelegate class. Add below code in “func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool” —

LocaleHelper.doTheSwizzling()

And Thats it, you are done.

Now, when user changes app from inside of your app screen — You can update your app language by adding below line —

LocaleHelper.setAppleLanguageTo(lang:<LANGUAGE_CODE>)

Now, to reflect changes in app, WITHOUT MANUAL RELAUNCH, just reset your app window to your App’s initial ViewController —

appDelegate.window?.rootViewController = targetVC

You will see that App Language has got updated and its LTR / RTL has also been updated.

LocaleHelper class has Stirng Extension which you can use to get Localised Values of Any String. If that String has been declared in lproj files, then respective value will be returned otherwise that String itself will be returned.

<STRING>.getLocalisedValue()

If you are using this inside any framework and you want to give your framework consumers a feature that if they want to override framework strings, then they just declare those string keys in their app and give required values. In that scenario, framework will start picking up strings from consumer app. In framework, you just need to make sure that you specify framework bundle in method call “getLocalisedValue”.

<STRING>.getLocalisedValue(targetBundle: Constants.sdkBundle)

Thats It!! Now you can have Multi-Lingual App, which doesn’t need to be re-launched manually after changing language from app listing screen.

--

--

--

I believe in modular development practices for better reusability, coding practices, robustness & scaling — inline with automation.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Python Multiple Inheritance — Python MRO (Method Resolution Order) in 1 minute

Host your static website in AWS under 2 minutes with S3 - sithum devops

Usablity, Accessibility, and Ethics: Grammarly

Module 1 at Roots Technology

Leetcode Problem 543 Diameter of a Binary tree

Jupyter Dashboarding — some thoughts on Voila, Panel and Dash

Making a title menu Unity

Inner Sourcing: The Ups and Downs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rakesh Chander

Rakesh Chander

I believe in modular development practices for better reusability, coding practices, robustness & scaling — inline with automation.

More from Medium

MVVM-C Xcode Template to reduce development time

iOS: How to upload photos and videos to Firebase Storage

Introduction to Swift UI

Build your first WatchOS App with Swift — Counter App