Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve i18n message handling #56

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

pearofducks
Copy link

@pearofducks pearofducks commented Nov 10, 2023

This imports messages during buildtime instead of in the 'compiled' icon file. This not only results in smaller files, but also avoids a needless JSON.parse.

Size difference:

  ~/FINN/…/dist/vue ∘ next
≷ du -d1
8252	.

  ~/FINN/…/dist/vue ∘ improve-message-import
≷ du -d1
8060	.

(Look for icon.title.diner in the sources here to see the difference)

Current:

var u=Object.defineProperty;var n=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var r=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,a=(e,t)=>{for(var s in t||(t={}))M.call(t,s)&&r(e,s,t[s]);if(n)for(var s of n(t))v.call(t,s)&&r(e,s,t[s]);return e};import{i18n as w}from"@lingui/core";var i=JSON.parse('{"icon.title.diner":"Kniv og gaffel"}');var c=JSON.parse('{"icon.title.diner":"Knife and fork"}');var l=JSON.parse('{"icon.title.diner":"Haarukka ja veitsi"}');import{i18n as p}from"@lingui/core";var x=["en","nb","fi"],m="en",d=e=>x.find(t=>e===t||e.toLowerCase().includes(t))||m;function L(){if(typeof window=="undefined"){let e=process.env.NMP_LANGUAGE||Intl.DateTimeFormat().resolvedOptions().locale;return d(e)}try{let e=document.documentElement.lang;return d(e)}catch(e){return console.warn("could not detect locale, falling back to source locale",e),m}}var h=(e,t,s,o)=>e==="nb"?s:e==="fi"?o:t,g=(e,t,s)=>{let o=L(),f=h(o,e,t,s);p.load(o,f),p.activate(o)};import{h as k}from"vue";g(c,i,l);var S=w.t({message:"Knife and fork",id:"icon.title.diner",comment:"Title for diner icon"}),G=(e,{attrs:t})=>k("svg",a({xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",fill:"none",viewBox:"0 0 24 24",innerHTML:`<title>${S}</title><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6.749.75v22.5M9.749.75V7.5a3.009 3.009 0 0 1-3 3 3.01 3.01 0 0 1-3-3V.75M15.748 23.25V1.503a.756.756 0 0 1 1.388-.41c2.778 4.337 2.952 8.849 3.113 13.157a1.446 1.446 0 0 1-1.5 1.5h-2.694"></path>`},t));export{G as default};

This PR:

var u=Object.defineProperty;var s=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;var i=(e,t,o)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,a=(e,t)=>{for(var o in t||(t={}))g.call(t,o)&&i(e,o,t[o]);if(s)for(var o of s(t))m.call(t,o)&&i(e,o,t[o]);return e};import{i18n as h}from"@lingui/core";import{i18n as c}from"@lingui/core";var M=["en","nb","fi"],d="en",l=e=>M.find(t=>e===t||e.toLowerCase().includes(t))||d;function v(){if(typeof window=="undefined"){let e=process.env.NMP_LANGUAGE||Intl.DateTimeFormat().resolvedOptions().locale;return l(e)}try{let e=document.documentElement.lang;return l(e)}catch(e){return console.warn("could not detect locale, falling back to source locale",e),d}}var L=(e,t,o,n)=>e==="nb"?o:e==="fi"?n:t,p=(e,t,o)=>{let n=v(),f=L(n,e,t,o);c.load(n,f),c.activate(n)};import{h as w}from"vue";var r={nb:{"icon.title.diner":"Kniv og gaffel"},en:{"icon.title.diner":"Knife and fork"},fi:{"icon.title.diner":"Haarukka ja veitsi"}};p(r.en,r.nb,r.fi);var k=h.t({message:"Knife and fork",id:"icon.title.diner",comment:"Title for diner icon"}),V=(e,{attrs:t})=>w("svg",a({xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",fill:"none",viewBox:"0 0 24 24",innerHTML:`<title>${k}</title><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6.749.75v22.5M9.749.75V7.5a3.009 3.009 0 0 1-3 3 3.01 3.01 0 0 1-3-3V.75M15.748 23.25V1.503a.756.756 0 0 1 1.388-.41c2.778 4.337 2.952 8.849 3.113 13.157a1.446 1.446 0 0 1-1.5 1.5h-2.694"></path>`},t));export{V as default};

@pearofducks pearofducks mentioned this pull request Nov 10, 2023
@pearofducks pearofducks changed the title Improve i18n message handling chore: improve i18n message handling Nov 10, 2023
@BalbinaK BalbinaK force-pushed the improve-message-import branch from 3d88b8e to e8ee9a0 Compare January 23, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant