Alok
Alok

Reputation: 25938

Add new language string file dynamically for localisation in iOS

Approach I have implemented localization using string file as given below: enter image description here enter image description here

Question

Is this possible to add new language file at runtime?

Upvotes: 1

Views: 603

Answers (1)

Alper
Alper

Reputation: 3973

You can just create the proper bundle directories and strings files yourself and use the longer version of NSLocalizedString.

An approach is described here by Alejandro Martinez:

// The two important new parameters are `tableName` and `bundle`. 
// By default when using NSLocalizedString the system uses the App 
// main bundle and the Localizable table, *table* meaning the name 
// of the strings file. So to hook into the localization system we 
// just need to convert the object structure that we have in memory 
// to the proper file hierarchy that is expected on disk.
NSLocalizedString(_ key: String, tableName: String? = default, 
  bundle: Bundle = default, value: String = default, comment: String)
  -> String

Upvotes: 1

Related Questions