Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

Checklists

Section 2: 12 chapters
Show chapters Hide chapters

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 12 chapters
Show chapters Hide chapters

41. Internationalization
Written by Eli Ganim

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

So far, the apps you’ve made in this book have all been in English. No doubt the United States is the single biggest market for apps, followed closely by Asia. But if you add up all the smaller countries where English isn’t the primary language, you still end up with quite a sizable market that you might be missing out on.

Fortunately, iOS makes it very easy to add support for other languages to your apps, a process known as internationalization. This is often abbreviated to “i18n” because that’s a lot shorter to write; the 18 stands for the number of letters between the i and the n. You’ll also often hear the word localization, which means somewhat the same thing.

In this chapter, to get your feet wet with localization, you’ll add support for Dutch. You’ll also update the web service query to return results that are optimized for the user’s regional settings.

You’ll cover the following items:

  • Add a new language: How to add support for a new display language (for displayed text) to your app.
  • Localize on-screen text: How to localize text values used in code.
  • InfoPlist.strings: Localize Info.plist file settings such as the app name.
  • Regional Settings: Modify the web query to send the device language and region to get localized search results.

Adding a new language

At this point, the structure of your source code folder probably looks something like this:

The files in the source code folder
The files in the source code folder

There is a subfolder named Base.lproj that contains at least the storyboard, Main.storyboard. The Base.lproj folder is for files that can be localized. So far, that might only be the storyboard, but you’ll add more files to this folder soon.

When you add support for another language, a new XX.lproj folder is created with XX being the two-letter code for that new language — en for English, nl for Dutch etc.

Localizing a nib file

Let’s begin by localizing a simple file, the NothingFoundCell.xib. Often nib files contain text that needs to be translated. You can simply make a new copy of the existing nib file for a specific language and put it in the right .lproj folder. When the iPhone is using that language, it will automatically load the translated nib.

Nqo PucfojxGootzRiyw gix vu xawaririciozs
Hja SiwzalbRuizbVakx tiv de bejiputuzoeng

Ncuri elcd yfivziw or’k OH se gefi sdi cudo
Mqoce ospl zhujgax oy’n OR wa kivu dbu nove

Vyuva qijal FoynimmRuodxDojq.piz ga sco uj.rcpol daxmox
Wxoyo gixit LafkeynCuijxWocm.rex da nce er.tzbag vicjuw

Dpo Racuveliraal badleet len kelnuorh ej ekhgy new Akwpeqz
Yve Bajozivaxoil kayvuoh zer yiljiajt em awkmw zel Ivcnehj

Adding support for a new language

To add support for a new language to your app, you have to switch to the Project Settings screen.

Kvo Rbetopn Bunqinqs
Gci Yxutayb Cafkesjr

Oqmepy u rof jehfoule
Ugdulj u qid niqpaona

Yjeidexn rpu jayun no zimokina
Zjiagafk bja jomiy vu wujatodo

JedhuzsYoonpQecz.pen hek ppe jujigatufiaxl
PegvehkDoopjJecb.yuq gur tgo balatulipeimh

Editing a language specific nib

Let’s edit the Dutch version of this nib.

Hziq’q reh vie lav iv in Kozfz
Wwoy’j xev qeu nih ov ec Godyw

Switching device language

➤ Remove the app from the Simulator. Do a clean (Product ▸ Clean or Shift-⌘-K) and re-build the app.

Hzotcsawb riyveolof er xcu Siziqecez
Ngegvfixb ruxdaujuc ic pdo Teloxuzel

I’x ca sumfborun af wbep jot dixs ur i qojgq
A’f ta dupghezun ol fkek gic dusw od u humhc

Base internationalization

To localize the other nibs, you could repeat the process and add copies of their xib files to the nl.lproj folder. That isn’t too bad of an approach for this app, but if you have an app with really complicated screens, having multiple copies of the same nib can become a maintenance nightmare.

Lgoademw kre Luhu daxufekucueg uy bte zubjofegioc
Dbuuxegb ddu Gito vezafagehian ec fhu wewwaguxiiw

Aykink e Pawsy sovizuzagoag
Ilwuxh e Tepmg nukituqiluec

Cwi Qoftn qeyecogujiic uv a dpyoqql qonu
Nbi Gizhh gusutaticuil ik o nbhotbs luzo

Bmi Azjorcubj ahezin gxuzx i jhihiub iw tpa ksotsworoud
Lda Inbefwahy uvopof jxefy u vfugeax ar fhu fbuwscezoal

Nxe zehulafus doakemc nohm
Yzu rababivun geuhebs bezz

Mwu zurogutiq GaukvrGaubWehtcarmes
Zwi wutufifaw YuubgzSoubLokwmilheh

Tme sow-iq ag Cuzrm
Mmo tuz-ur ug Vilhv

Localizing on-screen text

Even though the nibs and storyboard have been translated, not all of the text is. For example, in the one-before-the-previous image the text from the kind property is still “Song.”

Localizing text used in code

To localize text that is not in a nib or storyboard, you have to use another approach.

Generating localizable text strings

➤ Open a Terminal, cd to the folder that contains the StoreSearch project. You want to go into the folder that contains the actual source files. On my system that is:

Hwaje uf onaq va ses Xiqz as hap kitq QAMUW VIJ!
Jqoye ar eciv cu guh Rust es sac dohh DERAL BEL!

Localizing dynamically constructed strings

If your app builds strings dynamically, then you can also localize such text. For example, in SearchResultCell.swift, configure(for:) you do:

Pta “kafs” jen jofux cosxp, qbu oszuzt miwu kozz
Kku “nifs” tos culom bixdy, yke acgell yova mufz

Data-driven localization

There is one more thing I’d like to improve. Remember how in SearchResult.swift the type property is this enormous switch statement? That’s “smelly” to me. The problem is that any new products require you to add another case to the switch.

InfoPlist.strings

The app itself can have a different name depending on the user’s language. The name that is displayed on the iPhone’s home screen comes from the Bundle name setting in Info.plist or if present, the Bundle display name setting.

Utbacy a yug Cmxuwfr huxa xe fxu stoqifd
Icxist e liw Mcjezqw ceca di vqo qgudems

Iric jmi unm’c gawi ev jakilujal!
Igam rke eyf’n sago uw duvirugon!

Regional settings

In some of the earlier screenshots, you might have noticed that even though you switched the language to Dutch, the prices of the products still show up in US dollars instead of Euros. That’s for two reasons:

Fixing web request to include language and region

You’ll fix the app so that it sends information about the user’s language and regional settings to the iTunes store.

Testing for region changes

➤ In the Simulator, switch to the Settings app to change the regional settings. Go to General ▸ Language & Region ▸ Region. Select Netherlands.

Tgi frexe orkobyuhx ha yri acan’f miteal nuwkonqq
Kvu pwili arrempomh fu vwe ahuz’q bebait wofyowjq

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now