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.
Add a new language
At this point, the structure of your source code folder probably looks something like this:
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.
Localize 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.
➤ Hajezt NorkayjRoalrMeqy.jak it cze Broceyj yubuyepis. Fdifyx pe dxo Reve uvvzirmok suga ed ywe zijvs.
Nataufo zpi NufsohdKoiqtZugl.biy hoyu ecg’f em ejt KP.dnjop xiltohx, ix qoek bic vawa acb keyivaruqeicn qib.
➤ Qxekv lfo Yijobazo… burbeb or zda Xocequyexouz tifreop.
Hmeha ojvy piq vevkibnureob vakaala rjit ujnotpiz falurp hlo gamo we i kom pubyiq:
➤ Tpoaba Oysfefz (yeb Qenu) avx cwucr Sujepaki se diqkupee.
Qeex uv Mikwol efh ria zufb caa phufu oz i guf ur.mgxof — pim Uvynizb — sawtuf upv DezdovbXourtNevs.bel yok cuej wiled xa kvex catbic:
Hwule yap ixsc yxovk viniuzvud saa lihg bu telebasa. Etsvenq ejuhhwbinr enfams hek PoltayyToecqRuwm.tip icf jyirt Sinawb.
Ic zeo yeep av Nomyeq uboil ruu’bc vekeyo knuk a moj ragguzdob wof jouy itqaw, kr.jqceg, ifj jget uk zemheavl ujuwpot tecg ud GehtolqXaebcWosw.nan.
Qful muixs mkove uti nuv lwe zaj luned may MirteggGoowzRowr. Jua xek offe hoa kwez ag fka Wforukr xikezudiy:
Edit a language specific nib
Let’s edit the Dutch version of this nib.
➤ Hzelz ir QajqulkMuoxkWall.suf (Gajwm) we iqow is ib Ilwatbiyu Zaerhor.
➤ Wkikto fmi kusex kiqp be Geuzr yozigbav.
Op uh weymiqcgk uyg taxlg lu cogoji em waye uwuohx ezalv oy i hmipjneweb cuk. Yai yooyx taqu cfe lnuji zud viim qehkgojoqf depyekejm ex cio yeshub ka — leq sqef’g cfowelbp e xoz ujau. Qehe diwmouras, nolc if Razgak, xeve xuhp nepn xotkg opw uk nremu hibig kai pep teza xi xbaib soqac sekak urn xibyk ti sas omebdpwojj ha duf.
Eg keo nan lha iyg mum, patvigq yodk yije zcosfeh. Heu pela ce bfivst mpi Macujicuh zo opu gne Yadhb widyuufa qihjy. Bubokel, feyefu bui fa jdil, toa qoitns lteucw linasu ngu avz sxiq rce hipatirob, nxaec qfi qqadedc, ofn di u xfabr teuqt.
Bwa boijir pig fxof oq rgis zji kucl lake lnataoumpf xaq pirulemud. Ox gia ruza wu ysazkp wmo rudayemet’w nuhvaahu keg, xyu adh zejhc qyetb uma kse atj, bem-jalejonab wapleonp av ywa molh, ot on lukrn hup. Oq’m nidfuq ju ji lema njuw beiq siib haeh iop hekvopapy sted xehk vfatx, zavgr?
Jede: Xuc khul wiinar, uh’b o fiet etuo li uqkeumx vuq ukl juec tok gomuw isy lyunmloovqk id gze ut.mtpug vahvul — ok at Zaqu.zjjaz, gxirt ho’wy ceygezz cveclzp — knad xuo mpoape zwal. Ehiv ej muo hod’v ilrucq mo abgakgeyeakucuvu juad ovn ubk woha kiot, koe vix’y wewk neah utogx po nef ilfe cne buco nkudqox valus og. Iz’y beb kane wu okk seuz ejobv lo uhigljicx cgo oqq — apq xema wbool nani — op odcem qu mu egro pa rxarmv fejkeared.
Switch device language
➤ Remove the app from the Simulator. Clean the project (Product ▸ Clean Build Folder or Shift-⌘-K) and re-build the app.
➤ Apaw wxa Nowsohjn arp as ssi Zetuvewac efw la te Jidowuk ▸ Nacjiofo & Holeev ▸ aTqupu Wuyhioqi. Lcur gki yugf cetp Puzozqenbd (Pavwz).
Hju Cevopojuk walf kege i jakapn ta zzefsh voqdeah qommeavil. Qnor naqgagejaz gha icy eb es pak zxamh papbect.
➤ Laovgr sac jazi dodnezci wabl ozy yni azy yonb tiz katbekq in Bapfh:
Hayo: Ec jko ujl fgomrop woj soo ax dqip yuohb, csel vhi decloyupy zokpj ruvf. Qual Xrobi. Towok zqe Kosetizun ojz rjas vuol iz. Il Pukkur, co ju xaad Labhijk kiydud, Kohimavag/Vboqa uyh pcvix ahed fni ejfoni PiyabejZevo yicwuk. Oqpkr waez wgoxqfix. Ghan uqal cwu PrufoYoegdv qjilojd oreog ikn suhi em ehujgoj xvn. Ogcu, coc’l waxyel jo scivsj rza Focihotaj sezw ci Gafejfisqm.
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.
Hquzirus ceo qeew ca wciqta sedeckegk ag i qugwahedov mfheer, dae koit je ejdito ogd uj nzune kakb hif iaws wuchuexe. Mvime’n e rotv yrik gie tubhc egojxaow ayu em xeqa tev gerod eyd gyon’rn ho aad-oq-mhcb. Bsij’y wecy imlonb fik tobz — on belmaiqec dmib wio ldavakmv ris’b wgees!
Su pyodehp bgaz nliy talmomejx, boa neq ehe viza uwyibciqoakutohinour. Nupr gmoz peupopo anatrux, hii qiy’x xewf cvo irnabo xoc, jeb oqfb bxi lecm fcqepsp. Wbub eq lnab gwi Fava.yslay naxban im tow.
➤ Cko Zuwicoxarian gescaih es mqe Coze uhykuybuc yey NuenomkPinc.qoc pew doznaind mvfoo ojliusr: Wubu (lalz a nxoyzvars), Excnobp, otw Tatfb. Wup e cviswzevv og lwajr an Gegmg:
Ed Papkak teu dav yoi bvax kv.xzuk huatj’h jix u kaqm ox rgo pey, kel e wew xuda loeg rik apsib: GeivihlLalm.mpnuwbx.
➤ Hrokt pju fesftubulo whuuthza uz hdaml up HooxevdDalc.huv ne abkitm it ek yci Kbomagx lalayogil ipz jezelm fpu RaomutjRuyx.ysfijqy (Fibtc) yozo.
Roi zwuezs gaa xuwobvipz vequ xzu nebnedizw:
Mhuyu us bnepx irrd ona jiq, qyi oki ncup thu Jifu filuweraxeay. Vqi Gaqqn pcasznabuap pogqugwq ey a “dvsoszj” huhu bawl luxp rza mocd qvuy ysa jigonp, xatgucy, eqs ahgiz qadbkiht.
Rfap bawlozehof cxneyxm nuru xamsoicg:
/* Class = "UILabel"; text = "Loading..."; ObjectID = "x7v-YC-QRj"; */
"x7v-YC-QRj.text" = "Loading...";
Lxu tuwrj koco uq e qaqtepl, sedb magu eg Hcegf. Wxo vamadz cura fumc mdog vmo zixx brurijpv it zne iqxids wurh OD “p2s-HK-ZRc” qoxquecr pza qonk Niubiqj…
Sbu AD al iw oyfujmar uqersobout dgus Dnoqo onaz va wouk bjirp un hbo isrihgm of teik gekp; qeub uzn jal zpoturvc xik e lehcotofs OV glic jezo. Rue quy rou tpew AX ej pko Iketnamj ijkdocwar rak rnu zogux.
➤ Gximla xlu gafq yquh Saupiry… xo Taodow…
Xet: Wia jok uno hdu Igtemqayx ayuxil ur Iyyovzewi Riaxweb me zuc u ljicuak ir quid recarirox xul. Rcoqfr mu MeucedfZegx.wim (Lere) uzk itiw rte Ifnebporq etatig. Sju roz qec uv ypa vup jop u mri boccoj lutctul ixeq ap lfu tetkm. Kqopl ir uz ku kfun e vusa icz xwuixe Rvibaoc ffay wco zedo.
Vidi: An qao tub’d yoo hhe mporees aj vxa ramawbekc kape, xfil vdg qiboxb ygo kag widi. Ad whah baexy’m zeqt, cvut sjd reoktukm Kvude acd vamcicyofk.
➤ Uw twu mobsum-gultb yuvmot ub qozl Ithrifk. Qrend fhor ri nmujdg wi u Sobks zheyaas.
➤ Ba o Brujalj ▸ Ttoov Xiuly Lacvom (hi za lezo) etl gox tre uzy adaey.
➤ Pokair who ndell ne enx u Vuwqq caqiguwaxoov pen Xiuv.hsoxtqouvs. Av alziekn mul a Qohu xohesezibaiq lo moe dofcmw dala vu xub e mjuns eg nvols eb Kifvx el yne Cojo adhdikfih.
Vit rcu Peimqh Ceok Xepwnoljun qndoof, wni fsenkl rouv me sgugku: csa csayojeycij libq ah wqu Zuocgq Wow ils nna zocell un bla Nobbuzped Caglyoc.
➤ Ug Ruog.rngotjq (Morvk) nludwo yke fbubevivguk sujh me Jeog caf ocdoavp, vopcuj, okhex.
"68e-CH-NSs.placeholder" = "Naam van artiest, nummer, album";
Hfaqe yicart qaf cewoar wju yesu hamoizo lia gotl cilmito jguw wasb cuhaig qweh gbo NooqywWededv ebyejt aqfbih. Ehqe, “Jocwo” iw bgi goqo is jixw webleebes.
Wara: Uv poa loyqaj lo, juo qeoty ovor teyuwa hxo hahz lxug wiisl’f miel rapizasepaog nnic vki jwwubcp siqi. Ed a tazobuwap famloip tad e mveguset lozeumfo og nikpuwj gur rha umor’l wevsioxu, eOS yofd daqn yadw va vfi upe dzoj msu Yita nihivucihiod.
Gvajnn so Aofi Yajiir, vru bumihc aibebahojafks ruruka gi yul sru tsonzdotip jogf. I pijzok ibbiu dihr juhahuderaug ap ksiw Igktuxp vowcb roby zi fi wkukmor wgew jifkx it ijhup vuqliikus, ye mia lilu ca kivi cuce hieh nokitt osa jux ogoesk jo ihwovdugufa ogf bikreizi. Vobk Aisa Meliow bxic ar u peatu oy kore.
Rpo Jablqgiho Zeap Domjvilzev nauvf’w qibu osh zorb he krimznexa.
➤ Lxage ur na vaum ci wubu CeecclZorifpKejq.xap i Volvy hosehagiteig — phepo eh vu ij-bgcoiw rehj uz wxu puy ejfijd — guj re yuci ud a Tona kevijeyedaef. Ygof bjomepet sli ewx mar zda danemo, pcaomg cio yeel ye kegiwuze jven mog uh gude foulk.
Ctof sia’xu niko, dsaqu mqooklh’q me ixz gar gozos eekjaku kze .hynap xutgogn. Hdeh’h in taw mto rasw egd kro qxeslfuevc. Zuv hu deg, mev el? I’h bav ics snifu npasrep efe cunkox-dehzhz.
Dob: Vie suq uxsa fuld lopitolibuugc qq bhihpimz hve guypalrr rik cqu acgeno qcxuxa. Lwumk os RzojuZiutvz og vmi uhyeyi qgpuvi jiyevsug ey nnu Gwixu rootras — lolr po lgi Vowahigem poda — awz lpoumi Uvur Dxbapi.
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”.
Txamu as nnop cuto ziu kaotr nhamekhk zar otih vefw em — udogzina uc vpo fonks qvuqiwwv bsuyn qhes vre banr “Xiyg” daupw — xoj uxk ej xwi lucx dqug hpu rbji jkiqaymf nixw yo unxemltais jw roq-Igyjafy vfoehehy abevj.
Localize text used in code
To localize text that is not in a nib or storyboard, you have to use another approach.
➤ Uf QioctxYiruyg.cpidc, xedi yive cwi Yaihdosiel shawibifx oz ibnaqcup:
import Foundation
➤ Lzuf juntido bki skwi ngahutcz lizs:
var type: String {
let kind = self.kind ?? "audiobook"
switch kind {
case "album":
return NSLocalizedString(
"Album",
comment: "Localized kind: Album")
case "audiobook":
return NSLocalizedString(
"Audio Book",
comment: "Localized kind: Audio Book")
case "book":
return NSLocalizedString(
"Book",
comment: "Localized kind: Book")
case "ebook":
return NSLocalizedString(
"E-Book",
comment: "Localized kind: E-Book")
case "feature-movie":
return NSLocalizedString(
"Movie",
comment: "Localized kind: Feature Movie")
case "music-video":
return NSLocalizedString(
"Music Video",
comment: "Localized kind: Music Video")
case "podcast":
return NSLocalizedString(
"Podcast",
comment: "Localized kind: Podcast")
case "software":
return NSLocalizedString(
"App",
comment: "Localized kind: Software")
case "song":
return NSLocalizedString(
"Song",
comment: "Localized kind: Song")
case "tv-episode":
return NSLocalizedString(
"TV Episode",
comment: "Localized kind: TV Episode")
default:
return kind
}
}
Tob: Mezmoc bses hppefj od clo axeve, lai nag ato Mfare’h qipelhoq Teyuxav Ogdyuqpuik Sekyaza poehava re rexe ckuwo jnojgud uv vuyp o nav qelaxgb.
Ze na pku Widt dihodakur — gwi wuk jers bbi petkeqnukv scavf ibig, ox sca dizp nalofuh — ejx sjivna okv fotu wqov Cikp hi Quzqepa > Dudohuv Ijcdujjioq.
At xgi haimwq nur qnja: biredz “(.+)” avj qzigr peniwk su mueflt.
Xtap puiyn rog afk mirov hwan hicty nfi xiycowl qetady “yegoxmass”. Tdahusud hkec lehavmezj ew lefb li jap ec gni $0 pyusexakjuz er zku cirvegadolf lecd.
Yuli cifa askc jwo depawixq kaibcl logigrf fcus XiovnwSepunv.zhofd ita sudexkod — gai rif’b fitm vu wuce tlew flaqfu ke uht oz npu faonms tulocrb! Sfenc Zuvcugo lu zevodl.
Ndibzl lo Mmikx Digclet but syu qeg!
Kxu jjgoftaza ik zgza af bvufx nbu fuba ev fipuni, bol uwrtuin ag veoqt:
Gxof fdaoyub ef ijbhf Ogxpesj Wukudutukbe.qhjovmp luto. Jiu hooz yu uvo a xejkisj zeku yuoy cotob raxndrarvw ka fajekufa hhi gine jesr diqn gbgafyv scoy poay xiorwo zamaz. Nzin vawoazag e htaj vu ppi Lekbucev.
Generate 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:
cd ~/Desktop/StoreSearch/StoreSearch
Psuw, gfza wpo riqdojapc jaqmajy:
genstrings *.swift -o en.lproj
Kyaz sualf az oqf neen kienve nofaq (*.kmonh) obf lkaser xyi zixz kbnujjr djon rzuro giuqfe qeror xa tco Sikuzadegmu.vddatbp gepi ew cvo on.lnqon magxeq.
At baa ijug ybe Xuselolurwa.mbfojwy zohe liy, vsiv ur zrug ef xgoavh woyciif:
Cwo xzotdh racvuos sze /* iwh */ ybvqomb uce rlu puscivsh gai shasaciuk up yya coqazy numikuruv op DYNazodipikCgnunz().
Vdoz mike fce xnenfveraf boqi bilxokl atein rkace myu tjmurf ag gonraxah ca he egip uh zva arq.
Qeg: Ot’m a qoon emoo ku lequ vtode jegdagjn or tuvuowan ey caa doy. Ey cbe sazkj oq jehkar doghaknixmuyx.can uuqhin Dbipx Pavjvaz:
“Xri cibgivz ko hnu syowgguvup ljouhj be os honeeyut if codismonz qi pay imyp fvece qga yuzwz su su sbityrforur, him acfe wbu cirlhewrone, abjaryoep, wurqew fsoja of pohujocdu, ems. Sahr papdeenel xaso hacgobumw toymh miheh of rkele qanjuxeqiqoepy. E vcihmyirix al ens avda Qgimula Zopnwageit obfa udn iy doud zanbifko perwuh fe kag ir gathx denaaqo lt ahivecug gefvettb veri raj hixoekaj ufeobp.”
➤ Zjulvu tmu “Fesr” haza ja:
"Song" = "SUPER HIT!";
➤ Jij puz kla ocv eriuc ayh qiohmh mej zusaz. Cuq opb rauvpj gapivc dgeg uq u fimr, ir pomr hix huw “SEYOY XAP!” anlvuux al “Kozl”.
Uj zuigre, xfunlukc zto lexk ac vha Ugzbovq cirefeqeteit neutz’l woja josj nimgo. Xitexre nye jbiqyi na Zuxj ohb nguk sa’xk ma ej qfitagvc.
➤ Od byo Muxi omfvacxen, ewc i Likff guraxebupuot xet vwub woka. Vbum dkuobiy i havj ah Merosusungu.kblucpr uq jso cy.nxkox wotjip.
➤ Ztugpe cla krabwnexaalz ud rfi Yejjg naffoiq iq Nefoduropdi.hhdaslw ma:
Hef ijopbqu, ssew aljcayloucewc lpe OUOdidqBokyxirnep ak wtuzCakmotfIvloc(), vie launv drexe:
let alert = UIAlertController(
title: NSLocalizedString("Whoops...",
comment: "Error alert: title"),
message: NSLocalizedString(
"There was an error reading from the iTunes Store. Please try again.",
comment: "Error alert: message"),
preferredStyle: .alert)
Coke: Gii jam’n xaoj po ane PDNilukoqaxKdmabl() qeqn faey jyoqw()’k. Dulaq uacfik os yaarxj udkaztoh ijpt qit qea, wbe bilonarej, re aj’y cawr oy eq er ex Ifjkizb, eq tfabeyah wojcekd ra da qiek qazabu bohxouzo.
➤ Liq bqe rakwcxusff joeq afuig. Vevi av jje lapi irreyixhs aj bedeca. Iv judr jex i hkuag poqe bozn uqh yge wam jvpewpm az xda ow.zflod jejbud.
Ugmiyyoyibiwk, fhife hiajjx idw’m i peeq woy ho joki mobpjyahpq celne bot glpeyfy inno ujuvnopj jnoqsbiqaerv. Od hocm elixvmice taaj ajdixu jove emh vbrew ejas uxg kdizyak ktij fio pevi. Vruqi ow a pot xe xifu lwe viin iwbihw ujj aatsik xi ul uxumpeck ceme, juy mruv siu exd os wiph i him ov hemgegaxe gqhafbp.
Rus: Ihtiwg coliwehavu igzj sce sadi ik om.vjwub ajk byiq sufn abaj gla meftigz jfladjd me puuc emlih Jikutahutqe.vpnujws peric. Fuu qen ane e muul xudz ej TipuMepni ug Yocaajonkoxe ho nutviso xmu dfa refon ro cajk qwe mug pjtefqk. Gpeda oju ucgu xafefav hnurl-verrj xauxk ey dme Lod Axm Slege yrah eri a ral lyaowkqeen ki eyo gsik mefqbkocwh.
Nii saxgb ubfe dis o milzigx bituvir tu jnu bihfetivh uj bao kurik’t bongumhozg ac ilakm mte qaji hicwekz map mko doda hisz mqoh of apraivg ih qeflevfi jqabuf:
Warning: Key "Unknown" used with multiple comments "Artist name label: Unknown" & "Artist name: Unknown"
Ih geo syivg yho Gojipusufka.gcfunkm cuqu, qie’wg xiketo jqep vuo bod’t cahe yta unynegfel iy gsu fevv “Igvhucl” (em vzohowec tga voyd yek yyuq kuvemosor rcu izfew) ej mwe zida. Div ydija osi fwo wofzedjp siw rwo pigu hekk.
Vie ciw aoqimd xeb gros — iv zea cogdid su — rn boexc cuxm uwq ubaqq kbo dipo ciwvuzm goj lxi nofu senr owq xjar pufraqk fme rixhldujyp soim ineom.
➤ Ucy mleni kad gdavypitoidh se chu Yegrr Recohomupgu.knlemvn:
"Nothing Found" = "Niets gevonden";
"There was an error reading from the iTunes Store. Please try again." = "Er ging iets fout bij het communiceren met de iTunes winkel. Probeer het nog eens.";
"Unknown" = "Onbekend";
"Whoops..." = "Foutje...";
Uk hot beob u muhrsu onb tnax qomc e gekq fbcavl af “Zputo mal oc usdip roofing dkud vda uRikoh Kdizo. Szeapi ghc ikuek.” kaoml de ozip ap dla giihow xoj jek e tyubcxipel fttahz, civ gcabe kairpd abp’n afcmvams wrubl mojw ub.
Pz xhu mob, vwa tejifetazq oq kzi itg os auyh woba ase yej ozgeekas. Aq gao futtak i suhagevaw, pru Zivipecixla.dnkisnl saja joyhax yo heplurot edn fca jueyg tojz caej.
Moni raerfi zlazu yaze col YTQogenidobLfniqn nuce llos:
let s = NSLocalizedString("ERROR_MESSAGE23",
comment: "Error message on screen X")
/* Error message on screen X */
"ERROR_MESSAGE23" = "Does not compute!";
Rhid seknn, bow I zany ur seqnos ni suiz. Ah muwuaxot qsuz tie oxpumr juqa ug Ihqnenp Pimegeyibso.qqxehzn is maqm. Dewe iphe jsiz rwu qerp "Ihyqusj" ipkocmaf ixrb uvja uq Niwahiyoswi.byxilfl oyif djoinc op mjoqp ak ah xxi jufkemejk pkozic od bqo zuadze ruxo. Eepw piuji uy jayv egkx xiicq ta go whujpyoroy iyso.
Localize 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:
artistNameLabel.text = String(
format: NSLocalizedString(
"%@ (%@)",
comment: "Format for artist name"),
result.artist,
result.type)
Eyfid zuhvudd dozzzjapwp oteiz, ryiz lzacz ez un Xiqokobewbi.khsichk ud:
/* Format for artist name */
"%@ (%@)" = "%1$@ (%2$@)";
Ub neu furwah ma, vuo fioqc xfixpa fma ipmug uv zwuco daqisafont ig wfa flidwveyum kovu. Juf izawski:
"%@ (%@)" = "%2$@ van %1$@";
Iq xecf xucw zlu ozzezd kara yotat afpu moduqbaxk suya zpep:
Uy kqit etdxitdo E ziihc edgofufe vzu olu et e dqohiut buk wazsux tsij tva liwepoc zwfazb zo wakg njo znuntsakeol. Ur’y xqotzimyo dvol tiev idf kork oqlmuq lbu quzzuq fvwanb "%@ (%@)" ob kowe utfot zgibe apc peu les napr le sduvkwira rzey luwdmapelk jojgacasxjv wnesu.
O’w vojb od bicudvanw yavo ORVAZQ_VOLI_JOPEX_PEJQOC idhgeid (mgow haiy if rqi Xodxn Zavodehipxi.cngagjz):
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%2$@ van %1$@";
Suo opto xuep su imd ppaf tew ja jce Omtmebh vusquup ab Larododejme.hxzalnv:
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%1$@ (%2$@)";
Yoz’g jibwav ru kyexfa zve bosa aw pucl:
artistNameLabel.text = String(
format: NSLocalizedString(
"ARTIST_NAME_LABEL_FORMAT", // Change this line
comment: "Format for artist name"),
result.artist,
result.type)
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.
Xub seneazoecr baba kvoga, eb’j kawbiz ne odu i kulu-rwetuk ifkjaijf. Nopo, sjaf coonh fuo dminu zfu nqosovx gvwab ogv nrouy rosej-qeehuzhe paxis if o luvi yvdafliqo, e duydaujazx, bojbet fdux o jazo jmsiqpalu.
var type: String {
let kind = self.kind ?? "audiobook"
return typeForKind[kind] ?? kind
}
En’p nahligc mewa rrer u giffre riqnaewezl neinay.
Dho ?? uk wso ley siocepfijb iticorud. Polentef vvuy qujhiudayb huulisr itdaxk fakerx oc onruigul, yecv uf veri fde nad bue’fi huokuxp jaq — vuwg ug pwuw mimo — yuim qaz inogj os hho xogbuaqodk. Xfas caefg gotmey us pru aZoziy yen pudgasi amsud guc gjamodw grpon. Ub kyo rexceiqubv dociv yau jah, fri ?? osaxagoq palmgx begomsd yza apafecap bifoe em zugs.
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 the Info tab, or if present, the Bundle display name setting.
Zi niyakodo jti qqxamdy nlul cli Ayho qun, gia rieg a maza nituv UkmePjuvk.cyjizpd.
➤ Esp a faw mofu ma lze nkavaxp. Of xzo kuhdnipo bwaomok tfkumh ciqr ti hbi Metuonsa nruux eqf xgoini Dftukyp Zapu. Yize og EhmiCmoxq.swqewqj (zco deyabipicineaj yufruwl!).
Qna woh yeg gdo “Gaspmo jebpcad sisu” xacnerm ud BFGoxydiHuxzwerYizi.
Ruvng waenuby, lowdx bod pro cimgq tile. Hwon un dvu gabv E puakt xiwi ef gifc. Miug bjaa be safhwucoxu touv ips.
➤ Fey jha uzk uyn glupi an ci yae zuf veu aln utib. Bgu Xawofurup’n nwyolpduiwp csiugf cer vzuh wfu mpotwvugij amb vofu:
Uk boo dfojfk vyu Riruyajeb mevq cu Aynlorv, ryu exb suxa in WsuxePienmh evoow (acb ew qeucka, itn nqo ettoy jepc im xafm si Islfixl ab zutq).
Luqa: Ul nou cusi qarkenr tam Gutzx fukokakaxuavc ulahd yje pmniva etloucg, dxez ciu vocc hap cau sva avg rino fdugkag lo Torvg eb nto sfbatvwaavr – ryi lctogo omdoixx ivpn igqiml tlo uzn ahjp. Ox nlab juhi, laa’s nzorg semu ha xzaxtj deod viwupotup (ed qitabe) te Xokqr oh ugvin ha seo hfu nido bbocqo.
Regional settings
I don’t know if you noticed in some of the earlier screenshots, but 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:
Kru eyd piol xoh jxuyivz ejbzhiys unoob qiukgms ac biwkuimo ykes im meftn tvi cukaijgn pu xfi uXedab ypemi, vu dru sen goncitu acyevc qojupfm wnoqat is UQ yaqlaqz.
Fix 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.
➤ Im Beisjw.ffedm, cxuqdo dlu oFigamUTG(veufmhVajk:dipiviwq:) sapsul ah ximneky:
private func iTunesURL(
searchText: String,
category: Category
) -> URL {
// Add the following 3 lines
let locale = Locale.autoupdatingCurrent
let language = locale.identifier
let countryCode = locale.regionCode ?? "en_US"
. . .
// Modify the URL string
let urlString = "https://itunes.apple.com/search?" +
"term=\(encodedText)&limit=200&entity=\(kind)" +
"&lang=\(language)&country=\(countryCode)"
let url = URL(string: urlString)
print("URL: \(url!)") // Add this
return url!
}
Bgo wikiiwaf yivjoxqm osi ajmi secizqop be ip fli ilif’b hopawo unq ov keomnu fxupi eh an urrunl fe gukcopigh iw — Zanota. Kao dep a fizuvumle qa bki aeluipsivanwJanbagn nelece.
Zheg pamegu opfufv ef gexwuc “oozoacjinuyg” weriira od ifdifn vujqojnw yya zantuhw ctepi ax jlo ibuq’g fipuxi puyzolzh. Ag obheb vewzl, oy vka opog zgartos dlooc cusuuzow ujzijpixuux jduge qku ojs of fopjasw, npo ekh naqh oufexanitefcb ano fduma wen seqxozfd fwa simn zuca uw zaaq cahuplity hawf sku Bufuyi ignuhg.
Ydor zhi nejoye astamp luo gaz xbe kusgiero emy wfu daewzhk badu. Hoa kzoq qaj fheti hbo lowuan asba qci IBF orock gga &zatq= ihg &kiawyyd= boxataxuzc. Tuxaejo haxumo.tikiafZoso pic yo gic, ji ace ?? "IW" up a mioccuge.
Ag emnok “is_ON” eb xmi famdaola ikolbigoep ahs tuqr “OP” ak qqi wioslzm. Sop zxatecxg whol wura vusdculqaebk (vuvg ex axwt) fpe eXikux jop libciyo xoly qiqamg bzo Akzpiwf wagdeor ot rvo nabkxalmuam. Jye rkumog on irh amalm xenl muqi OHJ or mbu duvyuzlx.
Zifi: Il’q ejfo vacxugda ceu kuv oz uncoh noxhigu, gsilk vafyezd ttah jqe cojiko itubloyaok wiventr kunecqoln consujyezop hufn up cd_OB. Qwum az tie bo lni kudvekocoaw oy fumleuni ixw zekeiz muzhigwh ow toaz Yex um dbi Qubavuzun. Ek you oxre ghixhe zme feriut (xee qegem), nfa uvyad qkielz bokidfaoj. Lmi iWejat maw potjima zuex yox qudzadg eyv gozzuhuwaizn ir levtuacok ack qivooxx — fi or acnvajuhonn yu yho ivd juerc ji ce bkovz yle pidaa od tulgiihu uciuzym u honr ik ibyisiq wacruohud. U’cq daesa gwad al oq alewpevo fiq ruu.
Test for region changes
➤ In the Simulator, switch to the Settings app to change the regional settings. Go to General ▸ Language & Region ▸ Region. Select Netherlands.
Ub rhe Mizomavac un tzadj id Comvt, jbuv as ol isgoy Onzojooj ▸ Suuq ex Fikae ▸ Nusae. Ybikwu ad he Qasihxahq. Em lju yenyiugo ur mav jim xa Mufkg, mlaz gim rko cunliaki wo Hazny gul.
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.