Kodeco Forums

Internationalizing Your iOS App: Getting Started

In this tutorial, learn how to prepare your app to support multiple languages, including regional numeric formats, rules for plurals, and much more.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/250-internationalizing-your-ios-app-getting-started

Hi Richard.
In “Internationalizing Numbers”, I cannot identify theses parameters: “formatString” and “period”:

String.localizedStringWithFormat(formatString, quantity, period).

It’s not there in MainViewController on initial code project.
Maybe the initial code project is different, because that line (below) not exist in the project.

salesCountLabel.text = String.localizedStringWithFormat(formatString, period)

Could you help me please ?
Thanks.

Hi Marcio,

It looks like you may have missed a step earlier in the tutorial. You should have added:

let formatString = NSLocalizedString("You have sold 1000 apps in %d months",
                                     comment: "Time to sell 1000 apps")
salesCountLabel.text = String.localizedStringWithFormat(formatString, period)

As the last step in the section Separating Text From Code, right before the section Adding a Spanish Localization.

-r

Hi Richard !
Sorry about that. I really missed this step !

I’m in a real marathon of Ray Wenderlich’s tutorials.

Thank you very much !

Hi Marcio!

No problem at all. I’m glad to hear you’re spending your weekend with us! I hope you enjoy the tutorials and find them helpful.

-r

Why are you bothering with the NumberFormatter? If you just leave your format string as %d instead of %@ you can directly pass in the value 1000 and the right format will happen.

Hi gargoyle,

Right you are. The use of NumberFormatter is solely for teaching purposes.

Richard, thanks for a great tutorial.

There is one specific task that I find very confusing tutorials about: update of localized storyboards. Seems like new outlets are not automatically appended to the localized files. Sadly, after following one of such tutorials, I had to erase all localizations from my projects whatsoever to start it again.

What steps would you recommend? Thanks!

Hi Roman,

There actually is a solution, though it’s not nearly as straight-forward as one might hope.

  1. Make your changes to the base language storyboard as usual.
  2. With the storyboard open in the editor, go to the File inspector, Localization section, and change each localized language from Localizable Strings to Interface Builder Storyboard and click Convert in the resulting dialog box
    55 AM
  3. Now change each of the back to Localizable Strings and click Convert.
  4. All of your new localizable elements will now appear in the resulting .strings files.

As I said, it’s not as easy as one might like but it beats starting over.

You might want to make it a little clearer in the description? Somebody just learning about this will assume that’s the way to handle numeric data.

Richard,

Thank you for the tutorial. One thing that I am missing, and am curious about is how to manage content from a backend server, i.e error messages. Do you do the Localisation in the application, or on the service?

There really isn’t one definitive answer. It all depends on how you want to build your client app. If you want to be able to display content directly from your backend server, then you will need to do the localization on that server. This would mean, among other things, that you have to provide a way for the user to set his preferred language. If you’re already requiring that the user create an account that is represented on the server, that’s fairly straightforward to do.

On the other hand, if you want the server to be monolingual, then you have it return localization keys and you call NSLocalizedString(_:tableName:bundle:value:comment:) for each one of those.

Personally, I would probably lean towards the first approach simply because you control it and don’t have to wait for approval from Apple to deploy updates.

Hope that helps.

Hi Richard,
What about RTL (Arabic, Hebrew) internationalization?

Hi Coby,

It works exactly the same way.

Is there a tutorial on setting up RTL support with xibs?

Hi Kassra!

No, there is no tutorial specifically dealing with RTL language support. Most everything you need (like 98%) is covered in this tutorial. Three things of note to watch out for:

  1. Make sure all of your Auto Layout constraints refer to leading or trailing anchors and not left or right.
  2. If the app is RTL-only but the device language is LTR, you won’t get RTL support in the app automatically. You’ll have to force it manually in the app by adding the following to your AppDelegate:
UIView.appearance().semanticContentAttribute = .forceRightToLeft
  1. If you have custom views, you’ll need to figure out what changes they require to support RTL languages. All of the controls in UIKit/AppKit already have full support so this is just for any custom ones you’ve created.

Hope that helps.
-r

Great thank you. I do have one more question that isn’t covered here but I can’t find the answer in Apple’s own documentation. If I wanted to add the option in the app for a user to change the language inside the app is this something that Apple would not support and would not accept during the review process? I have a requirement from a client that they want this but I know that the preferred way is to just default to whatever language the iPhone is set to. If you’re able to point me in the right direction to what apple say about this it’d be appreciated :smile:

I have no idea on this. I don’t see anything in the App Review guidelines that would prohibit such a thing but that doesn’t mean it would pass either. You might try sending a support email to Apple and asking how such an app would be viewed by the review team.

There are no guidelines against this at all. You can force the language based on some user preference the user chooses, but there is no “proper” API to do this using NSLocalizedString easily.

There is a “hack” you could do if using a strings file and NSLocalizedStringFromTable. There is an Open Source library by Roy Marmelstein (Spotify) that you can look into that works around this trick: GitHub - marmelroy/Localize-Swift: Swift friendly localization and i18n with in-app language switching

Thanks for your recommendation. I did see this library in my search actually. So does this not require the app to restart/reload before the change takes place?