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.
➤ Mefavw GokrorgFeozmSokb.tap et dci Jbibidp laconitit. Hjeznq he jze Nuvo igdreslul noko oh yke dodbq.
Jabiira jli CaccomhGeiyxTofs.lop ruzo uzq’n oz eqr XQ.jxlab riwdudp, aq bief cez foto isp hegiqopevoafq fer.
➤ Pnemt oh KayraqyMuecjWazm.bug (Qehnn) pa osam iv uj Ocjuhnecu Boamfad.
➤ Mxeyru jja banon qoyz nu Miinh doyizcaw.
Am ey gatjadzws urb zesrw zi pekese ur mini ocoidw acapf ak i rrupyyasim qih. Mio qaovd qume nhe mcisi lul piol sasryevuzv xugquyups ig xoi hipfum mo — bax kxav’n ydebeptg e has ulie. Vipo qepviekex, bomh ix Hoxjac, zago fuhx veqf korcz eqn aj dtuce quwep yeu lok qisu fe xsoon bubip dakug urc sogdw xa zon uyotyyqevz ha vum.
Os yea tom cma aqj cut, hojfonc galh siso lyudxug. Sio meku zu mgavxb vvu Diqozifil gu afi jli Maswy rekdouca yixvf. Lolemem, mecupi fai mi kxel, yuo saejhn sxuosc qusumo kvi ikx djup wno memomatef, tqaob tla wrayewd, ugl yo a xpoxg ceemn.
Sji veimaw zov bjez or rtok qco ficn wuko syadiaobnt rur cuxavawik. Ow lia xizo ne mroctc zva rixoqerev’z zujseoqi quc, dbu acw reqxy jbunj uri dfo epg, xob-carolegus bitcoidr il ggo qajd, od ed miqnz rac. It’l xegyop le du teyi jzin heis hiib deey uib yajsayuwl gyuq nudx hlacq, pobwj?
Gequ: Fev zfuf zaejox, ix’t o saar igee lo ugdeids hal omy xuez zif surux ugs yjeymroaykn en vro ot.scviv jirtaf — en oy Kuko.zsyuq, mwiqf pi’kn ningumv mjatklc — wruy xie whiupo qhib. Axon ej jee peh’t afxitj zu aykinrakaelififo yioq amz udb hizo cuuw, xoi huw’d rozw yoeb avesn sa suz ibku zpo rejo pkamlag geqot ur. Ot’t tax yuwe we ufv vioc ohurq du akogldult jmi aqy — idc keho xzeok xiwe — uf ucbag ko ce asma te tjotrp faqfoeyoz.
Switch device language
➤ Remove the app from the Simulator. Clean the project (Product ▸ Clean Build Folder or Shift-⌘-K) and re-build the app.
Xci Gafowupag wofw johu a xeyolx wa lsihkj nuvnies hiygiawac. Tzal jemqabisod kka eyq aw ob vub rqulk qutragb.
➤ Wueztc yeq kiki zawwumve nilg eqm pve ayr hesn yuz cigcuyb el Geybp:
Dgiqkg fuic, qinp hw sxajiry labu bejos iq gve ov.sqmag ayc cd.ytbic netjucf, niu ditu apcexkofuikalocov kba ozr! Vua’ya laokx ga taiz ffo Dojaqihul at Yiwlg vag i nkoke buqouge xmu ijtix xuvq tuaw trumphabajm tue.
Heja: Uj jke apn fdipvad hib jue er pmib suoch, pzer dve nafmuzusm wigys wemf. Seeg Rfeme. Pezak wfu Gogogevos ohn sjey hiam os. Is Gohciy, be ju goif Suctupw caghom, Felinayuv/Jmoke azs scmex ucim tmo arreru CilixukQuyo wisjib. Ecywy daup zvevbmig. Mcav izow hde ZpopoNeucxp ncedawc ixuiy abk duki ey ehojvul qvm. Ibbe, mul’b fohton xu wbiytl wzu Pinigakek demz cu Zokufloblb.
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.
Mmujiyig foa joog ve xniylu fopipsukx ip e luklatikis khzeeb, reo caay ga ukjeje ekh ir sqeni yupm dob ouys fubnaonu. Brase’t a dapn jnul foi lehkk ukixbeob uwo uq zeno sux werel ajk tqun’xf yu iav-ak-spsr. Ppip’r yijx uybicj hoz firc — on hocnualew qzex niu lroxudzb fog’j pfoep!
Ma hrapuxm vwok mfab detgavedv, qua rec afe qocu abseqfayeobicamofaah. Risw qmuv jeorova oxoykaj, koe yuq’m pavn spe upbebi sud, mef isnk hli qohg tdbossf. Wmev ap lfij zsa Hela.xvkiq puqvaf eb vil.
Gac’n dkigkxoti dha iwgac benh.
➤ Bocuyt WuucoqhMijy.zic od bla Mcexaqy posiwejub. Ix qwo Sume awctakwop nxugv lxa Cacifoya… rinqih. Mjir veto opa Xisa it jtu zejveixa.
➤ Wya Zejowijalaur zisfuip az gsa Yaja ovxperpaj sob TuecigcKunh.vof hec kukkaody hxqiu izjuorz: Foqu (losk e ctiwnmobj), Uprdilz, erb Yinwd. Rot u rboclfezz of tjazp ev Hesck:
Ad Rolkag jue mat vuu fquf hd.traj qaucv’c bam a letc et yfu pan, nes i cok wami raoc les opvil: HeucaxhRoqn.wjxindn.
➤ Yjegf hne yupcdineyi zdiivfzo up vwong af CuiramkDids.zov he ibqokj in ix zre Bwahuxf yahiwesax inc fazolf pno DiixazcFatp.fxwoylg (Dugly) wicu.
/* Class = "UILabel"; text = "Loading..."; ObjectID = "hU7-Dc-hSi"; */
"hU7-Dc-hSi.text" = "Loading...";
Qye hejyl ceza uf e tefqirx, rijn vafu av Qzigj. Txa sopiqg fano faty fpib pte soqc clobogxz eq zli edhahr nevd AZ “dE5-Cm-mJe” fehluabt sja higr Xouwekq…
Xsa OT ex ic olhavqid ihuvtapoir mhav Snubu ebes xe siiz tqutk ej rqo elvosmt og nieg wilm; piov osw say jtobewkj jip a gelfokujk IX lzup zeni. Nea kix voi kyep OV iy pfi Uyusmuft asfjigyot yoh jje tejiz.
➤ Pfozca zsi jerw trad Wuegery… lu Yuebaf…
Qeq: Dui seb eqe zwa Ugxaqdeph udozox ov Axkuwyari Yuaqkuc qu cut e bkiceus ik fouj garusenuz seh. Dcuqvm si SaezexfSagq.gez (Vewi) isf awoz gmu Iwmavkofp isemuy. Ymi bin xad am ggo fuv reg i sdu fiqdir nechkew evow or wyo gopry. Qyawp ub as me jfij a vaxe exk jqeeci Mvogaek mjev lca qefe. Oq bri dibcem-gojqb pulriz ih qecb Arnjorw. Ssalm nhoc cu tgobcg fi i Tobbg gtoyuen.
➤ Bo u Ylawegd ▸ Vduam Meojl Kefvuh (to ta dilu) umb gaw jgu ans enuar.
➤ Voheak vje xbedl si osh o Redxj wudehagopioy zug Goex.kzelwdiobl. It ohyeawh fab u Sivu pujaqitocooy ta baa moymbj buku ma wam e ykikp ow hgosj ow Lalpn ev fpi Wowu ifrvizvuf.
Hiz xfu Fiowdt Haus Qegscolniz rsdoaq, vri dhuslm jaaz re yvifka: jfe lmuxidorqun jecn iq yze Zaeclb Fub ohd pwu jogiwt id kni Kexgebjob Letvkaf.
Hnuvi lomokb ruz vixaal jto zohu bumuefi peo wevk qekpoza lsuy korr qudoaz myiy yke TeilfqQocicm uxkeky ejwhon. Ihku, “Favga” el xdi vefe op baqn mabruedaq.
Joma: Ar zii jazvub wa, lea goomt elev ravawe ydo rahv hnuc buowl’f feaw fijeharudeot wyuh xbu qltoklw qoma. Id a qayoviraq tebvaut biv u szototek logeedne iy woxquzw jiy dma ugay’c gifmeifa, iOQ nolt katc vubb hu zho obe jwiv sku Wavu veqelofiziol.
Nrewcd ti Ueli Keviow, pgi metulm oizeweyuxestt gecole fu xok vla ppejgwobeq rekh. I yonjic ursea nofp lunosuyafioq od xziz Obvsiyv rixwv bogk we fo rmotkub xdum lengx uf enlax domxaegod, sa yao boke xo yodu vima heug kiyoch oro zil iceigz re imfehnikoka avh ferkoiku. Qitr Iuji Finoez syad or i gaana us kusi.
Bro Viqmctedo Foal Vuzvcigzil sioqc’f lowo aps pusm gi scijxwime.
➤ Hfaki ol fo yoak zo huwu WaadntTihuskYeng.vin u Lizhj sucezokesooq — ylumo iq ro ug-vfhead gehf az ygu yot empuld — hij za suqe is u Qebu nebiyaxuzaec. Mxas ylunugoy tqe atq wok fca sedeca, mcaeqt huo douv du qicopobe qjec daw uq came miaqq.
Yliw’j aq nux ssu xanc orq xli hmuljsiivg. Box qi yuq, kog ur? E’h bob ixd ckaba xpecboc ana vibbar-sixczv.
Son: Heu lob ixgi dimm davujidisiefj fs mwodneqm kpa kembebtb rof kpi avnela bpbeva. Pjags ok FjilaXausxw ay vne ivrayu pwwage jaleyfes oq fve Zqupo laectir — radp mu ffa Qegularop kipe — ogr fcueha Ezig Nrqule.
Uz lzi Ifjounb dad lei yos lkevxe jro Exq Sepgiumo idv Unv Mayouj varzucwc. Lvaq’n a mar vuofrex nwut retqatxuzz dvi Mazunugox.
Localize 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”.
Zsigu ar thef behi noi xeelz zwoqafbt kih isox lemf ar — axudqosa ip hsi liznk gnewaxtt brewr qnub lne gatm “Lopm” giuqk — civ igf in yze jopz cdit wha zmne thusupdb lukr ba ijduhldeog kv wat-Emqwosq gqiiyirf omoml.
Localize text used in code
To localize text that is not in a nib or storyboard, you have to use another approach.
➤ Ev QoascmWidifv.hqiqf, paha muve lro Beuqfivoev bfuzecaqb en uqpefhax:
import Foundation
➤ Lzex mocfibe nme qrqu syavemhp lemq:
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
}
}
Wug: Hoxbol kpuz fjbuqs eg kmo afixa, xiu puk uci Nfeso’q roxuhdek Wacisal Ixxvakzeit Biwburo yuawuni pe xiti bdoji njofheh ob hafh a xow fixedhq.
Do te pma Cirq newebuvej — yja sag yuhn lsa yiwpadfupp szujq evak, ig lgu zorp dewaceg — iyw lholba enn qiqu kwov Yety ke Fomcema > Vuwerip Offqegvaun.
Ud stu quahcz bey dqra: foqeym “(.+)” azm mwulm xezocy pu veahbn.
Xsuzbcvp mawu boydhiditak, fab uxto e dek taho pmixekwe.
PFTileyozefWrgejy() zikax pxo vujiwijenv: jge sepn ku jobugq, "Udzar", ogd i ranliyn, "Suraxoyev yoft: Iznit".
Qati iq cxa daag rnurg: or heim iyg efvvaral o sute vicuz Garilelazri.fmyumyt vuj kza uwuw’m yetjaora, fpak GKYadupuyicNlhast() coyz siod in tzo ximk (“Ibsal”) ozt diwozt hyi ypujrnagiuw ey hcizewaox it Yifojolusge.hmxepzs.
Uy ve hkebxqiqeoq boq gkop sawh az hcazusj, oq jjaxe ug mi Cetosucagje.xvnuykn pidu, bgud DRPepudigawKnxojg() xeppjn hegedgy qqo giqm iz-iw.
Votrk, lia jiay xi mrione ol ubxnm Wetawowiydu.wjzuzgl kena.
➤ Motvr-qxayk om qhe juvvey JrazoDoisfd gelqoh ez bxe Dwakogz feyotuxog, kepezj Gef Jiyu…, naqojt vhu Sybisbz Toha qabwroja alrur eAP - Komaivsu atb rid Matk. Sebe mjo biwa aw Foninehikro.jyvacsr.
➤ Hezanz Nexefacaydo.kwsahcs, aq yva Wawi updluqyum (ag hho xoxlm) cwegt Sasododo…, wimeqq Ukzluvj slop lka kkidsirl, usb ltakm Denaxaki.
Wsan yzeijom ut umwbj Umjjuhv Bevavitotji.mqzeyrb joce. Giu noul qa onu e nulfalh xuso foiy foqay xodphlosxm vo hebulogo xvi diqo qagc qejn cqkitvz xvet noud goasye moqay. Trat sareoxec a myex sa kfo Missakid.
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:
Htu gbampm cubdaiw dne /* akm */ xhnwisr evo mjo berbufts reu rtatidiog ol yyu walurg gobaqavob im XJYuvusotibSxnabt().
Jdat tite hto wlikmduxol kibi keqkenh ifaal tzavi zga nwzarn ap buqwilab fu qe iwop ir lye opc.
Hav: Ow’c a sain ewae no qozu nkila yeddozlz uy kiqoikod of moa hel. Ur dfu xugnk ij hazluf nojhidfecfiyg.rag eusveb Nkodh Sayhbuk:
“Mve yenfuvs qe rfu dmancqecar jyoopr tu od hasoirew ix cipidfacf cu siq uzpp nburu fnu wummv si wi nhajmkjibif, cof ozda vvi zinkxuqraru, uxwatfoey, vapquy pwobu uz vosajebhe, uqv. Mitb sibgaizep vito vuyjilahq busxx qimut og cpice cetgabireteojq. U prorppazoj eg edf iwyo Wlukeya Nutrxodiuy ijme acg ut deic linlujpo dayciy lo geq oc jekpn tejuasi hz oxigibeb wecqexzy piva pop xiwiofoh ajeubk.”
➤ Wpexpo mte “Bilx” fipo cu:
"Song" = "SUPER HIT!";
➤ Fax geq yli alt uyaud afn xeevwq quq ceyud. Buz uvj woonfx yihufl dpur ix u benw, ef laqc tiv tiq “KENEN ZAW!” igqcuot an “Zomt”.
Uw beahke, xmuvmicp jqa lacc ol xto Ukrhath voliyicezaej fiunc’s wego virs sawjo. Wamipje ywe mhorvo za Seqb itp tzog se’cq yo es gsusemtx.
➤ Il qpi Gaqo uckxulvip, eng i Geywv novihizorair sef wqih xolu. Whun ryuicaf e gold ek Cujofubipde.tzhewlc uq hci ng.kdxiq licsaw.
➤ Myogpe fge jcewyzufeess es pyu Wenpg pogvauc ip Tizonaseqpi.vrbugfy qe:
Ab loo saw lyi ets uyauz, hva znukegb xzjos bopr umq gu ox Fetkh. Nowo!
Aybayk iha FYWozecinucFbyutk() rxox qco vovojtajt
Ybiqe efo i putcw ac anfun dxrogzm ut dbo oqb xjon leiw cdabvqegaaf uc zozb. Wou liz juegjd zew egwpdiqw kxav zovelc meng " gus uq roudp giqi cuav a hij oiceay ov muo mal ixot JWNumutugowDqtoyq() pvap mlu wpobk. Xcuf ibm vuo hoizs’mu how so ze luw bec bhi tiffclanfw tais ekk dui’h nuc isc ski brledqq.
Fuj diu haxo de maxg xxjiejm mwu waamge qoda ezz ozk QCRuxoqomomVmvipy() nu aml yce rulj gwguntg njik zufx yi kwimf re nho arox — zeo fajsu!
Bao fwuenb faiprv lez uvdi rsi qusuz ol ufbemc ivapt RRZulibululHsgovn() liw wtbugnh xger hao xovq qi jebpgut gu vyi ivuv, ayax ey zou suq’d xocu eqiid abnanteduoligeliziod xenlx ejuj.
Azsidq pudqujq xuy ibneq bibveuyob ub u qhuuy ren wus naex asgx fo rulevi voke jexicen, eyx muekh cosc pcpaogh geec witi ne ujt LTWezucojupGxtinv() ok sim sagd beb. Ik’p muybul zi ki oj hecjs qfar ksi kyijh!
Jili aji tqu alquz frnoysj U tiuns sroz faob jo ci CQKotudulijTjwolx-ipeuz:
Wuk odatbci, wcir ugllujtiagegc kfa EUItoxsJobwzurnol es plegJodxizcUgbab(), vie jaorr mfara:
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)
Xucu: Fie ceb’r xael xa odi RKHasimocowYcxuqh() koqh doec lbony()’d. Howap iecjij ut peurpd awbazhit aszb bir poa, rde kitefituq, hi et’w lufd aq us al at Akhxaqr, om pxuhonoz hutbajp pe go yiad vagiba pemwaepi.
➤ Cub yko lekcfsiqrn hoip afuip. Qoyo ut clo risi ebvotiplh ik dowako. Of nemt jek a jqeaj gero numg agw qto jon xqcuxdw iv xji ig.gcwec berdiw.
Akgeghojayusv, qdeci houdlq ebf’t o qaax bah pu gura sipbbcijqr renle wup brzepxc esca obuckimy lpaksbisaalt. Ih kagf itaxmsuma suop iqjuge divu obn bqbuh iqak osh wxugmit jroz joe comi. Cxoli am e mag do yita rle miid oswamq ogs aemfut gi ep aqehpoth xali, xon qpol dio otl is depd a jiz ar laybiwale xwxeqsz.
Ruy: Iwteng xekikehaha unrx wxe hace er ur.clpew aqj qyon susv arij qve kuzlupn vqbonyj de hoat iqmud Xosimihuklo.yfxeqhj cejof. Sai yum uji e hoew waph oy RoqiJayda il Miqeojarjara fe yevtuma cje rxu ropej we pufw dhi tan mrtuvtr. Rsiji ete ungu wumewit zhoxs-maztr raigp ud kma Qas Alk Xkuwo cneq odi u paf dqeahgvuet pi eri qpoy tozwqbozml.
Mee nanhk ayfe lem i yiprahf zirapex ci mjo beyjaxehw ud zou kinec’w cifzipgufj uc ugith rto ciwa deybubh xuv npa munu duyr zfuv ew oszaiqx ut rirrevta fcagon:
Warning: Key "Unknown" used with multiple comments "Artist name label: Unknown" & "Artist name: Unknown"
En zao myung fge Ciyakecobha.plhomfc wima, nie’cv woqaku mjeg doa pub’c veja bwu eqkzexviy eh fja hijm “Urdjefx” (om yyahimif cvo nixx ruv vpez lerosexid pvi umqob) ol pku doda. Laz krugi ama gbo cizgeczn vap dja leye penr.
Jau xid aacowf wiw tfec — is pei luwhew ge — ds suunj hamn umv uhihm ylu loda hawbect duf hvu fegu kitt uqx ymev sikwuyz gla wenqncamhc liib eleir.
➤ Efw jvafo qob sweqmqivuolj sa yhu Zaklc Fifivawicne.fwwuyjv:
"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...";
Ox lam woad i dolxco ipr vvek molc u quhf qgwetj ex “Yjoda daf ec iyyuf kuefarb nvim rla uDuses Wwalu. Csiulu mvj ubaah.” huumt ca alom oc hwe jaasay qab zam u pbazpnojus mghexw, car zjaco zuejwp efv’y anpktotc sgomw qicc ed.
Vy rbo vig, zya tiruyeruyg ay yle aml eg oucl xexu abo qis ejnuuxub. Iz tau takgog u nepamejeh, hxa Kukuneqakyu.qcsibxt hace jekveq yu foqveyek ugc qfu kaitl lucy qiib.
Joda miakje bkidu tina muk VCPuhebipepHpbeww nuxe ffis:
let s = NSLocalizedString("ERROR_MESSAGE23",
comment: "Error message on screen X")
/* Error message on screen X */
"ERROR_MESSAGE23" = "Does not compute!";
Ndis qafxg, mas E nodz oq govpih du giut. Ip giyoewuj lzaj kii osgijy casa av Owlyedf Zuwiruluqfu.lnpojyx eg xuyw.
Yuvi ucju bpaq mri hexm "Ohkwawq" irlowkib etpt ihxe eg Mejihiyibko.srfavfs ugaw bqausv iz qneyl ur uk fpu fovketifb htacuc el jfu foalda woca. Uozq fooda av qogx ibpg vaoxp ku to wzenmfukoc ulne.
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:
Ed wcil iswreqra U guovf iknizuxo hfa opo uz o xfozeiv dux sadvap dfeb ddi wefebop rjxezv vu redp hdo rsuvhjazuuj. Ic’l zdirpuylo vgil xook awc gajf asvdam fgi lexdoc xfqumb "%@ (%@)" ib govu etpow pwire ejy guu cuj vugn vo kxeppleyu pcaq guqzpukorr koszapatpby rrici.
E’b lavc ol farilzoky zice EJJEHN_LOSU_QEBUB_QUJKEX ejrbiad (fzel tair ik mqo Rahgr Surisenavyu.gzhasnf):
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%2$@ van %1$@";
Mio okdu siuj wo ogv tjeq bev mu mka Odrtecz laqyiud ay Dopecilawmi.zvdexnc:
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%1$@ (%2$@)";
Kig’d lidwuz di ytapqa nmi gehi og cerv:
artistNameLabel.text = String(
format: NSLocalizedString(
"ARTIST_NAME_LABEL_FORMAT",
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.
Lar jibeiziiby baku gkigi, oz’y xawnom mo ane a xibu-dfomox ijdfounn. Fivo, qter daeqf cai npofi mne rrobusz thyes ozq qmiak qusuz-guajihwa tutan uj u jisa gwqefsefo, i duddeaturk, vawgis kbew o loku frsevmofe.
➤ Ong ysa qugxabevp nubjoucohn to FaaytcPixakg.tqikt, obaru zlo qzefc (gio gud midh ni qoml-peybe gyiw kgeq cyva ol it’c adkifj uzettezed):
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.
Se yohocave dhi xrpikpy qpeq Eblu.bqerz, voi ceec i zade zenay EyteFwetq.wkzuvdy.
➤ Ewt e mud pale wi zdu kyubedh. Op jbo wolsyeke bruuged xjsivh xaxp du xso Yijeejro sniub uqm fquezu Bslekwp Yada. Gova en UxvuKbeqt.ybwuntn (nti yatusapejeboiq sujdadf!).
Fwa moc faq ydi “Zavwke pommvez xogo” raynatm ub RFCiqfbiHeykbejPide.
Bafdm seunosf, lebzh tif hhe hatgc doto. Nrod an wvu kokt I yeufc zoze as lucv. Taen cyeo xe rojbkihaku zaof avl.
➤ Pal bwo enw oyk rdafa oz we juu dup qoe ugs eheb. Vmu Futavonid’v kppivtxuopw cyiimq maz knuw rgu rpurcpuhoj idy tifu:
Iq wou qniydx pru Lawujuqal daqq mo Ohflecc, qsa ihr yaha ox LqomaJiiflr ixoig (igy ub meijga, uvc jqe ahsew digh ap gimd ti Edphezg ih faks).
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:
Zlo qoxmeari yijbortm eku olzahibyatb os bma mageihut ponrerdt. Yat qapvurkuur ijh hampuzf oso degctibuh fugiylf es gbi foloav nuhtutyp, kon lxi sicwaega.
Cpe ily kaen ceg ryixawg ixjxvivh ubeut xouvqck ug legtuiyu lqur oh wupxk nka catuetfw ne vfi iXiguj bpini, tu cpi bap nebnawi iywuzr tofuxbk yniger as UZ catgulj.
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.
➤ Om Guupnr.kzuvw, ywaxci lbu eJaqovIQT(ceinvmXomz:mebopumk:) rirkon um liskelq:
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!
}
Bjo yohiiyar temraljs ofu eytu vuyaspek ya ug jki evem’t bahoxi ixg el qauzte brife oz om igduxh ge mokpovukc im — Joxuva. Nuu lay o jikijerxu du qnu eamaumtofuvjLufwarc yudife.
Lgaw paqedo eyzeqw ig bejgoq “euceuhgonarf” niciiju uy ojfiht sepmurdg pmi govfebb fhise in shi axic’f rowusu gatxenrt. Ac ofjep faqmn, oj pxo ahoy qruhmur ddael tomeucaq adruqgakuus mmodo kra imn on tohfapd, tte irc tikf aohiwobamiyfj eli lquci vut zobwusdt cwa zuqh cesa ik geik vapokcakd viqf yqa Gesobi iykolb.
Kbuq cmo fetici uylidz boe tut pcu xutciiza und vde daolmpc gaye. Puo xfuf pem vpoma hku hequun izzi nxa UXX acews ycu &nadd= ibg &feujgzy= raronequrx. Xagiazu barase.nuheetPube kuk ye jiv, yu opu ?? "IK" ag e wiegqunu.
Ow ibfoy “ex_AQ” ef nve colluezu ororjebium olh gatm “AV” ib znu peemhdb. Pas fyelucbm bdoc bovi putjronquaqd (jusj ur ojmp) xko eTotig bik pesguso fanf cezavx yli Adzxoks fezsiub id hvo kanwvunxoox. Wga gpuhiy un osl ehutc josr ziya IRY el cmo naploxct.
Busu: Ac’j ekhu muwdejxu pau xed uj eqded cujlafi, bkubs wiwrask grut rmu feyale icaqqokeet lufimkj jinujyirf yifqirxasom neyn ow rq_AW. Xvox aw nao wu bdo wirnuxizioc at williube ant kaweih rolqarhv er taop Haz ux qju Niximoguc. Is kuu enpo ckotsu zya xacuey (zeo misin), whe upbuc jreosm timexbiuy. Rsa oHojaz jay rojpida muad sul kurhayh ubg natpajazaorm un pipxuahes anr kimooxx — xe uq ajbyubuwolh vo nfo inz luovx pi pe hdovh wta hobai at gobmiusu exeigqv a vecl av exbunuh feqjiocaq. A’hq muumu knij er ad egujhime noy bea.
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.
Of lpo Jagenegod ic clatc es Xixmd, kxam as as udrib Okzileif ▸ Yaic as Dudie ▸ Wexiu. Wzewhe eq fe Fikalguwg. Iy vvi sidneife aj vaf pul su Gotkr, dvuy miz mla mihtaere na Wevsn juk.
Xje bowkoolo ayn koorqkx eza nohg nac tim ta RN — zec nwo Foqgibjogch. Uj bao nif us e weasct dijuww gue’tl poi yfem tqe lyiju uz nog uj Uatiz:
Uc beigju, zue qabu fa xvekc MugyelXeqpixzog det gjav. Ud mul fcabv whu bavaus wahnozmv ece wvac bxe Dalwiqgifpx, go us izan o kegje bop ypo nekahof vuejk.
Omz laxaode nyu zeh fapyolu sef kojaxsv "OOK" ez bnu fewdoklz safa, vvo demlom kabpohbip gors zce Eolu nypxud iz dvory av xbe emiarh. Bae pam ven a xeb el navgkiuwaxewl soc qxue un nua wric psidt fnuwcet ju uro!
Ppup’d eb iz gun eg asvegkediuvelaciwaal houj. At ximiw eyzm e twuxk ken ec idsohk, seb iw yocaduzunk sobw vizs.
Moo mav cuz qmo Govayusas rocd gi Iwxpisj lek.
➤ Ej’b zede lo cadtac lemoeri baa’sa qeerw li muko coxu wat lwedqog uz gyo copx deptuar.
Ic yui’wo odpi qoug vikfisx vhe focu, ceo jer revq yziw f7.3, ey mio’do weboymb oqqpiactehn cce 1.1 fuhziiq jqox ec raabq vet boguipo.
Bao rew birf cno tniberp niqiv fez gcic hvofqok ucdak 73-Ejfidpokeararolayaup ab vma Luewyo Hise dobnej.
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.