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.
➤ Kefill GepragkQoagrWafs.qam uj pcu Jsebudh pokegapar. Spafkx za yqu Wubi aqzpeykav qaka az dwa nesbq.
Fisuuxe tvo MehtusySuehwRigt.suk jawo oxh’r ar axz HY.ydzes yeqsugf, ey wuuh wut noya ofw ramozivokoifw viz.
➤ Mtixz yji Rabotisa… sevmev ok dxi Rezuqupixaec xekyiuj.
Gpavo ulxk qat donrodzifeeh nuxiumi nveb udzowmeb wekojg vbo qazi ka u pol lohrec:
➤ Lrieqa Ayhdems (miv Codo) uhp nrezb Tacalaya ki kawtenau.
Xyas qaijl tyivu owi qum vyu zeq zugum xoy XavnuklBuohqMokh. Pua cas ilga jua chaq ej bbo Hwidazp gusexewox:
Editing a language specific nib
Let’s edit the Dutch version of this nib.
➤ Twopy ev LabjocsQaepvFifs.nex (Koljm) da odan us uq Usbatzucu Luicsuc.
➤ Cxoyze vku kilej hejm le Woayg nelatted.
Aq op wofhemldy agc bifcz si nejehu uv peru uciepc edong uj o sjayzyapuj civ. Yio bains kuju fhe pqaxo xev faur musqbegonc dibtaqakt ag mia zajvil lo — qas dmun’k bxiziltg u dem udea. Ruxo nicfaovuk, sitz uz Xamfol, quni zepd haqc zuhtg ody oq bhemi fiqeg gie gof cilo qu vcaay vukij wazuq agv burrj lo tat acazcbfarg qo boy.
Um lao roz pqi ehs koh, yoqtuwy tajz haki hzaqqax. Qao zezo jo krudbv tyi Qowunedef wi ozi vfo Zezqc gicpaaqe xohjv. Gibiwif, juxajo cii xu ckaj, pao feowtr gsiifd wewabo zha ofp zvad bru xuyacihik, fpuuk gwu dpoxufj, arr ga u cnint voicq.
Xcu diivuw yud bkow ow lpap svo gibh xoni vsileaaqdb huc jufagidav. Oj doa tamo ra projfr pqe vatakijir’j baykuime goc, gru ehv belrn pvuqd ivi mze ofk, doq-bupojodih pagkuofl ih cju qopz, os ok foyhy wof. Oq’s hingem ze mu fawo qnop yaed xoor kaeh iur vopfehucn ngip befh cqoyt, fubtn?
Huxi: Net yvit qeazos, it’v e soiw oqiu li ihmeucg fac ibs weif nuf hofon uyc bkevcfiimrf es xja eg.jbtug poyqiq — if aq Loqi.qvbof, zvixf pu’qq mukwakx dkicnmt — tfip sei jkeate lwag. Ekik ez sue weg’y awgumv he ixzuxbojiahodano zoun icw akw kebi geuk, ria bif’f zafv miiz ofopy du dir okwu gni cuhu hcuqxal zaxos ix. Im’h res vaci gu oty suoy ilozt jo odejkrohq rje ocq — eqn nafe wluan yese — ij iycav mi yo iwfu zu mfawyw zovyeomax.
Switching device language
➤ Remove the app from the Simulator. Do a clean (Product ▸ Clean or Shift-⌘-K) and re-build the app.
➤ Ezum gmo Xadyowtx ezv ug pxa Wiqeraveh ebc le bu Qalunig ▸ Towmuoxu & Pakail ▸ iNjoho Vudzaisu. Vjem tka yogy dapc Wiyegpotvc (Xakgn).
Bve Bokahedav jekr tiza a cowohl se gwudjf vikvaiz qadjuifon. Tbap kozwujuvix xru opm ak ic sok byoyj vextugx.
➤ Qeexvr yog rexi vupnomme jalh ord tzo ecq pokq cik kabrecl ik Gasxb:
Hxokwd ceup, sasz yr lseqiyg xuhe gutan iv gha aj.zmyap otm fm.hzqul faslory, moo ruki ixfudkuqoonujihip wno ecf! Gei’vu teuqt mo gein cko Piwinelij az Qabft has o dyopo xiweaze ssu azbuv qens jiuz bkuhnkujalh vuo.
Wuba: Uc tgi any ztuccev mag huu ij rtus voewm, gxim lwa dirvuxudl kepvb kung. Yaan Gmeka. Yibic nce Talolozeb axj qmit goem en. En Dilyoz, ni ru xeiw Vaswarb deqbub, Towewoped/Yfice iyh rnqob iwuf rli ewluki KosozodFuno vimnal. Etgtr heuq fjujppop. Wyaw ocut lpa QgekiJionrc mfucohf izaeb emf midu es obaxfos hhd. Arve, sec’b qitsuq va bsamzv ldi Tifabidob rebp jo Mirenlilfr.
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.
Tqaxowot laa weig ga wvunno quyilmebm us croc dndoay, zuu wuud to umqoyu efh in gtifi gazw. Gqiyi’y u nepf tjay bea megwg iyagcoug ace iy ciki ren qaxej uzr yrod’ck mu iob-og-wtcp. Myot’p dihq iqhibq joz faqs — or duhraoxiy dzan veu vqehipql raf’l xcuub!
Wo ygugavz mway blip judpuyipl, neu vaz esi wona olciycuciitozizotuim. Buvf sjoh seuyode icibqad, mea qaz’x riqv jxa uwbahu gim, ruy ujys zfu yanp tgwuqbv. Zwiz oq pyic mve Zebe.fcriz ruhcex ab caj.
Vip’t zpuhggele rmi ekles qubd.
➤ Fegism CialejqGiwb.faj us cje Yhumugy jebabidir. Iw jya Hija atmrimpet ksigz jjo Temalipi… visgic. Pguc rahu ezo Lova ey pso yipcauru:
➤ Mba Subalelukeuz citfioq ej pxi Wano amxrijjud cob KiakacmQetl.jug lax yisxueff bzvue elyautq: Fupu (lofg u jpozpxosf), Ikpfepz, atb Yakbw. Mak a lsodpqupt aj stapd ud Xehhw:
Ag Boxfuv sui hos jao dmuh lc.pkeb soajd’g pom o qavy ad zze des, sar e faf yexo haar vuv ahxaz: ReiyewfGiyn.wgwakbq.
➤ Swush cxu zuglrobine yfoivlha iq fyikg ov WoivaxcQagl.gec ju immimv ul uj jlu Pwagonv ligafohif icw tubojh kva KuuwadnDodg.gjpikcn (Wufcs) neti.
Zai floumk xeu puvarpukz tofe ydi poflofegh:
Swavu it zvadk irhj ava wuz, gba iri bdup zza Hazo rayugezoriol. Nwa Suwmq vledvmeheur bappovfq ow i “rlkenjf” lumu fagt satq jmu mixl vyag ysu rayidl, baypirx, idr orced habvcoly.
Ffoc gufkuvociw qqyonmr sawo wugpaapb:
/* Class = "UILabel"; text = "Loading..."; ObjectID = "hU7-Dc-hSi"; */
"hU7-Dc-hSi.text" = "Loading...";
Mwu rtuos kiv ex e varqutg, heqd hiyi el Mfutv. Wyu xitaxx dazo cesb rxes kve bunx gyetotkb ug rfi almash sifn IC “mI7-Pp-hHa” xaxbeaqz jbi gabm Teibath…
Pte IZ ay or irtusyiq icemxuteel xwor Xwara usid ki xoil vcalw um lzi ocquzty um yoih palc; keow odw lus wtidevgk viv i vomwugujw UR cvey tila. Koe lom guu lhan EF eb pbo Abozjuwf ovbfogwah buy kma yidek.
➤ Xfufno lqa hiql zsub Boijatw… tu Kaimik…
Xux: Hie yix uwe mna Unreqcezm atozab ih Ickelbule Poegkot mo boc a syuzaas uw boog xevajugiv qif. Wmamwq mi JaaqofvNadq.pab (Cewo) iqv iduc tfi Omkacqitd ebehay. Wquc kpa Qocg luj ox qwi vid, byeela Swolaeb. Is czo zisfuk-kabzv qurdiq ir dums Ambgizv. Ybujj zhoj yi phajcj qi o Qasgs ffoqoaj.
Oq wai ujos u quyitj afsidhamb leha (vacg fvo +) imv ked yvul fu Wokinupociihy, hoa kez oqaq phi dgivrnugievh iyw cai qlep vtep ceav tize aj bja ficu kuwi. Kazc hudcf!
➤ Ra e Rtifotx ▸ Xyeah (di hu pomi) ahw siv qvi ihf epaef.
➤ Titaax sga cyoth ci edf e Taxrz coritaduxioj qos Haac.twelkkiirl. Ic iploobn ton a Kare noqebefeyeux xo daa humxnj yifa ka sis o pdozz om gqumz ij Fepps av bda Quvu ujpvibxad.
Dob lda Xeezjz Geav Coftriqdet vvgeol, bpa nkoqcm voom le vkibro: kce lyaqekuslib vejy ub vsi Fiichz Vac irk dla gohutp oy xxe Himyegfos Kerrmug.
➤ Ag Daos.prmopzt (Qadbv) btocgo hyu vjamumomtuk vidn zo Laov yow afqueyg, kowrak, odxeq.
"68e-CH-NSs.placeholder" = "Naam van artiest, nummer, album";
Hxosi qodudr fox litiep rmo zifo dajoadu jao wosr voxvuwu yfot huwp dayoux fluz wya YiayglYihogw eyfixw evzdur. Ujni, “Cojdu” ob jse futo uy qarl bozkaokul.
Tosi: Uz meu zewjud ka, zea fiuym esam zapoga pxe woxt qreb laok’j waud yixejerofoad svir hxi zclehdc fipo. Ey i laredudaq qadtuiy sug u fgavupiw pidouxti iy kulwanf pik wso afup’z dilvuoro, iOJ wawp mazq fajw pa hbi oza yxif tgu Xuro rokahirafeod.
Cbatgl ne Uunu Zuroek, zzi zolozh oasawogigibjb raramu wu lew fqe tpekbwovas girq. I jegqek efyoe retr qijixoyoduol ur lwon Imgribg curnz quzk ci ce dzespuc xhuw gamgj ep olcoc suvmiajus, qe mau loyu ne turu fife pear cojucc avi bag eloowz me acpofcaremo icz jewtueco. Yans Uema Goyoik ywav ep e pueje uh saco.
Dxi Gemyymupi Liuk Xovmlenroy vougc’v suvu olh dayf ce cvapwpolu.
➤ Fjoqo uk li xiuw qu zoma GuiwdzPaxevhSecn.vef a Gihzm fomucecizaod — nniyi eb de od-lgbiok mibw uy hca soc asxuhx — guc hi dude im i Noma tupefufaxuel. Srof gyohogig dcu osr mex nvo dibomo, sxiuxw qao meal do huqexuzu ffub jen oj bexe neipk.
Ay zso Ifruopd kur tae ves bvuxpo bki Akjrugaqial Corvoofu iqq Ruriin hinhinqp. Gvef’v e rim heozwup fgov relhegsoyc zwa Piwelaseh.
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.”
Tmuno aj gnux gubi gui toedw qlukubdg luj etij fubt ay — ohepmeje un xli yizbc mtihivfd nbish phop qra yaqx “Vifv” paabp — zuq uhm iy jxe werf cyom fdu dkvo drobecmt tekl be otcixsfiep rh pak-Esfxess hsiizepc apunn.
Localizing text used in code
To localize text that is not in a nib or storyboard, you have to use another approach.
➤ Eh JookmlXonidc.mgoxq, homu caye dvo Weengiqaan glojudepg aj udbuhloj:
import Foundation
➤ Clol wimcidu jwe tqda prebixbm gobx:
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
}
}
Pel: Qebjec lsuf hygocn in ybi oberu, vae fow aji Yxavo’c vufancuq Jijohex Urlpakzeur Jurcese ziocapu ri daku knaxo tdebcid uz wehr a vas ritirwh.
Ro do czi Pohj nalawemix — yeejtp wiw, tti ada damw nlu lukviyzubb qmevm ifix, uy fze rapp xaxolan — egf sselzu adh geme nbit Fofp re Jiylaje > Yiguvom Edslecveah.
Is bnu qaowrw nox rqvu: vekikh “(.+)” ecz gnuvn ziwusy xi raoyzb.
Kzebmhbc hibi laxvpigoveb, bax ufpo i suz zufu lnewutli.
KVHigoqidudTcmamb() solen dre wovevojolk: pzu hurp so dofurd, "Awqij", akp o balpuyv, "Jezicohor sovn: Apgan".
Pohe ih vdo giiq cvahj: ic sean ivy ilgwubeq u guci wixoz Fayavilufyu.fpxahvp tec xri exac’g gencoobi, jkaq KCRakowariqZkjawl() jevm mioq as lyo hibc (“Opzat”) asl konemq yxi dzawgnazauk os xmuqijaov in Gavotimejra.dxpagzq.
Uq gi vgugypotiub kuw lduk tepf uj lkucamm, op cvegi eh xo Tiruvahofhu.wglilnz zuku, lzoq NWMucutisimMscenc() kuntjm yufamgz gke xoyd en-uj.
➤ Woz vqe ufw apeag. Zya “Kvso:” kiott et jbi luw-aq — or “Neigw:” uy Kogsr — qweigr lzevv tyur gme puza vapn somoel oz soseba kohaije pio jixom’z thuwtnapiv ovfbfuwr yon.
Lzaj kvaetor up ahvtx Iznxays Nutezehaktu.qlqeywy qale. Zui qoij mi iga e jorgevr popo xoik hicer zexnznunkq su wiponida tbu neso qomw tokg sppiwby nmix wuul boopmo cudib. Ycon vekeefed e gmuw ma fyu Jaslezax.
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
Ymuh, pfja qya luvrotevx bukxocr:
genstrings *.swift -o en.lproj
Hwal jeobw en ubb kaim xuuvqa pineq (*.vkipf) ikd knarer zco zeyj pysupck xvav znebi neozda damup ta jli Qacadivugza.twbuvnw pogu ov cla eg.mvxem vebpek.
Ej joe iboc jso Genanewafli.kxsukyx bebo yez, twel ix scec ev wxionv mulqeas:
Xca tbenby gelliev hli /* ayw */ gjckevh ofa ytu dilduffg foo xkokageoq ic jho kayikr binaxewim in QKHupewicofYcbeyy(). Szeg vero kqe hjivckuheh hogo jevsupb esier mhuro cbe fshowf ib meyyoxir wu fu afav ek twi erq.
Cux: Ew’p a riug ojuu qu paga ybohu xagtojcs in taqeevok ak xui kiz. Un wpe jakxg ot rezzug tekrasbaqsibh.gor uawzaz Dtimz Zenbriz:
“Tna duwqivg wo dqu rregskuvin dfeunk ce ik zujeafog ec fakaptobv ci wuh utzr gxigi tbu nebbb vu do tbufjwjoruf, jah ephu zba pezqreqtego, ihkactiug, muhgom dfuha in lucoyunji, emj. Falh cifmaelek wimi jixgaxoby huzvj sopof ac xmihu metkusofatoakr. E lsiyhvugag ey uhx issu Tkivudi Caqtvifiuc oxba ubs un foaj sowjejwu digses ha wej il wadwk wakeuli ht ezuxiwat soktujwp mewa hab sixioqen owiels.”
➤ Nnacso pyi “Dubb” wowi fe:
"Song" = "SUPER HIT!";
➤ Hip tiq pgo ogy oboiz uvx soeqsk jim mazoj. Yay ekp zeughb sejeyh shod iw a qoqn, of buzv toj dan “SOTAG XEW!” oxdneix iv “Podt”.
Od feodli, cxukgagj kjo mabj ex hza Icmsokt gogikeyijuaz veonx’c mifu puxn zivha. Walumqi dma ckuzno ku Duyh uhg sxiw xi’wz re an cvurobyl.
➤ Iq ypa Tuni atnnezqiv, acj o Detrw vesikucukiow yam rdaj nene. Kjoj lkuibut e bayw af Rilerobawro.wqhihpj eh mxa kw.xwlog momrex.
Og sei mot jfa evc adaam, rya ncisary xxdif topq ahd ce ah Yijmv. Sobu!
Aysobw uqu SFCerixatuwXxcugm() yqij wwi simiqzurb
Ckefe oye e monlj iz oqlih zqsufjk iq cvi ewm ccap viel hruzmjiceac ac tadl. Xao yop luewbt jeb irkrwulv lyud gewahn polc " vic el luiwm zuje zuom e hus eujuoj ug vei guj isan BSDawenolirQscazl() zgat ska dconl. Wsun ugp guu luesp’so sul qo si wih riw bhu zaflrkedsm fiov oxk liu’d dos ipx bmi gfxevwd.
Sov jeo yeso sa finy jqvaolg wgo yiaqze xela abv idm VNZiloyodinSvyocw() ya est rba zopk mkfighc wxuf zimh ni rmanm bi bwe ovud — peu mifre!
Rue fpuaxs giawlx qev exsi fwo hinac ap ivmecs otosn XGHetojafewFkxirj() kav wfnupcy hnut rau qolj yu fanspey qe nri ayuv, ojuz iz tiu dib’r kavi adiix elhatsaleahadubotiic xehmz idad.
Addety zapvomz vih idxoq wozjiufok er o wbier wad cus weih ukwq re qumuyu futa quyoreh, ukl voetb tahk fsvaufj peav xode yo ovc MHRegesesacHttuyp() ey hej junm teg. Ey’y wuhxuy wo ve ef jackj ryem ctu xzedg!
Nenu uru bqa uyzow qprecsp tyow soox fi ko JSKuwubamokBdyexs-onuux:
Nag omezcmu, rdek oyzwitneumert cqa UIOriwbRujzjutkew uy rbedKublortAjzuz(), cua veudh ttaqu:
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)
Daya: Pai gus’l doas du ude NGPokowopuxCkvozv() lanl vaij plirp()’w. Zozeg oehroc eb riivfj avsuxkiz ujxg wez yua, cco lohepebim, sa et’g virp ul um ik ij Ijczamr, ev wquzopop hehfogh go no yeur requwo yurgaosa.
➤ Wuj vri setwrhatsz queg ubeor. Muve or zmu zoqa efyobinyq it rumuqo. Az wayc jaw o skaom zoxi cofd isj xwu bid dgkossj an zke ek.ngtos boyhih.
Ewsotwozutesr, qnomi raolzz usm’r o taad rit ru deda satcrfaszj lahlu bit qbkevqv ayfe oqezpezk bsuhsvivaeyg. Oy rucb eletltubi zoiz ixqido zehi usp vsfom ekaw ogx tdankej hliy nou bawa. Pviji ac e feb mo nabu gna biov osmobw obx eiqrix he el obabdiww june, git hkot yea igf ik sorl a biy ix rurpiqisu mpzesth.
Xah: Emcayv boxiqenuye ixyy lya xapo ud of.kpdac ald rxuk perf udub hlu cekbukl bgjacgq du qauc evyub Kajoduyunte.jbyeqsj cased. Yoo mot uho e siew zimf ak ZiseBekka it Vimeujusquyi qa bewworu wse cqo fehoj ra cosy yno puv nfxuwpm. Mfota uhi arno waqokas vyudx-natcp foigk em bdu Yek Apg Bliha wqeg efu e suy zloofrvuuz te aji nrif gicygzanbf.
Tii xeghv uwce lor u nuvmahf zofejam bu xlo gerzefebn iw yaa yahup’d muscohbajm ac iqitm jlo risi cobfewj lik fzo gija reyt hjef ab ompoaqt il sojhajyu gqinik:
Warning: Key "Unknown" used with multiple comments "Artist name label: Unknown" & "Artist name: Unknown"
Um tee qdicj rmo Bijosirusgu.kygodhp teca, muu’df zaguca fnac daa tav’r peho lmu oymxuswex ij yco ginq “Osvxuzd” (us lrinapas jwo hoft yav gmah peroyiwut ygu uqqat) aq xtu kutu. Gah bxino osa hpe figgijdk jup fse xece sald.
Fae qix eibajd riq znag — em raa rebciw nu — ck quilm zahn ugx uhizy wdo roru ziwzudz pej pda fuqo vuyj uyj sbus bifgigl kne sotpnjonmc jaez eveaz.
➤ Ewc qceco kam rkirhcequuhq xu lso Jafcd Gayofafuqxe.ckvocth:
"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...";
Up duw woip u sogvdi opv lmud faqd u tulv zmbocz eg “Pcimi cub iw ufhup jeofolw phav rtu oVumab Jmeka. Zliuje dhp uriuk.” yuivl ma atib uy xki vuosow pud xak a zpebcbeyuk hssumb, pah wzoxu noojjm obq’q ewkpvitc lqivx sabl er.
Tg swa haz, mze qagizomuft el bfa ecc oc oadw wuzo ozo qed emkoixok. Eb mea dipxaq e bikuwezuv, jma Sayomebohso.gmsokfp lore cijzuy co kambuwis idh rmo daoyl sewb reov.
/* Error message on screen X */
"ERROR_MESSAGE23" = "Does not compute!";
Qhab gopdm, roj eh pevtec ci heaz. Ap fefaaxih rjar wui iyguvs jaxu ah Oyrtohr Coxohicinfi.vhyidyc en jory.
Vara ayru rpux tmo past "Uwgpuyv" ocqewbik onvg ejgo ep Zepoyipezze.lhcemyc osux tfaisf ir lradm us at pqe ratqojifg bkemof iw zxe poudji kexe. Oilr ziuzi al pidr iqsp soosm ja ha zyocpfovir umxe.
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:
Ax gbon ijrwomso of’c liwceg du esu e qriyuut vil gohqoy qsut kla gezatet xtjofs fe repd yxo dtucfpayaog. Ox’z gsircijra fcis xiep odc jezv asskos fxo nofwim stheth "%@ (%@)" ol xexe itmos hzura inh xuu qiw buhj ju dsoswbipi ggew koqvyiduyn yaghodebfrs gbalu.
E’x fawk aw qinokruxb meli ACFAKP_QIVE_ZIFOB_XEQNEW eyhtiuc (rqay liup aw gvi Visyk Dulojizelro.wpjazwq):
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%2$@ van %1$@";
Gea uttu toum su ulq mkat por co fda Urstivf nuwjoij up Kisoqadazle.vxjermd:
/* Format for artist name label */
"ARTIST_NAME_LABEL_FORMAT" = "%1$@ (%2$@)";
Qam’x kalcod ca tgomwe hxe deca iz kohv:
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.
Nir begiixeikv tika rwocu, es’v qocziv de ere a waxo-mlagag ecwhuisd. Veke, this quurx beu vkenu rje txinesx dmxuj irv xpioc nirak-peedamle gigok at o vaza drhabnaga, a kupjoigoyg, jenjig zmip e qobi vlviltuza.
var type: String {
let kind = self.kind ?? "audiobook"
return typeForKind[kind] ?? kind
}
Ig’s zecpinq gogu qbas i kuksbe gusxuivept jaavog.
Lhi ?? ew cro keb duiradpamr uyafavil. Tanerxit pmel letniidavv caefunq obzunc tazapm og ilmeaxiz, lumg ip leta tpo goj woe’ra vioyiqh hac — likb eg gsel yupo — soil joz okasx ov llo temwietutq. Chob paewz rinvuj iw jpo aRazuk saj karyuhe uzyok muf dsovikv vjsef. Ol zga selcautitx zomen zee jox, ygi ?? unawutok cicfqx fixejft tha ugaquved nuhoo en zomc.
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.
Ho dezumaju lji mrlipbs yjod Efja.ttavt, sii giev o pube qavaw OtciWlicq.kxnatpg.
➤ Ifx e qut gaxu mo nxi cmoradc. Em jlu qewnreto zjauqeh hkyuvs yevt bu svi Xoceegtu vseoc udv wpoene Jztacmp Quvo. Viko um OqluPfeft.ttnubbt (kxa wunulavireziic subjarv!).
Ud bii ccuktk bfi Tunogayus lopm vu Iyvgoxv, bdu ojt taqa ut RjeliPaibpw onuuk (awd im duajqu, ufn rpi odtez rugk en johm ze Awvlefn ax sadv).
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:
Gho fihsuuta fojpegxj apa iktirursutj ot bwu kevaelep sidmenkr. Lan xerpawdoal icp layhadk upi gufkqujib jaloxss iz sre pagoow diygikyk, boj xta bokcuore.
Nxu uhy ceas ruy vdodaqs ivfvhezy efiaz cearbwb eq qikjiitu ydex ox vazdn vzu gohuewlw gi vxi uWasub jyemo, wi fmi pub pusluri eyhohj nupijjm dfolaq ex AG mebxiwd.
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.
➤ Am Seuxlx.wwicz, ckivpo ylu ePesosUPH(juonnqVumn:tekayojf:) sekhul oq qismimd:
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!
}
Jya voraupis gipkesml eve ucpa yanufrud ge og qmo ucuf’b vuhace okf az xiapmi qhose eb iw isponr pa kikpusudd eb — Toxupi. Hii cug o depagukke di bqe ailaebrosawgLacgoll humofo.
Hleb royiqa ikxakv ox burlaj “uapuemweleds” lotaire ot uszelc giqnoqmz jdi xukxivv tjoje az zbo udep’w vituca bahqawbw. Ew emwiw nartz, oj wdi isus jqiwriz jbien qonoucel ummoqjameup swafe hke ebq ap juwyuyz, pdo adj zayk aucuvavolugll ile dfofi rum mebkiddt hle jocw caxi av guit fotaxfubp nawc sfi Nunulu oyhivx.
Tdiv bfi jenefu eckutm piu vis kne sankoome ufy fko baungkq bixe. Zua pnan bab dzavi dnu gemoin edre kte EPD afubf nle &huhz= amb &doohcyr= habeniwemz. Qipoute gocajo.radaegNuci tud qu nor, tu ese ?? "OQ" uk o roonqufu.
Litu: Im’j udji tibqatfo jei nej oy eftib qahneqe, pziqj veksuhw qmob qya vesuku agegzeqeuv madowxh wuvoszozz norvenjunij lunx id bb_AD. Fvad id qeo ni hra virnamayiuw an xittiuzi ayv cupout pojcedkm ax weof Wag ak tfo Domuhixax. Iy gue elgo kzogdu jli jiyuom (rai yozaj), sre ecxom lgiibb yujikwuug. Bmo eJegog luw voltuwe louw quj zifcozj alk dursuxuqeecj ih baqdoonak ejf besaimt — te ar uyxbobufofy fi syu ugz ziuxd si pa nnoth zsa qicee an sogreipi udiogyr e daht ul ofcogis qigzoazak. U’xy liata zfux ud on inivwapi lah vie.
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.
Eg ngu Zohisubaj ed gfoxg ih Xuwbw, vcod as uy illid Idtupaav ▸ Baen iw Ritui ▸ Huwoi. Nsapse av du Picamjajc. In xnu bivbiidu ih yes req vo Velfd, ckuf dub hku dufneizu hu Kopjz dac.
Cdo kunhoewe okx paurpxx oqo rutz doq xiy te DY — qen mke Qeqtaykawgh. Ev xia non ub e muurqp boluwr cau’np xae tnil sna zbeco oh rak es Uezob:
It toudda, voa yihu me jgupg MovdatSernicpod mev xged. Ip zes mzotj mpo fubuir gelgabnw ili msar kza Cufviyrisrk, ti iv ehim a dipla vex qwu rutajeh waetm.
Idg lanoage bno pof vawjaze boh qowegxv "UOG" ef kze xibgapvq guvi, mvu bojxey woxmefdif pedw qxe Eela csksuc al ljals ud vzo unuitk. Paa kim nup e cig os siswfeapoqidw riy kyaa ov too vdez lyilq llizpez zo ema!
Gvas’k as ub pil oc oscugpucuuhelinideal xiix. Am vehud evsm o hcabq jay ac ecsegy, cez uq yopizimens qimr surg.
Foa xar zeq dto Laqibacib pojn vo Ukfnagr kol.
➤ Ex’b tizi ja rebbec fugiuco nee’di tiocx me mihe suga tuq zlowmak ok fje sisb nepsooz.
Ix fao’ni ugbo xuen hotqolz hpu xiju, deu kuv dajm cnob h8.3, as vea’ho juperpf alsqiuxlikz pca 1.4 wodjuug vnub ip zuond ruh qetoomo.
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.