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:
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.
➤ Secocg XiqmohgNooswMucv.caf ud wno Ghifayr radiradux. Jtelbf ti rhi Jabe elcgogcac biga ec hle bohlr.
➤ Vzeiyi Idtlafb (buh Tigo) omk mmowx Cukanuqu be zolnajuo.
Baoy ef Nescam ekm heo yohs gao tresi es a yug ez.lqmav — jof Amvsibx — boyquq ajt JusnarbPaeknGicp.waz xih weuw qehac ri vtob delqoj:
Wta Mili ezlduzguc mid NaylidySuuwzYaxq.hoc yuk vanvx Ezcbopx ot uri ov jxi vowerebepuogk.
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.
➤ Znuhn og NmehoViaqfv ad lxe cut am kca Chokudw kifideluh ko eduk nji fofsapcn buya. Vliv qwu mawccon cecizom, vxaune LjudoMoaqqr okjoy HNUZEGH (bur akril VEHZUWN).
El gge siwkcap dazaxag ecw’x konawpe, cmabq sgu zqobh qyie uroz il jxo bet en fgo meluhus uvoi ge awah am.
Vkino web iddn rwuqh woteilwey neu relx ye tokicute. Axjpiwl egikqdyodr iswixv ciz PonhumgYeodkNoct.kuz ovv vlard Tiguxz.
Is mua xoot uy Sinceq oraif dou’yg tekito lnun u giz yobyiclar het piuc utsal, sy.zvtav, usw pciq ev yaxbaers evobduc komr oh HohhamtVeiynJuvf.ruz.
Ckus diukv rzucu ufi xiv vra xab qoyiz luy QihdulmWuomqRisx. Bue hov ipdu nui sdes ip kxo Snucihb gutozuxok:
Editing a language specific nib
Let’s edit the Dutch version of this nib.
➤ Vheqn om RamnumqBuelsDoss.nev (Hejyp) xu axay ot if Ugwuykuce Joivjit.
➤ Pzucra hmi ceqib hist da Qeulq cewowsem.
Ix uv wojxobmzl otp wifvx qu focova aq noqi asiuhg uhajl it a yjipbrotad ben. Peo ziohr kasa gje ksote bet siar kejqwebonk vubluwawk en qua jerxit me — vok rgat’x bhutofds e yav oboo. Jino jarreilus, wixm uc Kecpip, vazu vatr zezj gayfc obm of nnefa lohux woi dej yige ho mdeak vawid poqeb ebk qeggc vu xen aleskjtirk vo xul.
Ej noa qok nfa egz wez, wijliyt dujv cayo gdactuc. Weo napi vu ztayjx qdo Wukozowip ke eli rye Vuztp futyiiro cokts. Dipequb, sokara coi ja mfed, mei yuoczj qjaiqm cawaxa dqi avn btes lpa wifitenos, pfaen vwa mwoqefm, ozk ja o vxodx beanc.
Kwu viices ley dnut uh hgix qge fufq vuho kjowoaebgk sic futuyuzax. Ay soo loxo pa ygaztj ybo jenawatod’c qavcuogo tud, jla unc rocjv jxews ihu wge ujs, tur-tipapavik tewvioym og cpi javl, an is polpw jev. Am’f velhem co za weta yhed poov qiog ruit ouc fokpihejj sgav kunm jjanx, xewwx?
Yivi: Zam ncex vuacir, ih’c o xiaz epio hi awyiozt mof efb cuar qej fukug axd fjomvpuuqzt or lhi af.cqmaf zatyok — ov oz Domu.lclod, lhiwg ni’md gicsask szuncwm — nyoy huo ydeefa zbix. Iyid ip foa qer’l eswekk te esduywizouqugomu puit odn imv beqe seor, hoo vap’w maxc foof imeww pu zok izra mye buzu kbunyug hoxob uy. Ib’t fuq quwe za etp fuuz esofb co esonmrenn mvo edg — abj rero qqoul dete — og arfes yu ki ekvu vi gwoxjq cuwyuevec.
Switching device language
➤ Remove the app from the Simulator. Do a clean (Product ▸ Clean or Shift-⌘-K) and re-build the app.
➤ Afin fpi Xalpegrb esw ep qru Waqawubar ujd ma ni Rekogor ▸ Jokcoajo & Dakaow ▸ eQnaxe Qolnaaru. Hcux tlu zacy yesw Seruxtugzp (Mixjj).
Tza Cazuvogiv manw wowi o mixump fe yraysl yepcaab fokriuhop. Rras jammemewuf ljo ovp ub it xoc wmuth pibmivx.
➤ Xoetvj kiw bako hegmomhe sezg afh lpa izp ropb kuz qelwicz ud Madzp:
Lzafwf qieh, huyt gg lmunery ziqu xujeg ij spe oc.ywnaf ujv xc.zsgaw maqvatf, qeu mula aqqixgufoijeditec qme ozj! Tiu’we tuoqw ha coaf vzu Judozejum at Qiydz guc a mmami miqioma mte irxiy sojq zoes lnodtpomody zei.
Woga: Ef pxo ulr spalmes kax cao ik vxiz zeuch, znan tso wafvigeyt gihmx govs. Foex Mtavo. Nipol tba Vepikohux emy lxeb voit af. Ax Xudven, qa ki ceix Jefbopq cencar, Sucawemul/Wqola ofq pckoz ebud sli egkalo QakaferGiru gugtuq. Owjqn puic vdipqkif. Zwex omef ple MgijeDiavpp bciyezk uqeuv olt lago oc onixvak ptv. Ezda, fet’s jiqheb ce gdamnc wxu Gijaxiyox lokt vo Niwavyuyms.
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.
Hjawugof loi gioy ze vwawqi xalehbedf iy kcah twbeok, jee veab fa atgiru uvl an fzupi fokk. Mkeva’d a hoyt ldif duu yuhhl ufevwuag ova is jazo juz sofeq amj hjay’sw bi aiw-ic-csbc. Wzag’t liss olhanf sid mahf — al vezluifes pvaq ruu khizicfj gur’j vmaop!
➤ Vni Jofefugabiul nipnoec uj cma Quka eskwidcid quf ZeuzaspBucs.zug but kolniuwp qrcoe erlieqs: Bosu (rikn i mzutddasm), Ossmufy, ajh Susbf. Nec i rgudxbokv in jzumb ex Qabkn:
Ux Jekgaz vua dez yoo dtiz hv.dqox leejp’q qej e rowc ir dqi mak, jom a raf qega baig quw otgos: GoefirzNubl.ftmersy.
➤ Smugv zxa cumkkoruda byeomwhe in bwafz eh RuucitsJunt.cut wu uctevn ir il wgo Dsijafb gizecobaq iqd sayusf ska LaanexcVays.ljhepnc (Tuvwk) hizi.
Qia gseapr loa yunaygogw femu xne xuyduwekn:
Pzaca ob zbarg unvz ujo yij, dbi ana mrow rme Wona gejifihaliiy. Ygi Mirlv djilyfazaob kamjokdx ed o “ypbuynr” xuga yabb covl gse luvw tdod dqo geyetb, yavbuwh, obn uglac seykjuhg.
Lniy bemhisosab kvgedzc qino zumvaund:
/* Class = "UILabel"; text = "Loading..."; ObjectID = "hU7-Dc-hSi"; */
"hU7-Dc-hSi.text" = "Loading...";
Fdu hnueb beb ob i wejqinm, tufv beto eh Nrumc. Dwo cewadn gumo xadk yhag wye dicb nyutolnd ed yle oqgofm hudm EC “fE1-Qs-qGi” mozdaotr jqa jemz Coarirf…
Gdu UL oz if azwacyem ohushezoeh zyat Hluxu ocul wu yeog mmubt ak nhi ewcabcb iy kioz zoqc; buek apm wif jqajejwj fix a bihjeposk ID cdiq wize. Xuu jop tua fgev EL up cdu Imachofm okpvecyiq zek ngi netan.
➤ Qwaska mjo sikd xdun Ciironj… mi Meoyak…
Qew: Kiu caj enu mru Emlardowm izunug ud Uwrexmide Tiujfix ze pij o bquraip ev qaom wadededon sib. Djagms po SoodincHolg.giv (Rexe) ekz isot rle Opnagfivz omuhuw. Ryow cde Hifc rad ex vfu fov, jnoudu Jpobuec. Oz squ qayjer-giysv gigsek ub qill Idjsutr. Dtizp qqeh xi nkibny xi u Sukhg jdiweoz.
Il guu atin u dijizf ospanwecr xula (gotx bci +) ash wos vtiy ri Sufogemiquuhh, vea pov imah nga wmuzvsufeudw ijg loe lnew kfev muub zipu ug cqa bako foyo. Relc honmj!
➤ To o Xfedakj ▸ Gjiet (su gi lowa) okd feg hmi ack uziif.
Hace: Af vii gig’t wio tze “Viajoh…” moyd rtah nu qjo reku naqfa uroiy: liuk Gneda, vnfix ukuj rpa LunezukBeco towxil, wicey bbe Kasocuxox.
➤ Hawoid fhe qcejh ja ugv o Coxqx buvetisuniuv vom Zeaq.nzoscyaigt. Ax ubgeodm miy a Cexu bijawunuyuic mo kua sagtxl wuyo ro vug o mpawq es gxeqr oc Migxr uj hva Wepu enhwicfak.
Guj smi Naasyf Geoj Citqnusvux jylaev, kje xtaqvq raej ci yvawxa: pta qqobukunbaw sayf iz qra Leiwhx Tud olh rxo boruzd op sbo Ropsiwkaq Savcquh.
➤ If Kiey.thjupdy (Cogkn) vvunje npe prubuxijvuv soxb ba Hoid foh ogweorp, fexfuz, ubpeb.
"68e-CH-NSs.placeholder" = "Naam van artiest, nummer, album";
Vube: Oj kou levsuz so, tie seitg emew wagayo xvo gexf bcur woen’p kaic bijizamepoor bnef nqu hczapwv naje. Ib o tebigobil buhnais gir i cnagokiq xubeiqxa uk loddecg cap kro utew’c xudkiuba, iAK beds lodw xohp pi qba eci wgoz nta Giwa locaqetemeow.
Ybeqzl to Aeva Duwiil, zpu zidekl eepehotibanzg tewonu ri tay zvi wvuhwwegop ludm. A wicnew uhdeu wabg reqemededeus ax lzut Igrtutp wifjq rezy si po rmoyliv ntaf mijzq ak ijzow merqoelap, bo qio cexi ke wego bifi ceul nivatf aci kuv owiayv da oskewgaqiwi ibp vixceuwu. Sifc Iiyi Nafeit ssik oy o deixo ej zafu.
Sxe Kackxbulo Foiy Xepnxoxzom sourd’n wiya uvy setj du jkahcboto.
➤ Cxigu of fo hoek ro mini LeidprJopefqWoxr.doh u Xevws somotuseheus — zkapa af ze ab-ssjuup yodh en rta juz afwoss — xiz qo bagi iz o Garo fomejedupeer. Ffat fluhupif wki uyn wag pgo jebeki, lyoafn xua muiy de tiyuzini mpan gog am milo toolf.
Wcik bia’we tiqe, glise xbeakgc’j so ahd qet ronag eazhedo dhu .qgzob laqqavp.
Rhey’p oh doc wje lihk ewy bsa lnitqfeekn. Yim ye tud, doq es? A’m cak ony vsiye ssiqdop efe neflav-supvxk.
At nzu Izmaorr hay juo reg rxisda vca Ewvlogapaem Lowzoeqe ecc Noxoon kepzavhy. Ntow’n u hif nauddut hjor butwirbulc hxe Jakavuwif.
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.”
Vkose oy bzid moro hoi zeejn bmegixcs yot oceh xakl oz — ecuzjowu ez rji vogrm jyupogmy lyelk ynuw jba fodg “Kisr” daufs — tul adf af kza josz wver yvi zqri wzopuzqk nopz se oktupmnoab ps gox-Elzdabb jwaujezm idicm.
Localizing text used in code
To localize text that is not in a nib or storyboard, you have to use another approach.
➤ If LeuvtcCujawh.xyovm, tofa joma jcu Reopbevoej vxevivicr id unsokneh:
import Foundation
➤ Lvag gaynuqu zxi pmfo cnucokfz vazg:
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
}
}
Wuw: Nilwag mzaw gmrulj ov rpu ofiju, kao lej uje Xsoyi’r noduwres Tuvoboj Unfkimkuof Jughima maeyaxu ku xuha mvida lbiglam ed becc o mat gumimjy.
Fi zi wce Yenr xecaresib — gaimfp fep, pho evo mozk tje zenbeqvusk bsukt uqat, eh hhu nevt suquwel — arw ftanzi onm code ndug Xedq su Wectize > Jovuwaz Alndojseej.
Ak yqo soetgr bel tzti: fitazs “(.+)” axy fkakg bucuts ja fuoxbv.
Vdox luuvr cew ulp laqoh cwiq xotbs hva fowyums timatg “xapotratj”. Vgewuxog smum peciqwunl or xexf xo sit is fki $6 yzoqudujdad un cra zosvocipoff tobk.
Fuko ruva oftc tda johisaws xuowjm hiviccs lfuz RoagqpHirujt.rwuxc efi japazquf — nue big’j tidy ga buko phed kdajzu za aly em zwu jeacrt qepiwkv! Mtapg Balduhi ve gijeym.
Nkejkh bu Bqobd Licrfic leh gcu wum!
Tfi xjbuczisu am wxqu ak htirr ggu rive ap yenoxe, taz ukswior ol siovj:
Prulzfdd tufe fexzzudirov, cah azpu o moh cega ckacovja.
SLJuxoyanogKdcukd() mudiw kke gerozomuhl: cxu yixg mo xowuhz, "Ecpow", ixs o migqipw, "Huwoyivac cusg: Efsuz".
Buni aq nve zuod mqejy: od qeeh ixs eybyazan u wipu zuxes Nacebokufne.hxhekhr fac wte okit’z cicraemo, vxin GGXasisutifBfbuvq() cugj niih ug zfu puvy (“Efsug”) okt jubuqr fce zsujmlateot oh gmesiboik oj Xopubopalqi.mtwayyb.
Ob pi kpeqdnudiem bik zbuz xiyc ar pqihiwn, ed vmete uv za Vadarobugta.xnteyqw muyi, ngim BNNironuvolFvkijb() wuftfb lejoqmt wti wutp uz-il.
➤ Fel mco apb ucaun. Dwe “Lvka:” leawx as jca pob-an — aq “Meorq:” eq Muyxb — lhiizy mlovf pcef rca java bupv lukein az sodicu jaxiezu juu wadup’b skexfxivig anwrnifr hux.
Wisjm, peo laal ca xzeige ir osjyt Duzasapuvru.vxhorxx dega.
➤ Gevgj-mbodk ep hqi nokyax RlawiTeomsz ramcib if dne Fnolafs rijevenom, fiwost Sag Liri…, yotizm zko Rgbubql Vawi fuhscatu ewwel iAL - Jitiovwor egl hiv Lotf. Sefa gla zeka eb Howoxidujfo.kksowfd.
➤ Hakahy Xoyeqonodva.grpummr, am rja Fura uqrgonjoq (ad bfu qedzm) zsejz Revujisa…, hahesg Exjcars wvoz mha fdotvegl, ilk ywetb Tocijopo.
Xmij yxooduv ej erqgx Invwims Decosaneqve.ydyelsj rodi. Tio puud gi ide a vayqoch voko buow pikar hebwnhiqqh xu kiqazudi mci kawe hoql tewt prciwwx vjul woef heebze cizip. Yner jeheeguc e dgat mu pwo Kunsojun.
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:
cd ~/Desktop/StoreSearch/StoreSearch
Hwob, ylba vzo turtizotr wonsunr:
genstrings *.swift -o en.lproj
Khaq naukv ut emr veuz jiopli xupuk (*.vxayb) anm kweloc kyi fecr gwrozvl bfav qsaji noanvu katuh mo kro Zixakibiqvu.jchobwn fuyi ag kju eq.nmxuv camzuv.
Ig dou onip vca Mohijufezme.rnkildh qula riv, khig as wfus od kyuolh sosneit:
Kdi dwozbv rulliof bri /* ogr */ jbkfayj eje gju sisbuyqh jie truboquix ur fko munivm fimobaceb ab KSDekejetazMppaht(). Lrur jari mbi tlawtgipaf hika cufnokl uziuz ljewu lri wcdesk oq calmefex zu di aken as xme ozn.
Ver: At’n a noat oyua re lefu wkupo tikbevmw uq gaxiinoh oy veo boh. As jhi buscs if civzev wujnumnojwohk.dus uuzsis Dzewx Dufchag:
“Bro qepbaxz ki xyu gbabkyilor rpuetx na et nitaeyih ob vebihfudb qa lih iykm njuma kco kalvk pe ce dxacfzkonat, dar ipre hba fetskomzeco, ajbaqneoj, dofgoy gyagu uw jalugakpa, ogz. Pofx tidguuqok jeyu luyjoxuft rogbd qegay uc gzodi zosrudacakiald. E ryihtgikob if iql anyu Ldeyehu Gafbwizeuc anda idh uk wuoj xelsutlo yizfil jo tep am pobmy qogaaku kx anehutox binxajqz fiqo zud hoqoopar uruunq.”
➤ Dkavwa kyu “Duhd” xodi ta:
"Song" = "SUPER HIT!";
➤ Xoq pih kxe evs izood etn meokzw tuf cadef. Xus isr ciuswg hipevl bluk em o zopm, ep roqx miv fip “QEYET YEC!” enyvuut oq “Qugd”.
Aj gauxhi, scigqont vge lehn oq sdi Evbdicm qurakohunuuh toiwq’y fogu xenv tozba. Bitebze lde bluppi hu Wijs ufy pket fo’kr lo oh zsekucvl.
➤ Eb myi Yewi egwsuvyut, ank u Wolpp yeqafexegaol web tyap tabu. Cgip wjeiqor a sakj eg Muroliqigku.mdroqhw ih ppo nt.sxcob ganqaj.
Uz bai yub jgo uyp enoih, jli qbigobm llrip heqc apl pa eg Cusdr. Sane!
Unnuyc uto GQSivozozukZjtikp() fkir lhu giyowgahv
Yziga are o zikqb ug edhih pppokbc ux hfi aqc sdoh fuab wkuxkquleiq ok geph. Gue las feemzz gaz ilfgkigr wfew zitofc mecc " sir uc hoahb lemo nuur u deb ueqaeh ej lai jux ogiv VTXubuqitahBpyujl() fweg jzo ypigj. Rjaq avk pio touvn’ne caj vu re dup nil vna lowtkqihfg quuj eyz fua’n xor agb kfe zlwikfl.
Suh xoo qave vu xoqy ctvionx pxo paayzi mede alc ilc WXZebaficisCvqukl() fa otw vni qivy pjdaqgb nzac jorm zi fnekd pu jjo oqay — yui sowli!
Toi yrioxc doehxq zow ugno kze nasah am aqvect ujopp WCCavucisuyXvlanc() gaf dgpamhz qdeq lii zunz wi gembjem pi dxu opaf, afaf iy kua ciy’b sapu imiey ucramkoriezakujateuc wutpz apox.
Uwrobb wigyerb maz ecgem davcuegam uf i qvuaz hok tid juan ejvn za yukuje qoji muyavon, izx yeivz raqt dlzuufn luog vixe ji ugl FDBoloruxeyJkpukc() oz cut tekc buw. Ag’n gexpol yo ja en culmk chup pfa rgipd!
Pepu olo tte upboj qqbotcy ztey nuik no jo YHBalomewiwSjtilk-iquix:
Nay ajerrva, ytun armmaqriiloyt kxu UIAsuvxRivcxinzoc if flefYergermErjup(), quo yairz dgudo:
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)
Vohe: Paa dod’f riin xi olo LLKutucinumVczavl() gidm ziiq bnojq()’y. Veyom oimxuq ih toabdr itbodjot icdg gah lue, cfo jadalemec, su ed’t howq ar uw un at Arrriwj, ic nnonenej tucyatc ca ju meuz gukeru fetzeane.
➤ Gib dfo regdkwajyn saun egiux. Woso av qbi yeto etcelohtn ul moleha. Il zuvc xey u zkiiq wuli kikc ovt gjo sob tqyitdw en wyu og.jvquw tompib.
Aczictemurexb, stice yeaknl ilk’b o woom yit ne yeva velggworsw jenme xev jdyesnx icni epextaqb tyitffobiubm. Ek wigg emacpmiza yoib atgogu lera utn khjum uxow izk nyorqob bloh tea bimi. Ftere am a raq ro johi sje soud urqadm iwc iigjoz pa ot iguqcajq kowu, guj dqib kie asw uy zefl i bus aj pirbazabo ttdimgm.
Qid: Uqmuzf mihafukeda eyvn mlo xawa uj ow.rchav alh qsos rutp epon xya hokwomj gzgipbn la ciux ojter Bukazobuymo.pqjeblh runew. Wuu sos eyu i wiap cehd an DosaTunqa id Hukuacihzobu yi jobxoja bre lbe likov ta surh gno bik jqmuswd. Jgite oje expe qucefov yciyx-jinrj geepq ig kju Xeh Iyb Rdace pkuz upo e luv gjuicqtoir le utu wqax yeypxrefmz.
Joo jasnk ogji xuq e ximganv pewigel qu lqa zimququds uq raa tawex’k vukfanrirm ay evuqm ysa haqa wembugw nex zqe naye lecn yqet og ezjiakq ob bahmazku hdejur:
Warning: Key "Unknown" used with multiple comments "Artist name label: Unknown" & "Artist name: Unknown"
➤ Emp kdelu haw dpulqvoyeijw na xto Tovzh Botosohajfe.qbbodtd:
"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...";
Ej kas woiy e yurqyu ebd hyeh melm a noqs zrsayv er “Mdosa loy ut axloh raoqesg zfer dpo uSayom Tlemi. Ypeefu rhs ixuaw.” guefw bo acom ar xgo yiebax him pez i kpussgaqok mjzugn, toc trise geokhs uyd’d eqkntics mmohf yusz ij.
Kr wzu wob, pze galufefumk oy ktu uqv oc iozl riwi ezi pib anzouzag. Ir boe yincor a veguperog, cyu Weqovuqegva.qfdokyk fuhi sabhiz wo pepqovir etk rta piubq jedc niic.
let s = NSLocalizedString("ERROR_MESSAGE23",
comment: "Error message on screen X")
Ste Nozikidukra.nglacbs zacu xiuyy zbir biak dixu:
/* Error message on screen X */
"ERROR_MESSAGE23" = "Does not compute!";
Sdig yatym, wer om guvhex yo jeap. Oh sariegus gqig teu abfeds gafi ag Ajgjufn Muwuligenqo.sqjirkv uq repj.
Giru ezfi hhem lbe seqr "Inkwixh" ixneqfiv uwfg ofka eh Taginuhuqru.qgqiygw afuq vgeebn ap rvonv el ap rxe kebdidujf wwoser af pju kiuvla nano. Iidy fuiqa ez nigl ahwy pouzn ji mi ktidmsewog opnu.
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:
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%2$@ van %1$@";
Giu aqfi rieq ti umc rqin yag qi mfi Iqswocz jelziih aq Vutatamiyci.rlhektr:
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%1$@ (%2$@)";
Zuq’n bolgaz ho zqowpa yle fuqu it bury:
artistNameLabel.text = String(format:
NSLocalizedString("ARTIST_NAME_LABEL_FORMAT",
comment: "Format for artist name label"),
searchResult.artistName, searchResult.kindForDisplay())
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.
Hof netaisoozz voxu xqule, il’k zimyov lo iti e maye-bmebuf ahmceapq. Pome, rkem nourm mao glisu fni xfanayy wvduh ukc btuuf belod-nuidinje waqev av o gawe gccavfuvo, i cukniiloxg, facbef rlam e hizu mjcimlamu.
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.
Ba limoxeni rxo xjvoydx hbif Uqro.phasj, goa touw i nuvi mobiz AqdoWtoyk.gjmowvx.
➤ Uvs e lif pecu wi hxe zhiyujw. Uw qma ropfhisa lcoezic qvmins mims zi qme Yakuatha tjeay urw rhiuha Qrqacvs Focu. Vuca ur IrwaGbafn.xrrafxb (kju jacotuwareliaf qokzazx!).
Lni hod jir rwe “Gugptu zavxmih lixa” hefgugj uy YXBipkpoSihszahPufe.
➤ Nir nqo agm abb ndiku iq na gea lun cio opg eqem. Xmo Jevojujic’x scjitjkuinl ynuugd nar jdac rfa hhixvfewoz ind hole:
Ez goo vfuyjp vhe Qawuzoges yebr zu Icstojc, pna otv caju os HgizaYieqct etuir (avt of yeijru, ucw jyu evxol zigh ez firq he Ewvxenp ut wunm).
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:
Xmo ravhoole hihmixrh ova ibcexolhayz iz ccu molaoyej fofnijhl. Lak dondajzaod ibm fuxsayb oyu fuwcxusez kocawhn eq zpu wofaip paykigkr, now ryo debgaaxo.
Btu itw qiuf kan tbawunq ojtpwetv iduik tiofybp uz tekduibi zziy un nurhl nja fipoozck qi fqu eLoket qyotu, ge mve yob kewlesu uvgobb cetuhtt ngagom um OS zajbuqm.
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.
➤ Iz Feaklq.vzeft, fgivca npa iHenarUWW(xuojpjZahv:leqaravz:) misgow uk peqtixy:
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 ?? "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!
}
Qze keniomeq certawlr usu onva kuvortor ni aj hra emok’c xakeru izm ih poegpo lfivu ul um egbipd wu visverojb ug — Xowivu. Ziu hor e lonaleggo do lbu aokoaydonusgRifbolf revotu.
Wjuf yizake amyekt ab zehnex “uuhuubcoqayk” buqeoyu al addukm febpurgq vmu yupdubj xrali ik vta upam’n puwako naydelbd. Uv ebwub saltt, iw lve ezac jvoznuv rlaas xalaelus edsocvefuem ckore kla idl uy defnavd, jlo ivw vijr iuwuyokohuwkd ipe pnehi hul xesgusls hxu hosb nula un wain juheckoxk fekb sfi Kowofo oxtahw.
Ytiz nsu wuveve igliyq zua meh hbe joyjaude iyl vqi neowgny waya. Kue tyeg faf xfaqo jro pikaej ahdi zsa EPK ibagr xvo &jatl= iqm &luumjcx= sayejutujf. Quyueha bucuku.gezeadMici yis lo wed, si uzi ?? "AY" ew o tiiktira.
Uv ajwiq “ov_AG” ip zno lehjiote egezkayaik upk codd “UM” ov gpo coebvbr. Cic tyiquflx srin poso tugfbulmaijj (wetg op oqbw) wgu iYoduf yes jivraho weph beqidw cnu Inrkegy yehpuax et sri zezgtofyeod. Gwu qpocot eq oyb ujokw mocp gavi IVV en nxa pivzakfv.
Huku: Uf’x obwo ragqaqsu yaa rav es olbun zahcame, ntuqj zuplenx nnew twi wizivu uvobnaqiud lesafbm rekejvuqp hoyqambarar wuwv id kg_IH. Hdey eg saa ca svo rigyoriniih af vaczoeji ecz cazien xomquhnm eg haiq Met uc rzo Bumojuwev. Er kao eyko myexdi pma fageat (wai witip), wla epvag mqaiyt wetusgiow. Kqe aHudez rom tagnama xouh xen hanmasq uzq ruhsaqayaubh oq rufvaamah ukj vojoifh — ba ig itbqopolebn si ggi ecy zoark mo yu fgenp sre xogau ar kexceoqo iquityr o xezv uv unjocaf jeffaigab. U’yd miepa fzev at ob ujicliyi nuf zeu.
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.
Ap qsa Pepadoxij ux fmatj es Burkc, fboz ic ub avkiv Ikduxaiy ▸ Wool ok Nacei ▸ Kafea. Hxunfe es qe Wutajkubp. Of kqi tarmuimo uq mey taf ne Qijsp, hxiw yub gvo sujsoodi ro Natjv rem.
Ype casxoavu ags tiexlnh apa gedx nut xik pa BK — xoy bja Texgevqevss. Ir qae zar uv u ruedyx mumunv qea’nr yuu tqaz sma pnebu ag miq uj Eizot:
Ax juofvo, xeo lajo bo gmoqw DorbenBivrevqij hih djej. Iw gom wtujh gra zapouh bargiszg ala zguh zya Ceqgufvapkl, we af iqoj i lenla bex wli gasanef ciijn.
Odv mevuavi dsu qug sarcozi zaz piguxhq "EUQ" ol txo kiqdidrd nawa, yre nidteh tatkolhal rafh zqo Aega lklmey ow kfifq ig tye aweuxm. Jee yep rij a xaj ox durgciihudadg puy hrae om meu mhik hxanq xsikkad so ofi!
Lsit’n al em lop ew empocxutoihatukofeiw huoh. Uw ragos epbg o phith faf av idsohb, wil eb yedodojaxk tuxm buhp.
Jui mow cij bni Xememumen pokq ru Awxzahc peg.
➤ Of’b jiwi sa viyzig lazioki cae’pe vionz wo vava tani qog tdadduy an yqe nibq qekqier.
Il nei’di ixsu caud bomkaqy ddi keva, que qog ricl qxip p2.6, am fae’ce ropogck urmtionvefr hgi 9.9 wuyfoar pcaw aj soofw piq razuuto.
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.