We are building an application with dynamic data that we wish to localize. We know how to localize strings in iOS and Android but in this case the data will be downloaded dynamically from the server so we will need to download the localization files dynamically.
Usually we store the strings files inside language folders. how can we do that when the file is coming from the server?
To add Localizable. strings file, go to File->New->File , choose Strings File under Resource tab of iOS, name it Localizable. strings , and create the file. Now, you have a Localizable.
A localized string can have different values depending on the language in which the project is being build. There are two categories of localized strings: the strings included in the installation package's UI, common to every MSI file.
Select the project and under “Localizations”, click the “+” icon. Add any language you want (I selected Italian) then click on “Finish”. Now go back to Localizable. string file, select it and on the File Inspector (right menu) select “Localize”.
Click on iOS->App/Single View App->Next. Name your project and select the language as Swift. Select a desired location and click on Create. To start with Localization, click on your Project Name -> go to Info Tab -> Under Localizations, click on the '+' button.
how can we do that when the file is coming from the server?
You can't because the app bundle is not writable on iOS devices.
There is, however, NSLocalizedStringFromTableInBundle()
, which lets you specify a different bundle from which you can load the .strings
file. I haven't tried but I suppose this bundle can also reside in your app's Documents or Library folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With