[{"data":1,"prerenderedAt":191},["ShallowReactive",2],{"\u002Fblog\u002Fnuxt3-internationalization-you-dont-need-a-plugin-for-that":3,"\u002Fblog\u002Fnuxt3-internationalization-you-dont-need-a-plugin-for-that\u002Fmore":178},{"id":4,"title":5,"body":6,"description":165,"draft":166,"extension":167,"meta":168,"navigation":169,"path":170,"preview":171,"published":172,"seo":173,"stem":174,"theme":175,"thumbnail":176,"__hash__":177},"blog\u002Fblog\u002Fnuxt3-internationalization-you-dont-need-a-plugin-for-that.md","Nuxt3 internationalization: You don't need a plugin for that.",{"type":7,"value":8,"toc":158},"minimark",[9,13,16,21,24,35,52,60,68,84,88,92,95,117,124,138,151,155],[10,11,12],"p",{},"When we started with our Nuxt3 development, we built eight months before the actual stable release. It came with its challenges; mostly, there would be no working plugins, which let us develop solutions for ourselves.",[10,14,15],{},"I created a simple solution for the internationalization plugin, which was relatively easy to make.",[17,18,20],"h2",{"id":19},"why-would-you-build-yourself","Why would you build yourself?",[10,22,23],{},"Before I show a demo and explain the code, let's discuss why you should develop it and when to go for a plugin.",[10,25,26,30,31,34],{},[27,28,29],"strong",{},"✅ Pro: upgrading is painless"," ",[32,33],"br",{},"\nInternationalization is a stateless plugin; it doesn't update much unless a new feature arrives, but a simple version will last you for years without needing to change, so why look at a changelog to figure out if it would still work?",[10,36,37,30,40,42,43,47,48,51],{},[27,38,39],{},"✅ Pro: complete control over how it works",[32,41],{},"\nYou own the code and understand the inner works, which helps you adjust to your personal needs; maybe you are not a fan of ",[44,45,46],"code",{},"$t()"," and instead have it work differently, or possibly you are used to ",[44,49,50],{},"$i()"," you can name it however you and your team wants it.",[10,53,54,30,57,59],{},[27,55,56],{},"✅ Pro: just enough code",[32,58],{},"\nIf you want a translation with a toggle, it is simple enough to make it ourselves; the code will be tiny compared to some solutions out there that might support multiple frameworks with all their unique ways of reactivity.",[10,61,62,30,65,67],{},[27,63,64],{},"❌ Con: there might be a more efficient implementation",[32,66],{},"\nThis plugin is just part of a bigger problem, and spending day and night optimizing for that framework with all bells and whistles might be too much.",[10,69,70,30,73,75,76,79,80,83],{},[27,71,72],{},"❌ Con: path based translation",[32,74],{},"\nvery common to do translations based on paths, ",[44,77,78],{},"\u002Fen\u002Fhomepage"," and ",[44,81,82],{},"\u002Fes\u002Fhomepage",". While this is not hard, I don't have that requirement so it won't be in the example code.",[17,85,87],{"id":86},"coding-time","Coding time",[89,90],"iframe",{"src":91},"https:\u002F\u002Fstackblitz.com\u002Fedit\u002Fnuxt-starter-h6eiwr?ctl=1&embed=1&file=plugins\u002Fi18n.ts&theme=dark",[10,93,94],{},"Three parts need to be looked at:",[10,96,97,100,101,104,105,108,109,112,113,116],{},[44,98,99],{},"plugins\u002Fi18n.ts"," is where all the logic is, and here is where you will import the translation files stored in ",[44,102,103],{},"lang\u002F"," directory. There is also an optional plugin (",[44,106,107],{},"plugins\u002Flanguage.server.ts",") that will work if SSR is enabled, it will read the ",[44,110,111],{},"accept-language"," header and check if it can toggle to the preferred language, or it will read the ",[44,114,115],{},"cookie"," set with that language of choice when the user toggled to their language.",[10,118,119,120,123],{},"In the composable, we will store the language the user has selected in a ",[44,121,122],{},"useLang()",", which we will toggle within our app to be the language the user wants to see.",[10,125,126,127,129,130,133,134,137],{},"You will write your JSON translations in the ",[44,128,103],{}," directory. Writing the JSON should be very straightforward, and you can use nested or array-like entries ",[44,131,132],{},"home: { title:'...'}"," or ",[44,135,136],{},"titles: ['...','...','...']",".",[10,139,140,141,144,145,147,148,150],{},"The last part to look at is the component itself. The ",[44,142,143],{},"component\u002FLangToggle.vue"," is just a simple toggle between languages, which sets the language that we store in the composable ",[44,146,122],{},". The optional code here is where we set the ",[44,149,115],{}," so the server can read the language in advance before serving any content in the future.",[17,152,154],{"id":153},"conclusion","Conclusion",[10,156,157],{},"I hope you found this short helpful\u002Feducational and will use it in your next project or have learned something about how a simple translation plugin would work.",{"title":159,"searchDepth":160,"depth":160,"links":161},"",2,[162,163,164],{"id":19,"depth":160,"text":20},{"id":86,"depth":160,"text":87},{"id":153,"depth":160,"text":154},"I have started to embrace the build-it-yourself first before using a plugin idea. Most of the time, your problem is more straightforward, and a \"do it all\" plugin will likely be overkill.",false,"md",{},true,"\u002Fblog\u002Fnuxt3-internationalization-you-dont-need-a-plugin-for-that","\u002Fimages\u002Fthumbnails\u002Fmeta-nuxt-i18n.png","2023-03-12T14:00:00Z",{"title":5,"description":165},"blog\u002Fnuxt3-internationalization-you-dont-need-a-plugin-for-that","toxic","\u002Fimages\u002Fthumbnails\u002Fnuxt-i18n.png","Jh8-X72TTHpkggPJuxqqiofBzA_nQPIaWxsECeq5Bf8",[179,185],{"path":180,"title":181,"description":182,"thumbnail":183,"published":184},"\u002Fblog\u002Fwhy-the-adoption-of-web-accessibility-keeps-failing","Why the adoption of Web Accessibility keeps failing","Web Accessibility is a well-known web innovation among developers, so why does it end up last on the priority list?","\u002Fimages\u002Fthumbnails\u002Fa11y.png","2019-01-15T17:00:00.000+00:00",{"path":186,"title":187,"description":188,"thumbnail":189,"published":190},"\u002Fblog\u002Fthe-power-of-peer-to-peer-right-in-your-browser","The power of Peer-to-peer right in your browser!","Peer-to-peer holds the potential to change the way you get your favorite website, so when do we start implementing it?","\u002Fimages\u002Fthumbnails\u002Fpeer.png","2018-11-01T16:00:00Z",1794948012853]