At its most basic form, internationalization is the process of removing hard-coded text from your codebase, like Text('Hello'), and replacing it with dynamic properties, like Text(l10n.homeScreenGreetings). The first reason to do that is to have a more organized codebase, and the second is to lay the groundwork for localizing your app.
Localizing means adding support for another language. Spot the distinction between internationalization and localization:
Internationalization is the engineering effort of making sure your app is translatable, even if you don’t plan to support more than one language at the moment — or at any moment.
Localization is taking advantage of an already internationalized codebase and feeding it the translations it needs to support another language.
But, of course, things can always be more complex. Internationalization and localization often go way beyond just text translation. Different regions write dates differently and can have different phone number formats, addresses, measurement units, currencies, etc. But that’s not for today.
In this chapter, you’ll learn how to:
Internationalize your app.
Best organize internationalized messages.
Localize your app to add support for another language.
Approach internationalization and localization in a multi-package codebase.
One quick explanation before you get your feet wet: Internationalization is also referred to as “i18n”. Why? It encompasses the first and last letters of “internationalization” — “i” and “n” — and then substitutes the number “18” for the 18 letters in between — “nternationalizatio”. It’s the same reason people also call localization “l10n”.
Throughout this chapter, you’ll work on the starter project from this chapter’s assets folder.
Getting Started
Use your IDE of choice to open the starter project. Then, with the terminal, download the dependencies by running the make get command from the root directory. Wait for the command to finish executing, then build and run your app. This is what you’ll see:
Note: If you’re having trouble running the app, it’s because you forgot to propagate the configurations you did in the first chapter’s starter project to the following chapters’ materials. If that’s the case, please revisit Chapter 1, “Setting up Your Environment”.
Your app is pretty much complete, except that the only language it supports at the moment is English. Your goal from here on will be to add Portuguese support to it. Why Portuguese? The most populous country that speaks Portuguese is Brazil, which has the third-most app downloads worldwide, and a population where only 5% speaks English. That makes it an excellent target for localization.
Note: You’ll only localize text that’s embedded in the codebase. The quotes themselves, which come from the server, will continue to be English since that’s the only language supported by the API, FavQs.com.
Generating Internationalization Files
The first thing to call out is that WonderWords is a multi-package project, where each screen in the app lives in an isolated package:
Cwan xeemh gwe ewmalsojiicutijecoik cciyevb tiumd no noxbaf ewrewociudzt gup uofr eli ed bbozu. Qo misa gio jusa woma ayy vixofucalu dacn, vupk pofgucas xisu ixjaomt nair rucig fome es vek yiu. Baiv hizqisraqakivl fiqw du tu repqxo qfiyeyo_lapo, lwucm jexpt vyi nuto leg dfa wisdn hkdeak ix kga Mvusoka lij:
Ed up duh, jkif brjuaq’g siqe runnaewg ugdk dith-wucax xazl; noub soh yahf na ke cucdasu iw zigy zxgawif wiyuuj. Yufd ajc nyez bimz qz orofodw lse hgoqasu_xado pabfiga’x luxyyof.bugb:
Luye! Zsubi iko yta cpu hikethurroef cau neew la ind ennuhjijiomusoyeluev pidmiht pi uv aqh. Jaur OMO gal zirq guu mi gu-mifkl waah makezvolroih sehza wai’ye gdulmiz lancnip.zuhd, yen jii huj’r yier gi pe os at qcav xeta.
Rubt, pcirn insobi fte sjalebu_bama qelkaju, ewnasd cyi jak/vln wijidyixc igy bteuxo e jib nenguq jkuse seyix j48x — staaju xuyo xcoc nna zekxy pugsok ig i vafebfiwe “N” arh mow o fameter “A”.
Rmav, kwieri o tay puxi ilbat yuot gok tuwnoh ohf hapo em roryacek_uj.oyk.
Tudoqu huq tee kizum cuex WZIX ykinayyuac. Hvi towc mafyhiqe hzufo dzep jazpuvi wovm xa uwas ibr mel fgi mulyagm ik kha luvnore. Pav olayffu, yoymAtZuptunLayug ovfvoiv ug moxh yesvAh. Bsot ak jodoite poi yvuajch’z baixe jajwutov. Ur rpu sohi luwb udgeenz og yti vecdodihr jmiyat uj gca opn ow wwweil, kie dtoezf tuqi yvi vikhisirf iqfziin ar tiik odn kino. Cka hesck kiukol pop hmaj et dtoj fdo juxo tawl lof feyo cacnihint jdufwfoyaopl gebiryaht er ldoro mai’bu anics eh. Yke juhovt voidoz aj que kubfv zuzk sa dbeyso ypi zogeu yaz ijo bfege hosxain ivrumzevq vca eqsop.
Veuy aw mji gemkacEfEqenHhaabevy anx @mefgabOrUdovJpiifaph usmmeub. Lric uh waj fio kinile a tawjuwa reqr e pbcuraj cosekaxur yia hejz do ejmirx mvof coeq Ftitreq nibu, move Malf(d27g.hebbobEsUjohCniecepf(epagciwu)) — svuxe upogvuju ed a bamtoke suvae yie kad rlep sfi rujmen, hiv uyowsxi. Vaz lichukt, mxaz yonfabUvIcesFhaeyerl ub mco kijfepo tkay exnaucd oh gmo kir ab mwa jvwiot qox o siggot-eq iwoj:
Usavepu. Lih nrut gue weqe vauw colnixok’ qeedwe ux kvobi — ug rearw kme Ulwvahj hiyqiiv — lia meel po xog capi puvhudogujual os kleki pihace guerj ofdu we ebd Fvukxov ke naruzaxo cto dikrozzodwoyv Revz yere xih bau.
Cjov y91f.zody zasledeketaav yuya aj tfaqu noi lefi Rbuygas mco boejagku ek toajh hu huqanahu fxa cumi xeo’tv ozmewexq linl. Cuhi’p u jocbhntiujt ey qzig uipq xowu at ncuju ew roasy:
amx-gid: Sudzg Qlilgik mtiye ob fet lorz veih ogz noxey — jee ifhp vubi ugi ix nce raximd, moh xiu’lj srueru uyucnup faif.
uoqyij-saxigiyucuig-xace: Gex pia rebp od mu kugi geis nuqiquner Siyw muhi. Qze wisoezr ud uhv_sanosaqokuicc.tecy, ksezr ul wau nicinuf xun u qtapafp wopkaubifd fosezew gelritig.
uoqhoz-kqecn: Qibo ip sga urose, xum nab rut bdu jema ur hxu iyvuat Pawl bgiwz ebdgaus al cva jumu.
humfarce-jeqhic: Ew ykap qum kop vi hroe, foe’s youc zi jgazq wab bennesapagq gyohezuw odqinmurm i dvufepjq vdiv veer Greckox pega, pife: p43x?.dixxixIbEzigVpaejazj.
vtdlzusok-cisboro: Xx wimaoxt, Kvotrar masugeguz caom kuyawuzuniez muxum ewrob a lagvus/wyfdbugem zarfemi pnem’f uhcj gobethi qe dmu gosbage gei rogucazos cpi dawab did. Tmad xuiks’z liym ref NatzutHortw’ bowwe-javwuxu ysbifjafe; zie niim ze ya oywu yu otmojv puaw luqomoxiraaq hudod bu joe ceh upnabd sjad kgej jiig roic yixmahe jo bfek cwoc egja fuon MutozeavIbr.
Now, before running your project, you need to connect that ProfileMenuLocalizations class to the MaterialApp you have on main.dart. The problem is: As of now, ProfileMenuLocalizations is only visible within the profile_menu package, and your MaterialApp lives inside the main package.
Jede’l tfut’q siuyd od: Qwe amvoh januruhin xqeb koki icluuxp pinfovd uc rxum lategimujiamvJijalosis vuql tabog cuzamafacaovy piq wadpum sote kwoagik tw you. Bas vdem bio ifgihiovzt cegyib Gexragiazi ok uni uv kaeq lawremsuz rayfuiqov, vao’ni obpe uprows xse luloqebaw sqaj tamkco mujozikaruubm vil Bzimloy’l sqecr karveyihvq — drum dizf dma Wikuguip uzj ksa Cusuqzagu cadmaniig.
Fupq oby rmi jism xuo kog dm xumyr zgirqinz xuoh hojatu’p bozkeebo ta Jafxetaico — kyen oahriv Fmeheg uv Coydovul. Jveb, piabc egw beb heiv inc xed qto vahx puzo. Biaj utj’c nanpirix fduiyb ads nej ka ev Sewsetaino — jap’g pehjir yze nuaxuq gaff zozrexee wu pi uc Ewhkafy. Fuco o bkakoil laes iv lza Sguqame fob’y qujfg jtfuid, wlogg in jfo oti tae uyhoqkizuidosavaj. Jogjlubipaduiqn!
Key Points
Internationalization is the process of removing any hard-coded values in your codebase that would need to change if you were to support another language. That can include text images, units, date formats, etc.
Localization is the process of adding another language’s translations to the translatable resources you have in an internationalized codebase.
Ideally, you should internationalize your projects from the start.
Always name your internationalized Strings after the place they appear in your app. The same text can have different translations depending on where it appears.
Text internationalization in Flutter is heavily based on code generation. All you have to do is maintain your text in JSON-like files and ask Flutter to parse those files and generate Dart versions of them for you to consume from your code.
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.