vue-i18n.js 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551
  1. import {
  2. require_vue
  3. } from "./chunk-IND6KQVK.js";
  4. import "./chunk-S6VK5PVK.js";
  5. import "./chunk-YVHZHMSQ.js";
  6. import "./chunk-VNBICN6T.js";
  7. import {
  8. __commonJS,
  9. __esm,
  10. __export,
  11. __toCommonJS
  12. } from "./chunk-2LSFTFF7.js";
  13. // node_modules/.pnpm/@intlify+shared@9.13.1/node_modules/@intlify/shared/dist/shared.esm-browser.js
  14. var shared_esm_browser_exports = {};
  15. __export(shared_esm_browser_exports, {
  16. assign: () => assign,
  17. createEmitter: () => createEmitter,
  18. deepCopy: () => deepCopy,
  19. escapeHtml: () => escapeHtml,
  20. format: () => format,
  21. friendlyJSONstringify: () => friendlyJSONstringify,
  22. generateCodeFrame: () => generateCodeFrame,
  23. generateFormatCacheKey: () => generateFormatCacheKey,
  24. getGlobalThis: () => getGlobalThis,
  25. hasOwn: () => hasOwn,
  26. inBrowser: () => inBrowser,
  27. incrementer: () => incrementer,
  28. isArray: () => isArray,
  29. isBoolean: () => isBoolean,
  30. isDate: () => isDate,
  31. isEmptyObject: () => isEmptyObject,
  32. isFunction: () => isFunction,
  33. isNumber: () => isNumber,
  34. isObject: () => isObject,
  35. isPlainObject: () => isPlainObject,
  36. isPromise: () => isPromise,
  37. isRegExp: () => isRegExp,
  38. isString: () => isString,
  39. isSymbol: () => isSymbol,
  40. join: () => join,
  41. makeSymbol: () => makeSymbol,
  42. mark: () => mark,
  43. measure: () => measure,
  44. objectToString: () => objectToString,
  45. toDisplayString: () => toDisplayString,
  46. toTypeString: () => toTypeString,
  47. warn: () => warn,
  48. warnOnce: () => warnOnce
  49. });
  50. function format(message, ...args) {
  51. if (args.length === 1 && isObject(args[0])) {
  52. args = args[0];
  53. }
  54. if (!args || !args.hasOwnProperty) {
  55. args = {};
  56. }
  57. return message.replace(RE_ARGS, (match, identifier) => {
  58. return args.hasOwnProperty(identifier) ? args[identifier] : "";
  59. });
  60. }
  61. function escapeHtml(rawText) {
  62. return rawText.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
  63. }
  64. function hasOwn(obj, key) {
  65. return hasOwnProperty.call(obj, key);
  66. }
  67. function join(items, separator = "") {
  68. return items.reduce((str, item, index) => index === 0 ? str + item : str + separator + item, "");
  69. }
  70. function generateCodeFrame(source, start = 0, end = source.length) {
  71. const lines = source.split(/\r?\n/);
  72. let count = 0;
  73. const res = [];
  74. for (let i = 0; i < lines.length; i++) {
  75. count += lines[i].length + 1;
  76. if (count >= start) {
  77. for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
  78. if (j < 0 || j >= lines.length)
  79. continue;
  80. const line = j + 1;
  81. res.push(`${line}${" ".repeat(3 - String(line).length)}| ${lines[j]}`);
  82. const lineLength = lines[j].length;
  83. if (j === i) {
  84. const pad = start - (count - lineLength) + 1;
  85. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  86. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  87. } else if (j > i) {
  88. if (end > count) {
  89. const length = Math.max(Math.min(end - count, lineLength), 1);
  90. res.push(` | ` + "^".repeat(length));
  91. }
  92. count += lineLength + 1;
  93. }
  94. }
  95. break;
  96. }
  97. }
  98. return res.join("\n");
  99. }
  100. function incrementer(code2) {
  101. let current = code2;
  102. return () => ++current;
  103. }
  104. function warn(msg, err) {
  105. if (typeof console !== "undefined") {
  106. console.warn(`[intlify] ` + msg);
  107. if (err) {
  108. console.warn(err.stack);
  109. }
  110. }
  111. }
  112. function warnOnce(msg) {
  113. if (!hasWarned[msg]) {
  114. hasWarned[msg] = true;
  115. warn(msg);
  116. }
  117. }
  118. function createEmitter() {
  119. const events = /* @__PURE__ */ new Map();
  120. const emitter = {
  121. events,
  122. on(event, handler) {
  123. const handlers = events.get(event);
  124. const added = handlers && handlers.push(handler);
  125. if (!added) {
  126. events.set(event, [handler]);
  127. }
  128. },
  129. off(event, handler) {
  130. const handlers = events.get(event);
  131. if (handlers) {
  132. handlers.splice(handlers.indexOf(handler) >>> 0, 1);
  133. }
  134. },
  135. emit(event, payload) {
  136. (events.get(event) || []).slice().map((handler) => handler(payload));
  137. (events.get("*") || []).slice().map((handler) => handler(event, payload));
  138. }
  139. };
  140. return emitter;
  141. }
  142. function deepCopy(src, des) {
  143. if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
  144. throw new Error("Invalid value");
  145. }
  146. const stack = [{ src, des }];
  147. while (stack.length) {
  148. const { src: src2, des: des2 } = stack.pop();
  149. Object.keys(src2).forEach((key) => {
  150. if (isNotObjectOrIsArray(src2[key]) || isNotObjectOrIsArray(des2[key])) {
  151. des2[key] = src2[key];
  152. } else {
  153. stack.push({ src: src2[key], des: des2[key] });
  154. }
  155. });
  156. }
  157. }
  158. var inBrowser, mark, measure, RE_ARGS, makeSymbol, generateFormatCacheKey, friendlyJSONstringify, isNumber, isDate, isRegExp, isEmptyObject, assign, _globalThis, getGlobalThis, hasOwnProperty, isArray, isFunction, isString, isBoolean, isSymbol, isObject, isPromise, objectToString, toTypeString, isPlainObject, toDisplayString, RANGE, hasWarned, isNotObjectOrIsArray;
  159. var init_shared_esm_browser = __esm({
  160. "node_modules/.pnpm/@intlify+shared@9.13.1/node_modules/@intlify/shared/dist/shared.esm-browser.js"() {
  161. inBrowser = typeof window !== "undefined";
  162. {
  163. const perf = inBrowser && window.performance;
  164. if (perf && perf.mark && perf.measure && perf.clearMarks && // @ts-ignore browser compat
  165. perf.clearMeasures) {
  166. mark = (tag) => {
  167. perf.mark(tag);
  168. };
  169. measure = (name, startTag, endTag) => {
  170. perf.measure(name, startTag, endTag);
  171. perf.clearMarks(startTag);
  172. perf.clearMarks(endTag);
  173. };
  174. }
  175. }
  176. RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
  177. makeSymbol = (name, shareable = false) => !shareable ? Symbol(name) : Symbol.for(name);
  178. generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
  179. friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
  180. isNumber = (val) => typeof val === "number" && isFinite(val);
  181. isDate = (val) => toTypeString(val) === "[object Date]";
  182. isRegExp = (val) => toTypeString(val) === "[object RegExp]";
  183. isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
  184. assign = Object.assign;
  185. getGlobalThis = () => {
  186. return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
  187. };
  188. hasOwnProperty = Object.prototype.hasOwnProperty;
  189. isArray = Array.isArray;
  190. isFunction = (val) => typeof val === "function";
  191. isString = (val) => typeof val === "string";
  192. isBoolean = (val) => typeof val === "boolean";
  193. isSymbol = (val) => typeof val === "symbol";
  194. isObject = (val) => val !== null && typeof val === "object";
  195. isPromise = (val) => {
  196. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  197. };
  198. objectToString = Object.prototype.toString;
  199. toTypeString = (value) => objectToString.call(value);
  200. isPlainObject = (val) => {
  201. if (!isObject(val))
  202. return false;
  203. const proto = Object.getPrototypeOf(val);
  204. return proto === null || proto.constructor === Object;
  205. };
  206. toDisplayString = (val) => {
  207. return val == null ? "" : isArray(val) || isPlainObject(val) && val.toString === objectToString ? JSON.stringify(val, null, 2) : String(val);
  208. };
  209. RANGE = 2;
  210. hasWarned = {};
  211. isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
  212. }
  213. });
  214. // node_modules/.pnpm/@intlify+core-base@9.13.1/node_modules/@intlify/core-base/dist/core-base.esm-browser.js
  215. var core_base_esm_browser_exports = {};
  216. __export(core_base_esm_browser_exports, {
  217. CompileErrorCodes: () => CompileErrorCodes,
  218. CoreErrorCodes: () => CoreErrorCodes,
  219. CoreWarnCodes: () => CoreWarnCodes,
  220. DATETIME_FORMAT_OPTIONS_KEYS: () => DATETIME_FORMAT_OPTIONS_KEYS,
  221. DEFAULT_LOCALE: () => DEFAULT_LOCALE,
  222. DEFAULT_MESSAGE_DATA_TYPE: () => DEFAULT_MESSAGE_DATA_TYPE,
  223. MISSING_RESOLVE_VALUE: () => MISSING_RESOLVE_VALUE,
  224. NOT_REOSLVED: () => NOT_REOSLVED,
  225. NUMBER_FORMAT_OPTIONS_KEYS: () => NUMBER_FORMAT_OPTIONS_KEYS,
  226. VERSION: () => VERSION,
  227. clearCompileCache: () => clearCompileCache,
  228. clearDateTimeFormat: () => clearDateTimeFormat,
  229. clearNumberFormat: () => clearNumberFormat,
  230. compile: () => compile,
  231. compileToFunction: () => compileToFunction,
  232. createCompileError: () => createCompileError,
  233. createCoreContext: () => createCoreContext,
  234. createCoreError: () => createCoreError,
  235. createMessageContext: () => createMessageContext,
  236. datetime: () => datetime,
  237. fallbackWithLocaleChain: () => fallbackWithLocaleChain,
  238. fallbackWithSimple: () => fallbackWithSimple,
  239. getAdditionalMeta: () => getAdditionalMeta,
  240. getDevToolsHook: () => getDevToolsHook,
  241. getFallbackContext: () => getFallbackContext,
  242. getLocale: () => getLocale,
  243. getWarnMessage: () => getWarnMessage,
  244. handleMissing: () => handleMissing,
  245. initI18nDevTools: () => initI18nDevTools,
  246. isAlmostSameLocale: () => isAlmostSameLocale,
  247. isImplicitFallback: () => isImplicitFallback,
  248. isMessageAST: () => isMessageAST,
  249. isMessageFunction: () => isMessageFunction,
  250. isTranslateFallbackWarn: () => isTranslateFallbackWarn,
  251. isTranslateMissingWarn: () => isTranslateMissingWarn,
  252. number: () => number,
  253. parse: () => parse,
  254. parseDateTimeArgs: () => parseDateTimeArgs,
  255. parseNumberArgs: () => parseNumberArgs,
  256. parseTranslateArgs: () => parseTranslateArgs,
  257. registerLocaleFallbacker: () => registerLocaleFallbacker,
  258. registerMessageCompiler: () => registerMessageCompiler,
  259. registerMessageResolver: () => registerMessageResolver,
  260. resolveLocale: () => resolveLocale,
  261. resolveValue: () => resolveValue,
  262. resolveWithKeyValue: () => resolveWithKeyValue,
  263. setAdditionalMeta: () => setAdditionalMeta,
  264. setDevToolsHook: () => setDevToolsHook,
  265. setFallbackContext: () => setFallbackContext,
  266. translate: () => translate,
  267. translateDevTools: () => translateDevTools,
  268. updateFallbackLocale: () => updateFallbackLocale
  269. });
  270. function format$1(message, ...args) {
  271. if (args.length === 1 && isObject2(args[0])) {
  272. args = args[0];
  273. }
  274. if (!args || !args.hasOwnProperty) {
  275. args = {};
  276. }
  277. return message.replace(RE_ARGS2, (match, identifier) => {
  278. return args.hasOwnProperty(identifier) ? args[identifier] : "";
  279. });
  280. }
  281. function escapeHtml2(rawText) {
  282. return rawText.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
  283. }
  284. function join2(items, separator = "") {
  285. return items.reduce((str, item, index) => index === 0 ? str + item : str + separator + item, "");
  286. }
  287. function generateCodeFrame2(source, start = 0, end = source.length) {
  288. const lines = source.split(/\r?\n/);
  289. let count = 0;
  290. const res = [];
  291. for (let i = 0; i < lines.length; i++) {
  292. count += lines[i].length + 1;
  293. if (count >= start) {
  294. for (let j = i - RANGE2; j <= i + RANGE2 || end > count; j++) {
  295. if (j < 0 || j >= lines.length)
  296. continue;
  297. const line = j + 1;
  298. res.push(`${line}${" ".repeat(3 - String(line).length)}| ${lines[j]}`);
  299. const lineLength = lines[j].length;
  300. if (j === i) {
  301. const pad = start - (count - lineLength) + 1;
  302. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  303. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  304. } else if (j > i) {
  305. if (end > count) {
  306. const length = Math.max(Math.min(end - count, lineLength), 1);
  307. res.push(` | ` + "^".repeat(length));
  308. }
  309. count += lineLength + 1;
  310. }
  311. }
  312. break;
  313. }
  314. }
  315. return res.join("\n");
  316. }
  317. function incrementer2(code2) {
  318. let current = code2;
  319. return () => ++current;
  320. }
  321. function warn2(msg, err) {
  322. if (typeof console !== "undefined") {
  323. console.warn(`[intlify] ` + msg);
  324. if (err) {
  325. console.warn(err.stack);
  326. }
  327. }
  328. }
  329. function warnOnce2(msg) {
  330. if (!hasWarned2[msg]) {
  331. hasWarned2[msg] = true;
  332. warn2(msg);
  333. }
  334. }
  335. function createPosition(line, column, offset) {
  336. return { line, column, offset };
  337. }
  338. function createLocation(start, end, source) {
  339. const loc = { start, end };
  340. if (source != null) {
  341. loc.source = source;
  342. }
  343. return loc;
  344. }
  345. function createCompileWarn(code2, loc, ...args) {
  346. const msg = format$1(warnMessages$1[code2] || "", ...args || []);
  347. const message = { message: String(msg), code: code2 };
  348. if (loc) {
  349. message.location = loc;
  350. }
  351. return message;
  352. }
  353. function createCompileError(code2, loc, options = {}) {
  354. const { domain, messages, args } = options;
  355. const msg = format$1((messages || errorMessages$1)[code2] || "", ...args || []);
  356. const error = new SyntaxError(String(msg));
  357. error.code = code2;
  358. if (loc) {
  359. error.location = loc;
  360. }
  361. error.domain = domain;
  362. return error;
  363. }
  364. function defaultOnError(error) {
  365. throw error;
  366. }
  367. function createScanner(str) {
  368. const _buf = str;
  369. let _index = 0;
  370. let _line = 1;
  371. let _column = 1;
  372. let _peekOffset = 0;
  373. const isCRLF = (index2) => _buf[index2] === CHAR_CR && _buf[index2 + 1] === CHAR_LF;
  374. const isLF = (index2) => _buf[index2] === CHAR_LF;
  375. const isPS = (index2) => _buf[index2] === CHAR_PS;
  376. const isLS = (index2) => _buf[index2] === CHAR_LS;
  377. const isLineEnd = (index2) => isCRLF(index2) || isLF(index2) || isPS(index2) || isLS(index2);
  378. const index = () => _index;
  379. const line = () => _line;
  380. const column = () => _column;
  381. const peekOffset = () => _peekOffset;
  382. const charAt = (offset) => isCRLF(offset) || isPS(offset) || isLS(offset) ? CHAR_LF : _buf[offset];
  383. const currentChar = () => charAt(_index);
  384. const currentPeek = () => charAt(_index + _peekOffset);
  385. function next() {
  386. _peekOffset = 0;
  387. if (isLineEnd(_index)) {
  388. _line++;
  389. _column = 0;
  390. }
  391. if (isCRLF(_index)) {
  392. _index++;
  393. }
  394. _index++;
  395. _column++;
  396. return _buf[_index];
  397. }
  398. function peek() {
  399. if (isCRLF(_index + _peekOffset)) {
  400. _peekOffset++;
  401. }
  402. _peekOffset++;
  403. return _buf[_index + _peekOffset];
  404. }
  405. function reset() {
  406. _index = 0;
  407. _line = 1;
  408. _column = 1;
  409. _peekOffset = 0;
  410. }
  411. function resetPeek(offset = 0) {
  412. _peekOffset = offset;
  413. }
  414. function skipToPeek() {
  415. const target = _index + _peekOffset;
  416. while (target !== _index) {
  417. next();
  418. }
  419. _peekOffset = 0;
  420. }
  421. return {
  422. index,
  423. line,
  424. column,
  425. peekOffset,
  426. charAt,
  427. currentChar,
  428. currentPeek,
  429. next,
  430. peek,
  431. reset,
  432. resetPeek,
  433. skipToPeek
  434. };
  435. }
  436. function createTokenizer(source, options = {}) {
  437. const location = options.location !== false;
  438. const _scnr = createScanner(source);
  439. const currentOffset = () => _scnr.index();
  440. const currentPosition = () => createPosition(_scnr.line(), _scnr.column(), _scnr.index());
  441. const _initLoc = currentPosition();
  442. const _initOffset = currentOffset();
  443. const _context = {
  444. currentType: 14,
  445. offset: _initOffset,
  446. startLoc: _initLoc,
  447. endLoc: _initLoc,
  448. lastType: 14,
  449. lastOffset: _initOffset,
  450. lastStartLoc: _initLoc,
  451. lastEndLoc: _initLoc,
  452. braceNest: 0,
  453. inLinked: false,
  454. text: ""
  455. };
  456. const context = () => _context;
  457. const { onError } = options;
  458. function emitError(code2, pos, offset, ...args) {
  459. const ctx = context();
  460. pos.column += offset;
  461. pos.offset += offset;
  462. if (onError) {
  463. const loc = location ? createLocation(ctx.startLoc, pos) : null;
  464. const err = createCompileError(code2, loc, {
  465. domain: ERROR_DOMAIN$3,
  466. args
  467. });
  468. onError(err);
  469. }
  470. }
  471. function getToken(context2, type, value) {
  472. context2.endLoc = currentPosition();
  473. context2.currentType = type;
  474. const token = { type };
  475. if (location) {
  476. token.loc = createLocation(context2.startLoc, context2.endLoc);
  477. }
  478. if (value != null) {
  479. token.value = value;
  480. }
  481. return token;
  482. }
  483. const getEndToken = (context2) => getToken(
  484. context2,
  485. 14
  486. /* TokenTypes.EOF */
  487. );
  488. function eat(scnr, ch) {
  489. if (scnr.currentChar() === ch) {
  490. scnr.next();
  491. return ch;
  492. } else {
  493. emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
  494. return "";
  495. }
  496. }
  497. function peekSpaces(scnr) {
  498. let buf = "";
  499. while (scnr.currentPeek() === CHAR_SP || scnr.currentPeek() === CHAR_LF) {
  500. buf += scnr.currentPeek();
  501. scnr.peek();
  502. }
  503. return buf;
  504. }
  505. function skipSpaces(scnr) {
  506. const buf = peekSpaces(scnr);
  507. scnr.skipToPeek();
  508. return buf;
  509. }
  510. function isIdentifierStart(ch) {
  511. if (ch === EOF) {
  512. return false;
  513. }
  514. const cc = ch.charCodeAt(0);
  515. return cc >= 97 && cc <= 122 || // a-z
  516. cc >= 65 && cc <= 90 || // A-Z
  517. cc === 95;
  518. }
  519. function isNumberStart(ch) {
  520. if (ch === EOF) {
  521. return false;
  522. }
  523. const cc = ch.charCodeAt(0);
  524. return cc >= 48 && cc <= 57;
  525. }
  526. function isNamedIdentifierStart(scnr, context2) {
  527. const { currentType } = context2;
  528. if (currentType !== 2) {
  529. return false;
  530. }
  531. peekSpaces(scnr);
  532. const ret = isIdentifierStart(scnr.currentPeek());
  533. scnr.resetPeek();
  534. return ret;
  535. }
  536. function isListIdentifierStart(scnr, context2) {
  537. const { currentType } = context2;
  538. if (currentType !== 2) {
  539. return false;
  540. }
  541. peekSpaces(scnr);
  542. const ch = scnr.currentPeek() === "-" ? scnr.peek() : scnr.currentPeek();
  543. const ret = isNumberStart(ch);
  544. scnr.resetPeek();
  545. return ret;
  546. }
  547. function isLiteralStart(scnr, context2) {
  548. const { currentType } = context2;
  549. if (currentType !== 2) {
  550. return false;
  551. }
  552. peekSpaces(scnr);
  553. const ret = scnr.currentPeek() === LITERAL_DELIMITER;
  554. scnr.resetPeek();
  555. return ret;
  556. }
  557. function isLinkedDotStart(scnr, context2) {
  558. const { currentType } = context2;
  559. if (currentType !== 8) {
  560. return false;
  561. }
  562. peekSpaces(scnr);
  563. const ret = scnr.currentPeek() === ".";
  564. scnr.resetPeek();
  565. return ret;
  566. }
  567. function isLinkedModifierStart(scnr, context2) {
  568. const { currentType } = context2;
  569. if (currentType !== 9) {
  570. return false;
  571. }
  572. peekSpaces(scnr);
  573. const ret = isIdentifierStart(scnr.currentPeek());
  574. scnr.resetPeek();
  575. return ret;
  576. }
  577. function isLinkedDelimiterStart(scnr, context2) {
  578. const { currentType } = context2;
  579. if (!(currentType === 8 || currentType === 12)) {
  580. return false;
  581. }
  582. peekSpaces(scnr);
  583. const ret = scnr.currentPeek() === ":";
  584. scnr.resetPeek();
  585. return ret;
  586. }
  587. function isLinkedReferStart(scnr, context2) {
  588. const { currentType } = context2;
  589. if (currentType !== 10) {
  590. return false;
  591. }
  592. const fn = () => {
  593. const ch = scnr.currentPeek();
  594. if (ch === "{") {
  595. return isIdentifierStart(scnr.peek());
  596. } else if (ch === "@" || ch === "%" || ch === "|" || ch === ":" || ch === "." || ch === CHAR_SP || !ch) {
  597. return false;
  598. } else if (ch === CHAR_LF) {
  599. scnr.peek();
  600. return fn();
  601. } else {
  602. return isTextStart(scnr, false);
  603. }
  604. };
  605. const ret = fn();
  606. scnr.resetPeek();
  607. return ret;
  608. }
  609. function isPluralStart(scnr) {
  610. peekSpaces(scnr);
  611. const ret = scnr.currentPeek() === "|";
  612. scnr.resetPeek();
  613. return ret;
  614. }
  615. function detectModuloStart(scnr) {
  616. const spaces = peekSpaces(scnr);
  617. const ret = scnr.currentPeek() === "%" && scnr.peek() === "{";
  618. scnr.resetPeek();
  619. return {
  620. isModulo: ret,
  621. hasSpace: spaces.length > 0
  622. };
  623. }
  624. function isTextStart(scnr, reset = true) {
  625. const fn = (hasSpace = false, prev = "", detectModulo = false) => {
  626. const ch = scnr.currentPeek();
  627. if (ch === "{") {
  628. return prev === "%" ? false : hasSpace;
  629. } else if (ch === "@" || !ch) {
  630. return prev === "%" ? true : hasSpace;
  631. } else if (ch === "%") {
  632. scnr.peek();
  633. return fn(hasSpace, "%", true);
  634. } else if (ch === "|") {
  635. return prev === "%" || detectModulo ? true : !(prev === CHAR_SP || prev === CHAR_LF);
  636. } else if (ch === CHAR_SP) {
  637. scnr.peek();
  638. return fn(true, CHAR_SP, detectModulo);
  639. } else if (ch === CHAR_LF) {
  640. scnr.peek();
  641. return fn(true, CHAR_LF, detectModulo);
  642. } else {
  643. return true;
  644. }
  645. };
  646. const ret = fn();
  647. reset && scnr.resetPeek();
  648. return ret;
  649. }
  650. function takeChar(scnr, fn) {
  651. const ch = scnr.currentChar();
  652. if (ch === EOF) {
  653. return EOF;
  654. }
  655. if (fn(ch)) {
  656. scnr.next();
  657. return ch;
  658. }
  659. return null;
  660. }
  661. function isIdentifier(ch) {
  662. const cc = ch.charCodeAt(0);
  663. return cc >= 97 && cc <= 122 || // a-z
  664. cc >= 65 && cc <= 90 || // A-Z
  665. cc >= 48 && cc <= 57 || // 0-9
  666. cc === 95 || // _
  667. cc === 36;
  668. }
  669. function takeIdentifierChar(scnr) {
  670. return takeChar(scnr, isIdentifier);
  671. }
  672. function isNamedIdentifier(ch) {
  673. const cc = ch.charCodeAt(0);
  674. return cc >= 97 && cc <= 122 || // a-z
  675. cc >= 65 && cc <= 90 || // A-Z
  676. cc >= 48 && cc <= 57 || // 0-9
  677. cc === 95 || // _
  678. cc === 36 || // $
  679. cc === 45;
  680. }
  681. function takeNamedIdentifierChar(scnr) {
  682. return takeChar(scnr, isNamedIdentifier);
  683. }
  684. function isDigit(ch) {
  685. const cc = ch.charCodeAt(0);
  686. return cc >= 48 && cc <= 57;
  687. }
  688. function takeDigit(scnr) {
  689. return takeChar(scnr, isDigit);
  690. }
  691. function isHexDigit(ch) {
  692. const cc = ch.charCodeAt(0);
  693. return cc >= 48 && cc <= 57 || // 0-9
  694. cc >= 65 && cc <= 70 || // A-F
  695. cc >= 97 && cc <= 102;
  696. }
  697. function takeHexDigit(scnr) {
  698. return takeChar(scnr, isHexDigit);
  699. }
  700. function getDigits(scnr) {
  701. let ch = "";
  702. let num = "";
  703. while (ch = takeDigit(scnr)) {
  704. num += ch;
  705. }
  706. return num;
  707. }
  708. function readModulo(scnr) {
  709. skipSpaces(scnr);
  710. const ch = scnr.currentChar();
  711. if (ch !== "%") {
  712. emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
  713. }
  714. scnr.next();
  715. return "%";
  716. }
  717. function readText(scnr) {
  718. let buf = "";
  719. while (true) {
  720. const ch = scnr.currentChar();
  721. if (ch === "{" || ch === "}" || ch === "@" || ch === "|" || !ch) {
  722. break;
  723. } else if (ch === "%") {
  724. if (isTextStart(scnr)) {
  725. buf += ch;
  726. scnr.next();
  727. } else {
  728. break;
  729. }
  730. } else if (ch === CHAR_SP || ch === CHAR_LF) {
  731. if (isTextStart(scnr)) {
  732. buf += ch;
  733. scnr.next();
  734. } else if (isPluralStart(scnr)) {
  735. break;
  736. } else {
  737. buf += ch;
  738. scnr.next();
  739. }
  740. } else {
  741. buf += ch;
  742. scnr.next();
  743. }
  744. }
  745. return buf;
  746. }
  747. function readNamedIdentifier(scnr) {
  748. skipSpaces(scnr);
  749. let ch = "";
  750. let name = "";
  751. while (ch = takeNamedIdentifierChar(scnr)) {
  752. name += ch;
  753. }
  754. if (scnr.currentChar() === EOF) {
  755. emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
  756. }
  757. return name;
  758. }
  759. function readListIdentifier(scnr) {
  760. skipSpaces(scnr);
  761. let value = "";
  762. if (scnr.currentChar() === "-") {
  763. scnr.next();
  764. value += `-${getDigits(scnr)}`;
  765. } else {
  766. value += getDigits(scnr);
  767. }
  768. if (scnr.currentChar() === EOF) {
  769. emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
  770. }
  771. return value;
  772. }
  773. function isLiteral2(ch) {
  774. return ch !== LITERAL_DELIMITER && ch !== CHAR_LF;
  775. }
  776. function readLiteral(scnr) {
  777. skipSpaces(scnr);
  778. eat(scnr, `'`);
  779. let ch = "";
  780. let literal = "";
  781. while (ch = takeChar(scnr, isLiteral2)) {
  782. if (ch === "\\") {
  783. literal += readEscapeSequence(scnr);
  784. } else {
  785. literal += ch;
  786. }
  787. }
  788. const current = scnr.currentChar();
  789. if (current === CHAR_LF || current === EOF) {
  790. emitError(CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER, currentPosition(), 0);
  791. if (current === CHAR_LF) {
  792. scnr.next();
  793. eat(scnr, `'`);
  794. }
  795. return literal;
  796. }
  797. eat(scnr, `'`);
  798. return literal;
  799. }
  800. function readEscapeSequence(scnr) {
  801. const ch = scnr.currentChar();
  802. switch (ch) {
  803. case "\\":
  804. case `'`:
  805. scnr.next();
  806. return `\\${ch}`;
  807. case "u":
  808. return readUnicodeEscapeSequence(scnr, ch, 4);
  809. case "U":
  810. return readUnicodeEscapeSequence(scnr, ch, 6);
  811. default:
  812. emitError(CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE, currentPosition(), 0, ch);
  813. return "";
  814. }
  815. }
  816. function readUnicodeEscapeSequence(scnr, unicode, digits) {
  817. eat(scnr, unicode);
  818. let sequence = "";
  819. for (let i = 0; i < digits; i++) {
  820. const ch = takeHexDigit(scnr);
  821. if (!ch) {
  822. emitError(CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE, currentPosition(), 0, `\\${unicode}${sequence}${scnr.currentChar()}`);
  823. break;
  824. }
  825. sequence += ch;
  826. }
  827. return `\\${unicode}${sequence}`;
  828. }
  829. function isInvalidIdentifier(ch) {
  830. return ch !== "{" && ch !== "}" && ch !== CHAR_SP && ch !== CHAR_LF;
  831. }
  832. function readInvalidIdentifier(scnr) {
  833. skipSpaces(scnr);
  834. let ch = "";
  835. let identifiers = "";
  836. while (ch = takeChar(scnr, isInvalidIdentifier)) {
  837. identifiers += ch;
  838. }
  839. return identifiers;
  840. }
  841. function readLinkedModifier(scnr) {
  842. let ch = "";
  843. let name = "";
  844. while (ch = takeIdentifierChar(scnr)) {
  845. name += ch;
  846. }
  847. return name;
  848. }
  849. function readLinkedRefer(scnr) {
  850. const fn = (buf) => {
  851. const ch = scnr.currentChar();
  852. if (ch === "{" || ch === "%" || ch === "@" || ch === "|" || ch === "(" || ch === ")" || !ch) {
  853. return buf;
  854. } else if (ch === CHAR_SP) {
  855. return buf;
  856. } else if (ch === CHAR_LF || ch === DOT) {
  857. buf += ch;
  858. scnr.next();
  859. return fn(buf);
  860. } else {
  861. buf += ch;
  862. scnr.next();
  863. return fn(buf);
  864. }
  865. };
  866. return fn("");
  867. }
  868. function readPlural(scnr) {
  869. skipSpaces(scnr);
  870. const plural = eat(
  871. scnr,
  872. "|"
  873. /* TokenChars.Pipe */
  874. );
  875. skipSpaces(scnr);
  876. return plural;
  877. }
  878. function readTokenInPlaceholder(scnr, context2) {
  879. let token = null;
  880. const ch = scnr.currentChar();
  881. switch (ch) {
  882. case "{":
  883. if (context2.braceNest >= 1) {
  884. emitError(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER, currentPosition(), 0);
  885. }
  886. scnr.next();
  887. token = getToken(
  888. context2,
  889. 2,
  890. "{"
  891. /* TokenChars.BraceLeft */
  892. );
  893. skipSpaces(scnr);
  894. context2.braceNest++;
  895. return token;
  896. case "}":
  897. if (context2.braceNest > 0 && context2.currentType === 2) {
  898. emitError(CompileErrorCodes.EMPTY_PLACEHOLDER, currentPosition(), 0);
  899. }
  900. scnr.next();
  901. token = getToken(
  902. context2,
  903. 3,
  904. "}"
  905. /* TokenChars.BraceRight */
  906. );
  907. context2.braceNest--;
  908. context2.braceNest > 0 && skipSpaces(scnr);
  909. if (context2.inLinked && context2.braceNest === 0) {
  910. context2.inLinked = false;
  911. }
  912. return token;
  913. case "@":
  914. if (context2.braceNest > 0) {
  915. emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
  916. }
  917. token = readTokenInLinked(scnr, context2) || getEndToken(context2);
  918. context2.braceNest = 0;
  919. return token;
  920. default: {
  921. let validNamedIdentifier = true;
  922. let validListIdentifier = true;
  923. let validLiteral = true;
  924. if (isPluralStart(scnr)) {
  925. if (context2.braceNest > 0) {
  926. emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
  927. }
  928. token = getToken(context2, 1, readPlural(scnr));
  929. context2.braceNest = 0;
  930. context2.inLinked = false;
  931. return token;
  932. }
  933. if (context2.braceNest > 0 && (context2.currentType === 5 || context2.currentType === 6 || context2.currentType === 7)) {
  934. emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
  935. context2.braceNest = 0;
  936. return readToken(scnr, context2);
  937. }
  938. if (validNamedIdentifier = isNamedIdentifierStart(scnr, context2)) {
  939. token = getToken(context2, 5, readNamedIdentifier(scnr));
  940. skipSpaces(scnr);
  941. return token;
  942. }
  943. if (validListIdentifier = isListIdentifierStart(scnr, context2)) {
  944. token = getToken(context2, 6, readListIdentifier(scnr));
  945. skipSpaces(scnr);
  946. return token;
  947. }
  948. if (validLiteral = isLiteralStart(scnr, context2)) {
  949. token = getToken(context2, 7, readLiteral(scnr));
  950. skipSpaces(scnr);
  951. return token;
  952. }
  953. if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
  954. token = getToken(context2, 13, readInvalidIdentifier(scnr));
  955. emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
  956. skipSpaces(scnr);
  957. return token;
  958. }
  959. break;
  960. }
  961. }
  962. return token;
  963. }
  964. function readTokenInLinked(scnr, context2) {
  965. const { currentType } = context2;
  966. let token = null;
  967. const ch = scnr.currentChar();
  968. if ((currentType === 8 || currentType === 9 || currentType === 12 || currentType === 10) && (ch === CHAR_LF || ch === CHAR_SP)) {
  969. emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
  970. }
  971. switch (ch) {
  972. case "@":
  973. scnr.next();
  974. token = getToken(
  975. context2,
  976. 8,
  977. "@"
  978. /* TokenChars.LinkedAlias */
  979. );
  980. context2.inLinked = true;
  981. return token;
  982. case ".":
  983. skipSpaces(scnr);
  984. scnr.next();
  985. return getToken(
  986. context2,
  987. 9,
  988. "."
  989. /* TokenChars.LinkedDot */
  990. );
  991. case ":":
  992. skipSpaces(scnr);
  993. scnr.next();
  994. return getToken(
  995. context2,
  996. 10,
  997. ":"
  998. /* TokenChars.LinkedDelimiter */
  999. );
  1000. default:
  1001. if (isPluralStart(scnr)) {
  1002. token = getToken(context2, 1, readPlural(scnr));
  1003. context2.braceNest = 0;
  1004. context2.inLinked = false;
  1005. return token;
  1006. }
  1007. if (isLinkedDotStart(scnr, context2) || isLinkedDelimiterStart(scnr, context2)) {
  1008. skipSpaces(scnr);
  1009. return readTokenInLinked(scnr, context2);
  1010. }
  1011. if (isLinkedModifierStart(scnr, context2)) {
  1012. skipSpaces(scnr);
  1013. return getToken(context2, 12, readLinkedModifier(scnr));
  1014. }
  1015. if (isLinkedReferStart(scnr, context2)) {
  1016. skipSpaces(scnr);
  1017. if (ch === "{") {
  1018. return readTokenInPlaceholder(scnr, context2) || token;
  1019. } else {
  1020. return getToken(context2, 11, readLinkedRefer(scnr));
  1021. }
  1022. }
  1023. if (currentType === 8) {
  1024. emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
  1025. }
  1026. context2.braceNest = 0;
  1027. context2.inLinked = false;
  1028. return readToken(scnr, context2);
  1029. }
  1030. }
  1031. function readToken(scnr, context2) {
  1032. let token = {
  1033. type: 14
  1034. /* TokenTypes.EOF */
  1035. };
  1036. if (context2.braceNest > 0) {
  1037. return readTokenInPlaceholder(scnr, context2) || getEndToken(context2);
  1038. }
  1039. if (context2.inLinked) {
  1040. return readTokenInLinked(scnr, context2) || getEndToken(context2);
  1041. }
  1042. const ch = scnr.currentChar();
  1043. switch (ch) {
  1044. case "{":
  1045. return readTokenInPlaceholder(scnr, context2) || getEndToken(context2);
  1046. case "}":
  1047. emitError(CompileErrorCodes.UNBALANCED_CLOSING_BRACE, currentPosition(), 0);
  1048. scnr.next();
  1049. return getToken(
  1050. context2,
  1051. 3,
  1052. "}"
  1053. /* TokenChars.BraceRight */
  1054. );
  1055. case "@":
  1056. return readTokenInLinked(scnr, context2) || getEndToken(context2);
  1057. default: {
  1058. if (isPluralStart(scnr)) {
  1059. token = getToken(context2, 1, readPlural(scnr));
  1060. context2.braceNest = 0;
  1061. context2.inLinked = false;
  1062. return token;
  1063. }
  1064. const { isModulo, hasSpace } = detectModuloStart(scnr);
  1065. if (isModulo) {
  1066. return hasSpace ? getToken(context2, 0, readText(scnr)) : getToken(context2, 4, readModulo(scnr));
  1067. }
  1068. if (isTextStart(scnr)) {
  1069. return getToken(context2, 0, readText(scnr));
  1070. }
  1071. break;
  1072. }
  1073. }
  1074. return token;
  1075. }
  1076. function nextToken() {
  1077. const { currentType, offset, startLoc, endLoc } = _context;
  1078. _context.lastType = currentType;
  1079. _context.lastOffset = offset;
  1080. _context.lastStartLoc = startLoc;
  1081. _context.lastEndLoc = endLoc;
  1082. _context.offset = currentOffset();
  1083. _context.startLoc = currentPosition();
  1084. if (_scnr.currentChar() === EOF) {
  1085. return getToken(
  1086. _context,
  1087. 14
  1088. /* TokenTypes.EOF */
  1089. );
  1090. }
  1091. return readToken(_scnr, _context);
  1092. }
  1093. return {
  1094. nextToken,
  1095. currentOffset,
  1096. currentPosition,
  1097. context
  1098. };
  1099. }
  1100. function fromEscapeSequence(match, codePoint4, codePoint6) {
  1101. switch (match) {
  1102. case `\\\\`:
  1103. return `\\`;
  1104. case `\\'`:
  1105. return `'`;
  1106. default: {
  1107. const codePoint = parseInt(codePoint4 || codePoint6, 16);
  1108. if (codePoint <= 55295 || codePoint >= 57344) {
  1109. return String.fromCodePoint(codePoint);
  1110. }
  1111. return "�";
  1112. }
  1113. }
  1114. }
  1115. function createParser(options = {}) {
  1116. const location = options.location !== false;
  1117. const { onError, onWarn } = options;
  1118. function emitError(tokenzer, code2, start, offset, ...args) {
  1119. const end = tokenzer.currentPosition();
  1120. end.offset += offset;
  1121. end.column += offset;
  1122. if (onError) {
  1123. const loc = location ? createLocation(start, end) : null;
  1124. const err = createCompileError(code2, loc, {
  1125. domain: ERROR_DOMAIN$2,
  1126. args
  1127. });
  1128. onError(err);
  1129. }
  1130. }
  1131. function emitWarn(tokenzer, code2, start, offset, ...args) {
  1132. const end = tokenzer.currentPosition();
  1133. end.offset += offset;
  1134. end.column += offset;
  1135. if (onWarn) {
  1136. const loc = location ? createLocation(start, end) : null;
  1137. onWarn(createCompileWarn(code2, loc, args));
  1138. }
  1139. }
  1140. function startNode(type, offset, loc) {
  1141. const node = { type };
  1142. if (location) {
  1143. node.start = offset;
  1144. node.end = offset;
  1145. node.loc = { start: loc, end: loc };
  1146. }
  1147. return node;
  1148. }
  1149. function endNode(node, offset, pos, type) {
  1150. if (type) {
  1151. node.type = type;
  1152. }
  1153. if (location) {
  1154. node.end = offset;
  1155. if (node.loc) {
  1156. node.loc.end = pos;
  1157. }
  1158. }
  1159. }
  1160. function parseText(tokenizer, value) {
  1161. const context = tokenizer.context();
  1162. const node = startNode(3, context.offset, context.startLoc);
  1163. node.value = value;
  1164. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1165. return node;
  1166. }
  1167. function parseList(tokenizer, index) {
  1168. const context = tokenizer.context();
  1169. const { lastOffset: offset, lastStartLoc: loc } = context;
  1170. const node = startNode(5, offset, loc);
  1171. node.index = parseInt(index, 10);
  1172. tokenizer.nextToken();
  1173. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1174. return node;
  1175. }
  1176. function parseNamed(tokenizer, key, modulo) {
  1177. const context = tokenizer.context();
  1178. const { lastOffset: offset, lastStartLoc: loc } = context;
  1179. const node = startNode(4, offset, loc);
  1180. node.key = key;
  1181. if (modulo === true) {
  1182. node.modulo = true;
  1183. }
  1184. tokenizer.nextToken();
  1185. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1186. return node;
  1187. }
  1188. function parseLiteral(tokenizer, value) {
  1189. const context = tokenizer.context();
  1190. const { lastOffset: offset, lastStartLoc: loc } = context;
  1191. const node = startNode(9, offset, loc);
  1192. node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);
  1193. tokenizer.nextToken();
  1194. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1195. return node;
  1196. }
  1197. function parseLinkedModifier(tokenizer) {
  1198. const token = tokenizer.nextToken();
  1199. const context = tokenizer.context();
  1200. const { lastOffset: offset, lastStartLoc: loc } = context;
  1201. const node = startNode(8, offset, loc);
  1202. if (token.type !== 12) {
  1203. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
  1204. node.value = "";
  1205. endNode(node, offset, loc);
  1206. return {
  1207. nextConsumeToken: token,
  1208. node
  1209. };
  1210. }
  1211. if (token.value == null) {
  1212. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1213. }
  1214. node.value = token.value || "";
  1215. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1216. return {
  1217. node
  1218. };
  1219. }
  1220. function parseLinkedKey(tokenizer, value) {
  1221. const context = tokenizer.context();
  1222. const node = startNode(7, context.offset, context.startLoc);
  1223. node.value = value;
  1224. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1225. return node;
  1226. }
  1227. function parseLinked(tokenizer) {
  1228. const context = tokenizer.context();
  1229. const linkedNode = startNode(6, context.offset, context.startLoc);
  1230. let token = tokenizer.nextToken();
  1231. if (token.type === 9) {
  1232. const parsed = parseLinkedModifier(tokenizer);
  1233. linkedNode.modifier = parsed.node;
  1234. token = parsed.nextConsumeToken || tokenizer.nextToken();
  1235. }
  1236. if (token.type !== 10) {
  1237. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1238. }
  1239. token = tokenizer.nextToken();
  1240. if (token.type === 2) {
  1241. token = tokenizer.nextToken();
  1242. }
  1243. switch (token.type) {
  1244. case 11:
  1245. if (token.value == null) {
  1246. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1247. }
  1248. linkedNode.key = parseLinkedKey(tokenizer, token.value || "");
  1249. break;
  1250. case 5:
  1251. if (token.value == null) {
  1252. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1253. }
  1254. linkedNode.key = parseNamed(tokenizer, token.value || "");
  1255. break;
  1256. case 6:
  1257. if (token.value == null) {
  1258. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1259. }
  1260. linkedNode.key = parseList(tokenizer, token.value || "");
  1261. break;
  1262. case 7:
  1263. if (token.value == null) {
  1264. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1265. }
  1266. linkedNode.key = parseLiteral(tokenizer, token.value || "");
  1267. break;
  1268. default: {
  1269. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY, context.lastStartLoc, 0);
  1270. const nextContext = tokenizer.context();
  1271. const emptyLinkedKeyNode = startNode(7, nextContext.offset, nextContext.startLoc);
  1272. emptyLinkedKeyNode.value = "";
  1273. endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);
  1274. linkedNode.key = emptyLinkedKeyNode;
  1275. endNode(linkedNode, nextContext.offset, nextContext.startLoc);
  1276. return {
  1277. nextConsumeToken: token,
  1278. node: linkedNode
  1279. };
  1280. }
  1281. }
  1282. endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition());
  1283. return {
  1284. node: linkedNode
  1285. };
  1286. }
  1287. function parseMessage(tokenizer) {
  1288. const context = tokenizer.context();
  1289. const startOffset = context.currentType === 1 ? tokenizer.currentOffset() : context.offset;
  1290. const startLoc = context.currentType === 1 ? context.endLoc : context.startLoc;
  1291. const node = startNode(2, startOffset, startLoc);
  1292. node.items = [];
  1293. let nextToken = null;
  1294. let modulo = null;
  1295. do {
  1296. const token = nextToken || tokenizer.nextToken();
  1297. nextToken = null;
  1298. switch (token.type) {
  1299. case 0:
  1300. if (token.value == null) {
  1301. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1302. }
  1303. node.items.push(parseText(tokenizer, token.value || ""));
  1304. break;
  1305. case 6:
  1306. if (token.value == null) {
  1307. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1308. }
  1309. node.items.push(parseList(tokenizer, token.value || ""));
  1310. break;
  1311. case 4:
  1312. modulo = true;
  1313. break;
  1314. case 5:
  1315. if (token.value == null) {
  1316. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1317. }
  1318. node.items.push(parseNamed(tokenizer, token.value || "", !!modulo));
  1319. if (modulo) {
  1320. emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
  1321. modulo = null;
  1322. }
  1323. break;
  1324. case 7:
  1325. if (token.value == null) {
  1326. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
  1327. }
  1328. node.items.push(parseLiteral(tokenizer, token.value || ""));
  1329. break;
  1330. case 8: {
  1331. const parsed = parseLinked(tokenizer);
  1332. node.items.push(parsed.node);
  1333. nextToken = parsed.nextConsumeToken || null;
  1334. break;
  1335. }
  1336. }
  1337. } while (context.currentType !== 14 && context.currentType !== 1);
  1338. const endOffset = context.currentType === 1 ? context.lastOffset : tokenizer.currentOffset();
  1339. const endLoc = context.currentType === 1 ? context.lastEndLoc : tokenizer.currentPosition();
  1340. endNode(node, endOffset, endLoc);
  1341. return node;
  1342. }
  1343. function parsePlural(tokenizer, offset, loc, msgNode) {
  1344. const context = tokenizer.context();
  1345. let hasEmptyMessage = msgNode.items.length === 0;
  1346. const node = startNode(1, offset, loc);
  1347. node.cases = [];
  1348. node.cases.push(msgNode);
  1349. do {
  1350. const msg = parseMessage(tokenizer);
  1351. if (!hasEmptyMessage) {
  1352. hasEmptyMessage = msg.items.length === 0;
  1353. }
  1354. node.cases.push(msg);
  1355. } while (context.currentType !== 14);
  1356. if (hasEmptyMessage) {
  1357. emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
  1358. }
  1359. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1360. return node;
  1361. }
  1362. function parseResource(tokenizer) {
  1363. const context = tokenizer.context();
  1364. const { offset, startLoc } = context;
  1365. const msgNode = parseMessage(tokenizer);
  1366. if (context.currentType === 14) {
  1367. return msgNode;
  1368. } else {
  1369. return parsePlural(tokenizer, offset, startLoc, msgNode);
  1370. }
  1371. }
  1372. function parse2(source) {
  1373. const tokenizer = createTokenizer(source, assign2({}, options));
  1374. const context = tokenizer.context();
  1375. const node = startNode(0, context.offset, context.startLoc);
  1376. if (location && node.loc) {
  1377. node.loc.source = source;
  1378. }
  1379. node.body = parseResource(tokenizer);
  1380. if (options.onCacheKey) {
  1381. node.cacheKey = options.onCacheKey(source);
  1382. }
  1383. if (context.currentType !== 14) {
  1384. emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || "");
  1385. }
  1386. endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
  1387. return node;
  1388. }
  1389. return { parse: parse2 };
  1390. }
  1391. function getTokenCaption(token) {
  1392. if (token.type === 14) {
  1393. return "EOF";
  1394. }
  1395. const name = (token.value || "").replace(/\r?\n/gu, "\\n");
  1396. return name.length > 10 ? name.slice(0, 9) + "…" : name;
  1397. }
  1398. function createTransformer(ast, options = {}) {
  1399. const _context = {
  1400. ast,
  1401. helpers: /* @__PURE__ */ new Set()
  1402. };
  1403. const context = () => _context;
  1404. const helper = (name) => {
  1405. _context.helpers.add(name);
  1406. return name;
  1407. };
  1408. return { context, helper };
  1409. }
  1410. function traverseNodes(nodes, transformer) {
  1411. for (let i = 0; i < nodes.length; i++) {
  1412. traverseNode(nodes[i], transformer);
  1413. }
  1414. }
  1415. function traverseNode(node, transformer) {
  1416. switch (node.type) {
  1417. case 1:
  1418. traverseNodes(node.cases, transformer);
  1419. transformer.helper(
  1420. "plural"
  1421. /* HelperNameMap.PLURAL */
  1422. );
  1423. break;
  1424. case 2:
  1425. traverseNodes(node.items, transformer);
  1426. break;
  1427. case 6: {
  1428. const linked = node;
  1429. traverseNode(linked.key, transformer);
  1430. transformer.helper(
  1431. "linked"
  1432. /* HelperNameMap.LINKED */
  1433. );
  1434. transformer.helper(
  1435. "type"
  1436. /* HelperNameMap.TYPE */
  1437. );
  1438. break;
  1439. }
  1440. case 5:
  1441. transformer.helper(
  1442. "interpolate"
  1443. /* HelperNameMap.INTERPOLATE */
  1444. );
  1445. transformer.helper(
  1446. "list"
  1447. /* HelperNameMap.LIST */
  1448. );
  1449. break;
  1450. case 4:
  1451. transformer.helper(
  1452. "interpolate"
  1453. /* HelperNameMap.INTERPOLATE */
  1454. );
  1455. transformer.helper(
  1456. "named"
  1457. /* HelperNameMap.NAMED */
  1458. );
  1459. break;
  1460. }
  1461. }
  1462. function transform(ast, options = {}) {
  1463. const transformer = createTransformer(ast);
  1464. transformer.helper(
  1465. "normalize"
  1466. /* HelperNameMap.NORMALIZE */
  1467. );
  1468. ast.body && traverseNode(ast.body, transformer);
  1469. const context = transformer.context();
  1470. ast.helpers = Array.from(context.helpers);
  1471. }
  1472. function optimize(ast) {
  1473. const body = ast.body;
  1474. if (body.type === 2) {
  1475. optimizeMessageNode(body);
  1476. } else {
  1477. body.cases.forEach((c) => optimizeMessageNode(c));
  1478. }
  1479. return ast;
  1480. }
  1481. function optimizeMessageNode(message) {
  1482. if (message.items.length === 1) {
  1483. const item = message.items[0];
  1484. if (item.type === 3 || item.type === 9) {
  1485. message.static = item.value;
  1486. delete item.value;
  1487. }
  1488. } else {
  1489. const values = [];
  1490. for (let i = 0; i < message.items.length; i++) {
  1491. const item = message.items[i];
  1492. if (!(item.type === 3 || item.type === 9)) {
  1493. break;
  1494. }
  1495. if (item.value == null) {
  1496. break;
  1497. }
  1498. values.push(item.value);
  1499. }
  1500. if (values.length === message.items.length) {
  1501. message.static = join2(values);
  1502. for (let i = 0; i < message.items.length; i++) {
  1503. const item = message.items[i];
  1504. if (item.type === 3 || item.type === 9) {
  1505. delete item.value;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. function minify(node) {
  1512. node.t = node.type;
  1513. switch (node.type) {
  1514. case 0: {
  1515. const resource = node;
  1516. minify(resource.body);
  1517. resource.b = resource.body;
  1518. delete resource.body;
  1519. break;
  1520. }
  1521. case 1: {
  1522. const plural = node;
  1523. const cases = plural.cases;
  1524. for (let i = 0; i < cases.length; i++) {
  1525. minify(cases[i]);
  1526. }
  1527. plural.c = cases;
  1528. delete plural.cases;
  1529. break;
  1530. }
  1531. case 2: {
  1532. const message = node;
  1533. const items = message.items;
  1534. for (let i = 0; i < items.length; i++) {
  1535. minify(items[i]);
  1536. }
  1537. message.i = items;
  1538. delete message.items;
  1539. if (message.static) {
  1540. message.s = message.static;
  1541. delete message.static;
  1542. }
  1543. break;
  1544. }
  1545. case 3:
  1546. case 9:
  1547. case 8:
  1548. case 7: {
  1549. const valueNode = node;
  1550. if (valueNode.value) {
  1551. valueNode.v = valueNode.value;
  1552. delete valueNode.value;
  1553. }
  1554. break;
  1555. }
  1556. case 6: {
  1557. const linked = node;
  1558. minify(linked.key);
  1559. linked.k = linked.key;
  1560. delete linked.key;
  1561. if (linked.modifier) {
  1562. minify(linked.modifier);
  1563. linked.m = linked.modifier;
  1564. delete linked.modifier;
  1565. }
  1566. break;
  1567. }
  1568. case 5: {
  1569. const list = node;
  1570. list.i = list.index;
  1571. delete list.index;
  1572. break;
  1573. }
  1574. case 4: {
  1575. const named = node;
  1576. named.k = named.key;
  1577. delete named.key;
  1578. break;
  1579. }
  1580. default: {
  1581. throw createCompileError(CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE, null, {
  1582. domain: ERROR_DOMAIN$1,
  1583. args: [node.type]
  1584. });
  1585. }
  1586. }
  1587. delete node.type;
  1588. }
  1589. function createCodeGenerator(ast, options) {
  1590. const { sourceMap, filename, breakLineCode, needIndent: _needIndent } = options;
  1591. const location = options.location !== false;
  1592. const _context = {
  1593. filename,
  1594. code: "",
  1595. column: 1,
  1596. line: 1,
  1597. offset: 0,
  1598. map: void 0,
  1599. breakLineCode,
  1600. needIndent: _needIndent,
  1601. indentLevel: 0
  1602. };
  1603. if (location && ast.loc) {
  1604. _context.source = ast.loc.source;
  1605. }
  1606. const context = () => _context;
  1607. function push(code2, node) {
  1608. _context.code += code2;
  1609. }
  1610. function _newline(n, withBreakLine = true) {
  1611. const _breakLineCode = withBreakLine ? breakLineCode : "";
  1612. push(_needIndent ? _breakLineCode + ` `.repeat(n) : _breakLineCode);
  1613. }
  1614. function indent(withNewLine = true) {
  1615. const level = ++_context.indentLevel;
  1616. withNewLine && _newline(level);
  1617. }
  1618. function deindent(withNewLine = true) {
  1619. const level = --_context.indentLevel;
  1620. withNewLine && _newline(level);
  1621. }
  1622. function newline() {
  1623. _newline(_context.indentLevel);
  1624. }
  1625. const helper = (key) => `_${key}`;
  1626. const needIndent = () => _context.needIndent;
  1627. return {
  1628. context,
  1629. push,
  1630. indent,
  1631. deindent,
  1632. newline,
  1633. helper,
  1634. needIndent
  1635. };
  1636. }
  1637. function generateLinkedNode(generator, node) {
  1638. const { helper } = generator;
  1639. generator.push(`${helper(
  1640. "linked"
  1641. /* HelperNameMap.LINKED */
  1642. )}(`);
  1643. generateNode(generator, node.key);
  1644. if (node.modifier) {
  1645. generator.push(`, `);
  1646. generateNode(generator, node.modifier);
  1647. generator.push(`, _type`);
  1648. } else {
  1649. generator.push(`, undefined, _type`);
  1650. }
  1651. generator.push(`)`);
  1652. }
  1653. function generateMessageNode(generator, node) {
  1654. const { helper, needIndent } = generator;
  1655. generator.push(`${helper(
  1656. "normalize"
  1657. /* HelperNameMap.NORMALIZE */
  1658. )}([`);
  1659. generator.indent(needIndent());
  1660. const length = node.items.length;
  1661. for (let i = 0; i < length; i++) {
  1662. generateNode(generator, node.items[i]);
  1663. if (i === length - 1) {
  1664. break;
  1665. }
  1666. generator.push(", ");
  1667. }
  1668. generator.deindent(needIndent());
  1669. generator.push("])");
  1670. }
  1671. function generatePluralNode(generator, node) {
  1672. const { helper, needIndent } = generator;
  1673. if (node.cases.length > 1) {
  1674. generator.push(`${helper(
  1675. "plural"
  1676. /* HelperNameMap.PLURAL */
  1677. )}([`);
  1678. generator.indent(needIndent());
  1679. const length = node.cases.length;
  1680. for (let i = 0; i < length; i++) {
  1681. generateNode(generator, node.cases[i]);
  1682. if (i === length - 1) {
  1683. break;
  1684. }
  1685. generator.push(", ");
  1686. }
  1687. generator.deindent(needIndent());
  1688. generator.push(`])`);
  1689. }
  1690. }
  1691. function generateResource(generator, node) {
  1692. if (node.body) {
  1693. generateNode(generator, node.body);
  1694. } else {
  1695. generator.push("null");
  1696. }
  1697. }
  1698. function generateNode(generator, node) {
  1699. const { helper } = generator;
  1700. switch (node.type) {
  1701. case 0:
  1702. generateResource(generator, node);
  1703. break;
  1704. case 1:
  1705. generatePluralNode(generator, node);
  1706. break;
  1707. case 2:
  1708. generateMessageNode(generator, node);
  1709. break;
  1710. case 6:
  1711. generateLinkedNode(generator, node);
  1712. break;
  1713. case 8:
  1714. generator.push(JSON.stringify(node.value), node);
  1715. break;
  1716. case 7:
  1717. generator.push(JSON.stringify(node.value), node);
  1718. break;
  1719. case 5:
  1720. generator.push(`${helper(
  1721. "interpolate"
  1722. /* HelperNameMap.INTERPOLATE */
  1723. )}(${helper(
  1724. "list"
  1725. /* HelperNameMap.LIST */
  1726. )}(${node.index}))`, node);
  1727. break;
  1728. case 4:
  1729. generator.push(`${helper(
  1730. "interpolate"
  1731. /* HelperNameMap.INTERPOLATE */
  1732. )}(${helper(
  1733. "named"
  1734. /* HelperNameMap.NAMED */
  1735. )}(${JSON.stringify(node.key)}))`, node);
  1736. break;
  1737. case 9:
  1738. generator.push(JSON.stringify(node.value), node);
  1739. break;
  1740. case 3:
  1741. generator.push(JSON.stringify(node.value), node);
  1742. break;
  1743. default: {
  1744. throw createCompileError(CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE, null, {
  1745. domain: ERROR_DOMAIN,
  1746. args: [node.type]
  1747. });
  1748. }
  1749. }
  1750. }
  1751. function baseCompile$1(source, options = {}) {
  1752. const assignedOptions = assign2({}, options);
  1753. const jit = !!assignedOptions.jit;
  1754. const enalbeMinify = !!assignedOptions.minify;
  1755. const enambeOptimize = assignedOptions.optimize == null ? true : assignedOptions.optimize;
  1756. const parser = createParser(assignedOptions);
  1757. const ast = parser.parse(source);
  1758. if (!jit) {
  1759. transform(ast, assignedOptions);
  1760. return generate(ast, assignedOptions);
  1761. } else {
  1762. enambeOptimize && optimize(ast);
  1763. enalbeMinify && minify(ast);
  1764. return { ast, code: "" };
  1765. }
  1766. }
  1767. function isLiteral(exp) {
  1768. return literalValueRE.test(exp);
  1769. }
  1770. function stripQuotes(str) {
  1771. const a = str.charCodeAt(0);
  1772. const b = str.charCodeAt(str.length - 1);
  1773. return a === b && (a === 34 || a === 39) ? str.slice(1, -1) : str;
  1774. }
  1775. function getPathCharType(ch) {
  1776. if (ch === void 0 || ch === null) {
  1777. return "o";
  1778. }
  1779. const code2 = ch.charCodeAt(0);
  1780. switch (code2) {
  1781. case 91:
  1782. case 93:
  1783. case 46:
  1784. case 34:
  1785. case 39:
  1786. return ch;
  1787. case 95:
  1788. case 36:
  1789. case 45:
  1790. return "i";
  1791. case 9:
  1792. case 10:
  1793. case 13:
  1794. case 160:
  1795. case 65279:
  1796. case 8232:
  1797. case 8233:
  1798. return "w";
  1799. }
  1800. return "i";
  1801. }
  1802. function formatSubPath(path) {
  1803. const trimmed = path.trim();
  1804. if (path.charAt(0) === "0" && isNaN(parseInt(path))) {
  1805. return false;
  1806. }
  1807. return isLiteral(trimmed) ? stripQuotes(trimmed) : "*" + trimmed;
  1808. }
  1809. function parse(path) {
  1810. const keys = [];
  1811. let index = -1;
  1812. let mode = 0;
  1813. let subPathDepth = 0;
  1814. let c;
  1815. let key;
  1816. let newChar;
  1817. let type;
  1818. let transition;
  1819. let action;
  1820. let typeMap;
  1821. const actions = [];
  1822. actions[
  1823. 0
  1824. /* Actions.APPEND */
  1825. ] = () => {
  1826. if (key === void 0) {
  1827. key = newChar;
  1828. } else {
  1829. key += newChar;
  1830. }
  1831. };
  1832. actions[
  1833. 1
  1834. /* Actions.PUSH */
  1835. ] = () => {
  1836. if (key !== void 0) {
  1837. keys.push(key);
  1838. key = void 0;
  1839. }
  1840. };
  1841. actions[
  1842. 2
  1843. /* Actions.INC_SUB_PATH_DEPTH */
  1844. ] = () => {
  1845. actions[
  1846. 0
  1847. /* Actions.APPEND */
  1848. ]();
  1849. subPathDepth++;
  1850. };
  1851. actions[
  1852. 3
  1853. /* Actions.PUSH_SUB_PATH */
  1854. ] = () => {
  1855. if (subPathDepth > 0) {
  1856. subPathDepth--;
  1857. mode = 4;
  1858. actions[
  1859. 0
  1860. /* Actions.APPEND */
  1861. ]();
  1862. } else {
  1863. subPathDepth = 0;
  1864. if (key === void 0) {
  1865. return false;
  1866. }
  1867. key = formatSubPath(key);
  1868. if (key === false) {
  1869. return false;
  1870. } else {
  1871. actions[
  1872. 1
  1873. /* Actions.PUSH */
  1874. ]();
  1875. }
  1876. }
  1877. };
  1878. function maybeUnescapeQuote() {
  1879. const nextChar = path[index + 1];
  1880. if (mode === 5 && nextChar === "'" || mode === 6 && nextChar === '"') {
  1881. index++;
  1882. newChar = "\\" + nextChar;
  1883. actions[
  1884. 0
  1885. /* Actions.APPEND */
  1886. ]();
  1887. return true;
  1888. }
  1889. }
  1890. while (mode !== null) {
  1891. index++;
  1892. c = path[index];
  1893. if (c === "\\" && maybeUnescapeQuote()) {
  1894. continue;
  1895. }
  1896. type = getPathCharType(c);
  1897. typeMap = pathStateMachine[mode];
  1898. transition = typeMap[type] || typeMap[
  1899. "l"
  1900. /* PathCharTypes.ELSE */
  1901. ] || 8;
  1902. if (transition === 8) {
  1903. return;
  1904. }
  1905. mode = transition[0];
  1906. if (transition[1] !== void 0) {
  1907. action = actions[transition[1]];
  1908. if (action) {
  1909. newChar = c;
  1910. if (action() === false) {
  1911. return;
  1912. }
  1913. }
  1914. }
  1915. if (mode === 7) {
  1916. return keys;
  1917. }
  1918. }
  1919. }
  1920. function resolveWithKeyValue(obj, path) {
  1921. return isObject2(obj) ? obj[path] : null;
  1922. }
  1923. function resolveValue(obj, path) {
  1924. if (!isObject2(obj)) {
  1925. return null;
  1926. }
  1927. let hit = cache.get(path);
  1928. if (!hit) {
  1929. hit = parse(path);
  1930. if (hit) {
  1931. cache.set(path, hit);
  1932. }
  1933. }
  1934. if (!hit) {
  1935. return null;
  1936. }
  1937. const len = hit.length;
  1938. let last = obj;
  1939. let i = 0;
  1940. while (i < len) {
  1941. const val = last[hit[i]];
  1942. if (val === void 0) {
  1943. return null;
  1944. }
  1945. if (isFunction2(last)) {
  1946. return null;
  1947. }
  1948. last = val;
  1949. i++;
  1950. }
  1951. return last;
  1952. }
  1953. function pluralDefault(choice, choicesLength) {
  1954. choice = Math.abs(choice);
  1955. if (choicesLength === 2) {
  1956. return choice ? choice > 1 ? 1 : 0 : 1;
  1957. }
  1958. return choice ? Math.min(choice, 2) : 0;
  1959. }
  1960. function getPluralIndex(options) {
  1961. const index = isNumber2(options.pluralIndex) ? options.pluralIndex : -1;
  1962. return options.named && (isNumber2(options.named.count) || isNumber2(options.named.n)) ? isNumber2(options.named.count) ? options.named.count : isNumber2(options.named.n) ? options.named.n : index : index;
  1963. }
  1964. function normalizeNamed(pluralIndex, props) {
  1965. if (!props.count) {
  1966. props.count = pluralIndex;
  1967. }
  1968. if (!props.n) {
  1969. props.n = pluralIndex;
  1970. }
  1971. }
  1972. function createMessageContext(options = {}) {
  1973. const locale = options.locale;
  1974. const pluralIndex = getPluralIndex(options);
  1975. const pluralRule = isObject2(options.pluralRules) && isString2(locale) && isFunction2(options.pluralRules[locale]) ? options.pluralRules[locale] : pluralDefault;
  1976. const orgPluralRule = isObject2(options.pluralRules) && isString2(locale) && isFunction2(options.pluralRules[locale]) ? pluralDefault : void 0;
  1977. const plural = (messages) => {
  1978. return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
  1979. };
  1980. const _list = options.list || [];
  1981. const list = (index) => _list[index];
  1982. const _named = options.named || {};
  1983. isNumber2(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
  1984. const named = (key) => _named[key];
  1985. function message(key) {
  1986. const msg = isFunction2(options.messages) ? options.messages(key) : isObject2(options.messages) ? options.messages[key] : false;
  1987. return !msg ? options.parent ? options.parent.message(key) : DEFAULT_MESSAGE : msg;
  1988. }
  1989. const _modifier = (name) => options.modifiers ? options.modifiers[name] : DEFAULT_MODIFIER;
  1990. const normalize = isPlainObject2(options.processor) && isFunction2(options.processor.normalize) ? options.processor.normalize : DEFAULT_NORMALIZE;
  1991. const interpolate = isPlainObject2(options.processor) && isFunction2(options.processor.interpolate) ? options.processor.interpolate : DEFAULT_INTERPOLATE;
  1992. const type = isPlainObject2(options.processor) && isString2(options.processor.type) ? options.processor.type : DEFAULT_MESSAGE_DATA_TYPE;
  1993. const linked = (key, ...args) => {
  1994. const [arg1, arg2] = args;
  1995. let type2 = "text";
  1996. let modifier = "";
  1997. if (args.length === 1) {
  1998. if (isObject2(arg1)) {
  1999. modifier = arg1.modifier || modifier;
  2000. type2 = arg1.type || type2;
  2001. } else if (isString2(arg1)) {
  2002. modifier = arg1 || modifier;
  2003. }
  2004. } else if (args.length === 2) {
  2005. if (isString2(arg1)) {
  2006. modifier = arg1 || modifier;
  2007. }
  2008. if (isString2(arg2)) {
  2009. type2 = arg2 || type2;
  2010. }
  2011. }
  2012. const ret = message(key)(ctx);
  2013. const msg = (
  2014. // The message in vnode resolved with linked are returned as an array by processor.nomalize
  2015. type2 === "vnode" && isArray2(ret) && modifier ? ret[0] : ret
  2016. );
  2017. return modifier ? _modifier(modifier)(msg, type2) : msg;
  2018. };
  2019. const ctx = {
  2020. [
  2021. "list"
  2022. /* HelperNameMap.LIST */
  2023. ]: list,
  2024. [
  2025. "named"
  2026. /* HelperNameMap.NAMED */
  2027. ]: named,
  2028. [
  2029. "plural"
  2030. /* HelperNameMap.PLURAL */
  2031. ]: plural,
  2032. [
  2033. "linked"
  2034. /* HelperNameMap.LINKED */
  2035. ]: linked,
  2036. [
  2037. "message"
  2038. /* HelperNameMap.MESSAGE */
  2039. ]: message,
  2040. [
  2041. "type"
  2042. /* HelperNameMap.TYPE */
  2043. ]: type,
  2044. [
  2045. "interpolate"
  2046. /* HelperNameMap.INTERPOLATE */
  2047. ]: interpolate,
  2048. [
  2049. "normalize"
  2050. /* HelperNameMap.NORMALIZE */
  2051. ]: normalize,
  2052. [
  2053. "values"
  2054. /* HelperNameMap.VALUES */
  2055. ]: assign2({}, _list, _named)
  2056. };
  2057. return ctx;
  2058. }
  2059. function setDevToolsHook(hook) {
  2060. devtools = hook;
  2061. }
  2062. function getDevToolsHook() {
  2063. return devtools;
  2064. }
  2065. function initI18nDevTools(i18n, version, meta) {
  2066. devtools && devtools.emit("i18n:init", {
  2067. timestamp: Date.now(),
  2068. i18n,
  2069. version,
  2070. meta
  2071. });
  2072. }
  2073. function createDevToolsHook(hook) {
  2074. return (payloads) => devtools && devtools.emit(hook, payloads);
  2075. }
  2076. function getWarnMessage(code2, ...args) {
  2077. return format$1(warnMessages[code2], ...args);
  2078. }
  2079. function createCoreError(code2) {
  2080. return createCompileError(code2, null, { messages: errorMessages });
  2081. }
  2082. function getLocale(context, options) {
  2083. return options.locale != null ? resolveLocale(options.locale) : resolveLocale(context.locale);
  2084. }
  2085. function resolveLocale(locale) {
  2086. if (isString2(locale)) {
  2087. return locale;
  2088. } else {
  2089. if (isFunction2(locale)) {
  2090. if (locale.resolvedOnce && _resolveLocale != null) {
  2091. return _resolveLocale;
  2092. } else if (locale.constructor.name === "Function") {
  2093. const resolve = locale();
  2094. if (isPromise2(resolve)) {
  2095. throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
  2096. }
  2097. return _resolveLocale = resolve;
  2098. } else {
  2099. throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
  2100. }
  2101. } else {
  2102. throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
  2103. }
  2104. }
  2105. }
  2106. function fallbackWithSimple(ctx, fallback, start) {
  2107. return [.../* @__PURE__ */ new Set([
  2108. start,
  2109. ...isArray2(fallback) ? fallback : isObject2(fallback) ? Object.keys(fallback) : isString2(fallback) ? [fallback] : [start]
  2110. ])];
  2111. }
  2112. function fallbackWithLocaleChain(ctx, fallback, start) {
  2113. const startLocale = isString2(start) ? start : DEFAULT_LOCALE;
  2114. const context = ctx;
  2115. if (!context.__localeChainCache) {
  2116. context.__localeChainCache = /* @__PURE__ */ new Map();
  2117. }
  2118. let chain = context.__localeChainCache.get(startLocale);
  2119. if (!chain) {
  2120. chain = [];
  2121. let block = [start];
  2122. while (isArray2(block)) {
  2123. block = appendBlockToChain(chain, block, fallback);
  2124. }
  2125. const defaults = isArray2(fallback) || !isPlainObject2(fallback) ? fallback : fallback["default"] ? fallback["default"] : null;
  2126. block = isString2(defaults) ? [defaults] : defaults;
  2127. if (isArray2(block)) {
  2128. appendBlockToChain(chain, block, false);
  2129. }
  2130. context.__localeChainCache.set(startLocale, chain);
  2131. }
  2132. return chain;
  2133. }
  2134. function appendBlockToChain(chain, block, blocks) {
  2135. let follow = true;
  2136. for (let i = 0; i < block.length && isBoolean2(follow); i++) {
  2137. const locale = block[i];
  2138. if (isString2(locale)) {
  2139. follow = appendLocaleToChain(chain, block[i], blocks);
  2140. }
  2141. }
  2142. return follow;
  2143. }
  2144. function appendLocaleToChain(chain, locale, blocks) {
  2145. let follow;
  2146. const tokens = locale.split("-");
  2147. do {
  2148. const target = tokens.join("-");
  2149. follow = appendItemToChain(chain, target, blocks);
  2150. tokens.splice(-1, 1);
  2151. } while (tokens.length && follow === true);
  2152. return follow;
  2153. }
  2154. function appendItemToChain(chain, target, blocks) {
  2155. let follow = false;
  2156. if (!chain.includes(target)) {
  2157. follow = true;
  2158. if (target) {
  2159. follow = target[target.length - 1] !== "!";
  2160. const locale = target.replace(/!/g, "");
  2161. chain.push(locale);
  2162. if ((isArray2(blocks) || isPlainObject2(blocks)) && blocks[locale]) {
  2163. follow = blocks[locale];
  2164. }
  2165. }
  2166. }
  2167. return follow;
  2168. }
  2169. function getDefaultLinkedModifiers() {
  2170. return {
  2171. upper: (val, type) => {
  2172. return type === "text" && isString2(val) ? val.toUpperCase() : type === "vnode" && isObject2(val) && "__v_isVNode" in val ? val.children.toUpperCase() : val;
  2173. },
  2174. lower: (val, type) => {
  2175. return type === "text" && isString2(val) ? val.toLowerCase() : type === "vnode" && isObject2(val) && "__v_isVNode" in val ? val.children.toLowerCase() : val;
  2176. },
  2177. capitalize: (val, type) => {
  2178. return type === "text" && isString2(val) ? capitalize(val) : type === "vnode" && isObject2(val) && "__v_isVNode" in val ? capitalize(val.children) : val;
  2179. }
  2180. };
  2181. }
  2182. function registerMessageCompiler(compiler) {
  2183. _compiler = compiler;
  2184. }
  2185. function registerMessageResolver(resolver) {
  2186. _resolver = resolver;
  2187. }
  2188. function registerLocaleFallbacker(fallbacker) {
  2189. _fallbacker = fallbacker;
  2190. }
  2191. function createCoreContext(options = {}) {
  2192. const onWarn = isFunction2(options.onWarn) ? options.onWarn : warn2;
  2193. const version = isString2(options.version) ? options.version : VERSION;
  2194. const locale = isString2(options.locale) || isFunction2(options.locale) ? options.locale : DEFAULT_LOCALE;
  2195. const _locale = isFunction2(locale) ? DEFAULT_LOCALE : locale;
  2196. const fallbackLocale = isArray2(options.fallbackLocale) || isPlainObject2(options.fallbackLocale) || isString2(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale;
  2197. const messages = isPlainObject2(options.messages) ? options.messages : { [_locale]: {} };
  2198. const datetimeFormats = isPlainObject2(options.datetimeFormats) ? options.datetimeFormats : { [_locale]: {} };
  2199. const numberFormats = isPlainObject2(options.numberFormats) ? options.numberFormats : { [_locale]: {} };
  2200. const modifiers = assign2({}, options.modifiers || {}, getDefaultLinkedModifiers());
  2201. const pluralRules = options.pluralRules || {};
  2202. const missing = isFunction2(options.missing) ? options.missing : null;
  2203. const missingWarn = isBoolean2(options.missingWarn) || isRegExp2(options.missingWarn) ? options.missingWarn : true;
  2204. const fallbackWarn = isBoolean2(options.fallbackWarn) || isRegExp2(options.fallbackWarn) ? options.fallbackWarn : true;
  2205. const fallbackFormat = !!options.fallbackFormat;
  2206. const unresolving = !!options.unresolving;
  2207. const postTranslation = isFunction2(options.postTranslation) ? options.postTranslation : null;
  2208. const processor = isPlainObject2(options.processor) ? options.processor : null;
  2209. const warnHtmlMessage = isBoolean2(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
  2210. const escapeParameter = !!options.escapeParameter;
  2211. const messageCompiler = isFunction2(options.messageCompiler) ? options.messageCompiler : _compiler;
  2212. if (isFunction2(options.messageCompiler)) {
  2213. warnOnce2(getWarnMessage(CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER));
  2214. }
  2215. const messageResolver = isFunction2(options.messageResolver) ? options.messageResolver : _resolver || resolveWithKeyValue;
  2216. const localeFallbacker = isFunction2(options.localeFallbacker) ? options.localeFallbacker : _fallbacker || fallbackWithSimple;
  2217. const fallbackContext = isObject2(options.fallbackContext) ? options.fallbackContext : void 0;
  2218. const internalOptions = options;
  2219. const __datetimeFormatters = isObject2(internalOptions.__datetimeFormatters) ? internalOptions.__datetimeFormatters : /* @__PURE__ */ new Map();
  2220. const __numberFormatters = isObject2(internalOptions.__numberFormatters) ? internalOptions.__numberFormatters : /* @__PURE__ */ new Map();
  2221. const __meta = isObject2(internalOptions.__meta) ? internalOptions.__meta : {};
  2222. _cid++;
  2223. const context = {
  2224. version,
  2225. cid: _cid,
  2226. locale,
  2227. fallbackLocale,
  2228. messages,
  2229. modifiers,
  2230. pluralRules,
  2231. missing,
  2232. missingWarn,
  2233. fallbackWarn,
  2234. fallbackFormat,
  2235. unresolving,
  2236. postTranslation,
  2237. processor,
  2238. warnHtmlMessage,
  2239. escapeParameter,
  2240. messageCompiler,
  2241. messageResolver,
  2242. localeFallbacker,
  2243. fallbackContext,
  2244. onWarn,
  2245. __meta
  2246. };
  2247. {
  2248. context.datetimeFormats = datetimeFormats;
  2249. context.numberFormats = numberFormats;
  2250. context.__datetimeFormatters = __datetimeFormatters;
  2251. context.__numberFormatters = __numberFormatters;
  2252. }
  2253. {
  2254. context.__v_emitter = internalOptions.__v_emitter != null ? internalOptions.__v_emitter : void 0;
  2255. }
  2256. {
  2257. initI18nDevTools(context, version, __meta);
  2258. }
  2259. return context;
  2260. }
  2261. function isTranslateFallbackWarn(fallback, key) {
  2262. return fallback instanceof RegExp ? fallback.test(key) : fallback;
  2263. }
  2264. function isTranslateMissingWarn(missing, key) {
  2265. return missing instanceof RegExp ? missing.test(key) : missing;
  2266. }
  2267. function handleMissing(context, key, locale, missingWarn, type) {
  2268. const { missing, onWarn } = context;
  2269. {
  2270. const emitter = context.__v_emitter;
  2271. if (emitter) {
  2272. emitter.emit("missing", {
  2273. locale,
  2274. key,
  2275. type,
  2276. groupId: `${type}:${key}`
  2277. });
  2278. }
  2279. }
  2280. if (missing !== null) {
  2281. const ret = missing(context, locale, key, type);
  2282. return isString2(ret) ? ret : key;
  2283. } else {
  2284. if (isTranslateMissingWarn(missingWarn, key)) {
  2285. onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
  2286. }
  2287. return key;
  2288. }
  2289. }
  2290. function updateFallbackLocale(ctx, locale, fallback) {
  2291. const context = ctx;
  2292. context.__localeChainCache = /* @__PURE__ */ new Map();
  2293. ctx.localeFallbacker(ctx, fallback, locale);
  2294. }
  2295. function isAlmostSameLocale(locale, compareLocale) {
  2296. if (locale === compareLocale)
  2297. return false;
  2298. return locale.split("-")[0] === compareLocale.split("-")[0];
  2299. }
  2300. function isImplicitFallback(targetLocale, locales) {
  2301. const index = locales.indexOf(targetLocale);
  2302. if (index === -1) {
  2303. return false;
  2304. }
  2305. for (let i = index + 1; i < locales.length; i++) {
  2306. if (isAlmostSameLocale(targetLocale, locales[i])) {
  2307. return true;
  2308. }
  2309. }
  2310. return false;
  2311. }
  2312. function format2(ast) {
  2313. const msg = (ctx) => formatParts(ctx, ast);
  2314. return msg;
  2315. }
  2316. function formatParts(ctx, ast) {
  2317. const body = ast.b || ast.body;
  2318. if ((body.t || body.type) === 1) {
  2319. const plural = body;
  2320. const cases = plural.c || plural.cases;
  2321. return ctx.plural(cases.reduce((messages, c) => [
  2322. ...messages,
  2323. formatMessageParts(ctx, c)
  2324. ], []));
  2325. } else {
  2326. return formatMessageParts(ctx, body);
  2327. }
  2328. }
  2329. function formatMessageParts(ctx, node) {
  2330. const _static = node.s || node.static;
  2331. if (_static) {
  2332. return ctx.type === "text" ? _static : ctx.normalize([_static]);
  2333. } else {
  2334. const messages = (node.i || node.items).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
  2335. return ctx.normalize(messages);
  2336. }
  2337. }
  2338. function formatMessagePart(ctx, node) {
  2339. const type = node.t || node.type;
  2340. switch (type) {
  2341. case 3: {
  2342. const text = node;
  2343. return text.v || text.value;
  2344. }
  2345. case 9: {
  2346. const literal = node;
  2347. return literal.v || literal.value;
  2348. }
  2349. case 4: {
  2350. const named = node;
  2351. return ctx.interpolate(ctx.named(named.k || named.key));
  2352. }
  2353. case 5: {
  2354. const list = node;
  2355. return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
  2356. }
  2357. case 6: {
  2358. const linked = node;
  2359. const modifier = linked.m || linked.modifier;
  2360. return ctx.linked(formatMessagePart(ctx, linked.k || linked.key), modifier ? formatMessagePart(ctx, modifier) : void 0, ctx.type);
  2361. }
  2362. case 7: {
  2363. const linkedKey = node;
  2364. return linkedKey.v || linkedKey.value;
  2365. }
  2366. case 8: {
  2367. const linkedModifier = node;
  2368. return linkedModifier.v || linkedModifier.value;
  2369. }
  2370. default:
  2371. throw new Error(`unhandled node type on format message part: ${type}`);
  2372. }
  2373. }
  2374. function checkHtmlMessage(source, warnHtmlMessage) {
  2375. if (warnHtmlMessage && detectHtmlTag(source)) {
  2376. warn2(format$1(WARN_MESSAGE, { source }));
  2377. }
  2378. }
  2379. function onCompileWarn(_warn) {
  2380. if (_warn.code === CompileWarnCodes.USE_MODULO_SYNTAX) {
  2381. warn2(`The use of named interpolation with modulo syntax is deprecated. It will be removed in v10.
  2382. reference: https://vue-i18n.intlify.dev/guide/essentials/syntax#rails-i18n-format
  2383. (message compiler warning message: ${_warn.message})`);
  2384. }
  2385. }
  2386. function clearCompileCache() {
  2387. compileCache = /* @__PURE__ */ Object.create(null);
  2388. }
  2389. function baseCompile(message, options = {}) {
  2390. let detectError = false;
  2391. const onError = options.onError || defaultOnError;
  2392. options.onError = (err) => {
  2393. detectError = true;
  2394. onError(err);
  2395. };
  2396. return { ...baseCompile$1(message, options), detectError };
  2397. }
  2398. function compile(message, context) {
  2399. {
  2400. context.onWarn = onCompileWarn;
  2401. }
  2402. if (isString2(message)) {
  2403. const warnHtmlMessage = isBoolean2(context.warnHtmlMessage) ? context.warnHtmlMessage : true;
  2404. checkHtmlMessage(message, warnHtmlMessage);
  2405. const onCacheKey = context.onCacheKey || defaultOnCacheKey;
  2406. const cacheKey = onCacheKey(message);
  2407. const cached = compileCache[cacheKey];
  2408. if (cached) {
  2409. return cached;
  2410. }
  2411. const { ast, detectError } = baseCompile(message, {
  2412. ...context,
  2413. location: true,
  2414. jit: true
  2415. });
  2416. const msg = format2(ast);
  2417. return !detectError ? compileCache[cacheKey] = msg : msg;
  2418. } else {
  2419. if (!isMessageAST(message)) {
  2420. warn2(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
  2421. return () => message;
  2422. }
  2423. const cacheKey = message.cacheKey;
  2424. if (cacheKey) {
  2425. const cached = compileCache[cacheKey];
  2426. if (cached) {
  2427. return cached;
  2428. }
  2429. return compileCache[cacheKey] = format2(message);
  2430. } else {
  2431. return format2(message);
  2432. }
  2433. }
  2434. }
  2435. function translate(context, ...args) {
  2436. const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
  2437. const [key, options] = parseTranslateArgs(...args);
  2438. const missingWarn = isBoolean2(options.missingWarn) ? options.missingWarn : context.missingWarn;
  2439. const fallbackWarn = isBoolean2(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
  2440. const escapeParameter = isBoolean2(options.escapeParameter) ? options.escapeParameter : context.escapeParameter;
  2441. const resolvedMessage = !!options.resolvedMessage;
  2442. const defaultMsgOrKey = isString2(options.default) || isBoolean2(options.default) ? !isBoolean2(options.default) ? options.default : !messageCompiler ? () => key : key : fallbackFormat ? !messageCompiler ? () => key : key : "";
  2443. const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== "";
  2444. const locale = getLocale(context, options);
  2445. escapeParameter && escapeParams(options);
  2446. let [formatScope, targetLocale, message] = !resolvedMessage ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) : [
  2447. key,
  2448. locale,
  2449. messages[locale] || {}
  2450. ];
  2451. let format3 = formatScope;
  2452. let cacheBaseKey = key;
  2453. if (!resolvedMessage && !(isString2(format3) || isMessageAST(format3) || isMessageFunction(format3))) {
  2454. if (enableDefaultMsg) {
  2455. format3 = defaultMsgOrKey;
  2456. cacheBaseKey = format3;
  2457. }
  2458. }
  2459. if (!resolvedMessage && (!(isString2(format3) || isMessageAST(format3) || isMessageFunction(format3)) || !isString2(targetLocale))) {
  2460. return unresolving ? NOT_REOSLVED : key;
  2461. }
  2462. if (isString2(format3) && context.messageCompiler == null) {
  2463. warn2(`The message format compilation is not supported in this build. Because message compiler isn't included. You need to pre-compilation all message format. So translate function return '${key}'.`);
  2464. return key;
  2465. }
  2466. let occurred = false;
  2467. const onError = () => {
  2468. occurred = true;
  2469. };
  2470. const msg = !isMessageFunction(format3) ? compileMessageFormat(context, key, targetLocale, format3, cacheBaseKey, onError) : format3;
  2471. if (occurred) {
  2472. return format3;
  2473. }
  2474. const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
  2475. const msgContext = createMessageContext(ctxOptions);
  2476. const messaged = evaluateMessage(context, msg, msgContext);
  2477. const ret = postTranslation ? postTranslation(messaged, key) : messaged;
  2478. {
  2479. const payloads = {
  2480. timestamp: Date.now(),
  2481. key: isString2(key) ? key : isMessageFunction(format3) ? format3.key : "",
  2482. locale: targetLocale || (isMessageFunction(format3) ? format3.locale : ""),
  2483. format: isString2(format3) ? format3 : isMessageFunction(format3) ? format3.source : "",
  2484. message: ret
  2485. };
  2486. payloads.meta = assign2({}, context.__meta, getAdditionalMeta() || {});
  2487. translateDevTools(payloads);
  2488. }
  2489. return ret;
  2490. }
  2491. function escapeParams(options) {
  2492. if (isArray2(options.list)) {
  2493. options.list = options.list.map((item) => isString2(item) ? escapeHtml2(item) : item);
  2494. } else if (isObject2(options.named)) {
  2495. Object.keys(options.named).forEach((key) => {
  2496. if (isString2(options.named[key])) {
  2497. options.named[key] = escapeHtml2(options.named[key]);
  2498. }
  2499. });
  2500. }
  2501. }
  2502. function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
  2503. const { messages, onWarn, messageResolver: resolveValue2, localeFallbacker } = context;
  2504. const locales = localeFallbacker(context, fallbackLocale, locale);
  2505. let message = {};
  2506. let targetLocale;
  2507. let format3 = null;
  2508. let from = locale;
  2509. let to = null;
  2510. const type = "translate";
  2511. for (let i = 0; i < locales.length; i++) {
  2512. targetLocale = to = locales[i];
  2513. if (locale !== targetLocale && !isAlmostSameLocale(locale, targetLocale) && isTranslateFallbackWarn(fallbackWarn, key)) {
  2514. onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
  2515. key,
  2516. target: targetLocale
  2517. }));
  2518. }
  2519. if (locale !== targetLocale) {
  2520. const emitter = context.__v_emitter;
  2521. if (emitter) {
  2522. emitter.emit("fallback", {
  2523. type,
  2524. key,
  2525. from,
  2526. to,
  2527. groupId: `${type}:${key}`
  2528. });
  2529. }
  2530. }
  2531. message = messages[targetLocale] || {};
  2532. let start = null;
  2533. let startTag;
  2534. let endTag;
  2535. if (inBrowser2) {
  2536. start = window.performance.now();
  2537. startTag = "intlify-message-resolve-start";
  2538. endTag = "intlify-message-resolve-end";
  2539. mark2 && mark2(startTag);
  2540. }
  2541. if ((format3 = resolveValue2(message, key)) === null) {
  2542. format3 = message[key];
  2543. }
  2544. if (inBrowser2) {
  2545. const end = window.performance.now();
  2546. const emitter = context.__v_emitter;
  2547. if (emitter && start && format3) {
  2548. emitter.emit("message-resolve", {
  2549. type: "message-resolve",
  2550. key,
  2551. message: format3,
  2552. time: end - start,
  2553. groupId: `${type}:${key}`
  2554. });
  2555. }
  2556. if (startTag && endTag && mark2 && measure2) {
  2557. mark2(endTag);
  2558. measure2("intlify message resolve", startTag, endTag);
  2559. }
  2560. }
  2561. if (isString2(format3) || isMessageAST(format3) || isMessageFunction(format3)) {
  2562. break;
  2563. }
  2564. if (!isImplicitFallback(targetLocale, locales)) {
  2565. const missingRet = handleMissing(
  2566. context,
  2567. // eslint-disable-line @typescript-eslint/no-explicit-any
  2568. key,
  2569. targetLocale,
  2570. missingWarn,
  2571. type
  2572. );
  2573. if (missingRet !== key) {
  2574. format3 = missingRet;
  2575. }
  2576. }
  2577. from = to;
  2578. }
  2579. return [format3, targetLocale, message];
  2580. }
  2581. function compileMessageFormat(context, key, targetLocale, format3, cacheBaseKey, onError) {
  2582. const { messageCompiler, warnHtmlMessage } = context;
  2583. if (isMessageFunction(format3)) {
  2584. const msg2 = format3;
  2585. msg2.locale = msg2.locale || targetLocale;
  2586. msg2.key = msg2.key || key;
  2587. return msg2;
  2588. }
  2589. if (messageCompiler == null) {
  2590. const msg2 = () => format3;
  2591. msg2.locale = targetLocale;
  2592. msg2.key = key;
  2593. return msg2;
  2594. }
  2595. let start = null;
  2596. let startTag;
  2597. let endTag;
  2598. if (inBrowser2) {
  2599. start = window.performance.now();
  2600. startTag = "intlify-message-compilation-start";
  2601. endTag = "intlify-message-compilation-end";
  2602. mark2 && mark2(startTag);
  2603. }
  2604. const msg = messageCompiler(format3, getCompileContext(context, targetLocale, cacheBaseKey, format3, warnHtmlMessage, onError));
  2605. if (inBrowser2) {
  2606. const end = window.performance.now();
  2607. const emitter = context.__v_emitter;
  2608. if (emitter && start) {
  2609. emitter.emit("message-compilation", {
  2610. type: "message-compilation",
  2611. message: format3,
  2612. time: end - start,
  2613. groupId: `${"translate"}:${key}`
  2614. });
  2615. }
  2616. if (startTag && endTag && mark2 && measure2) {
  2617. mark2(endTag);
  2618. measure2("intlify message compilation", startTag, endTag);
  2619. }
  2620. }
  2621. msg.locale = targetLocale;
  2622. msg.key = key;
  2623. msg.source = format3;
  2624. return msg;
  2625. }
  2626. function evaluateMessage(context, msg, msgCtx) {
  2627. let start = null;
  2628. let startTag;
  2629. let endTag;
  2630. if (inBrowser2) {
  2631. start = window.performance.now();
  2632. startTag = "intlify-message-evaluation-start";
  2633. endTag = "intlify-message-evaluation-end";
  2634. mark2 && mark2(startTag);
  2635. }
  2636. const messaged = msg(msgCtx);
  2637. if (inBrowser2) {
  2638. const end = window.performance.now();
  2639. const emitter = context.__v_emitter;
  2640. if (emitter && start) {
  2641. emitter.emit("message-evaluation", {
  2642. type: "message-evaluation",
  2643. value: messaged,
  2644. time: end - start,
  2645. groupId: `${"translate"}:${msg.key}`
  2646. });
  2647. }
  2648. if (startTag && endTag && mark2 && measure2) {
  2649. mark2(endTag);
  2650. measure2("intlify message evaluation", startTag, endTag);
  2651. }
  2652. }
  2653. return messaged;
  2654. }
  2655. function parseTranslateArgs(...args) {
  2656. const [arg1, arg2, arg3] = args;
  2657. const options = {};
  2658. if (!isString2(arg1) && !isNumber2(arg1) && !isMessageFunction(arg1) && !isMessageAST(arg1)) {
  2659. throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
  2660. }
  2661. const key = isNumber2(arg1) ? String(arg1) : isMessageFunction(arg1) ? arg1 : arg1;
  2662. if (isNumber2(arg2)) {
  2663. options.plural = arg2;
  2664. } else if (isString2(arg2)) {
  2665. options.default = arg2;
  2666. } else if (isPlainObject2(arg2) && !isEmptyObject2(arg2)) {
  2667. options.named = arg2;
  2668. } else if (isArray2(arg2)) {
  2669. options.list = arg2;
  2670. }
  2671. if (isNumber2(arg3)) {
  2672. options.plural = arg3;
  2673. } else if (isString2(arg3)) {
  2674. options.default = arg3;
  2675. } else if (isPlainObject2(arg3)) {
  2676. assign2(options, arg3);
  2677. }
  2678. return [key, options];
  2679. }
  2680. function getCompileContext(context, locale, key, source, warnHtmlMessage, onError) {
  2681. return {
  2682. locale,
  2683. key,
  2684. warnHtmlMessage,
  2685. onError: (err) => {
  2686. onError && onError(err);
  2687. {
  2688. const _source = getSourceForCodeFrame(source);
  2689. const message = `Message compilation error: ${err.message}`;
  2690. const codeFrame = err.location && _source && generateCodeFrame2(_source, err.location.start.offset, err.location.end.offset);
  2691. const emitter = context.__v_emitter;
  2692. if (emitter && _source) {
  2693. emitter.emit("compile-error", {
  2694. message: _source,
  2695. error: err.message,
  2696. start: err.location && err.location.start.offset,
  2697. end: err.location && err.location.end.offset,
  2698. groupId: `${"translate"}:${key}`
  2699. });
  2700. }
  2701. console.error(codeFrame ? `${message}
  2702. ${codeFrame}` : message);
  2703. }
  2704. },
  2705. onCacheKey: (source2) => generateFormatCacheKey2(locale, key, source2)
  2706. };
  2707. }
  2708. function getSourceForCodeFrame(source) {
  2709. if (isString2(source)) {
  2710. return source;
  2711. } else {
  2712. if (source.loc && source.loc.source) {
  2713. return source.loc.source;
  2714. }
  2715. }
  2716. }
  2717. function getMessageContextOptions(context, locale, message, options) {
  2718. const { modifiers, pluralRules, messageResolver: resolveValue2, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
  2719. const resolveMessage = (key) => {
  2720. let val = resolveValue2(message, key);
  2721. if (val == null && fallbackContext) {
  2722. const [, , message2] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
  2723. val = resolveValue2(message2, key);
  2724. }
  2725. if (isString2(val) || isMessageAST(val)) {
  2726. let occurred = false;
  2727. const onError = () => {
  2728. occurred = true;
  2729. };
  2730. const msg = compileMessageFormat(context, key, locale, val, key, onError);
  2731. return !occurred ? msg : NOOP_MESSAGE_FUNCTION;
  2732. } else if (isMessageFunction(val)) {
  2733. return val;
  2734. } else {
  2735. return NOOP_MESSAGE_FUNCTION;
  2736. }
  2737. };
  2738. const ctxOptions = {
  2739. locale,
  2740. modifiers,
  2741. pluralRules,
  2742. messages: resolveMessage
  2743. };
  2744. if (context.processor) {
  2745. ctxOptions.processor = context.processor;
  2746. }
  2747. if (options.list) {
  2748. ctxOptions.list = options.list;
  2749. }
  2750. if (options.named) {
  2751. ctxOptions.named = options.named;
  2752. }
  2753. if (isNumber2(options.plural)) {
  2754. ctxOptions.pluralIndex = options.plural;
  2755. }
  2756. return ctxOptions;
  2757. }
  2758. function datetime(context, ...args) {
  2759. const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
  2760. const { __datetimeFormatters } = context;
  2761. if (!Availabilities.dateTimeFormat) {
  2762. onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
  2763. return MISSING_RESOLVE_VALUE;
  2764. }
  2765. const [key, value, options, overrides] = parseDateTimeArgs(...args);
  2766. const missingWarn = isBoolean2(options.missingWarn) ? options.missingWarn : context.missingWarn;
  2767. const fallbackWarn = isBoolean2(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
  2768. const part = !!options.part;
  2769. const locale = getLocale(context, options);
  2770. const locales = localeFallbacker(
  2771. context,
  2772. // eslint-disable-line @typescript-eslint/no-explicit-any
  2773. fallbackLocale,
  2774. locale
  2775. );
  2776. if (!isString2(key) || key === "") {
  2777. return new Intl.DateTimeFormat(locale, overrides).format(value);
  2778. }
  2779. let datetimeFormat = {};
  2780. let targetLocale;
  2781. let format3 = null;
  2782. let from = locale;
  2783. let to = null;
  2784. const type = "datetime format";
  2785. for (let i = 0; i < locales.length; i++) {
  2786. targetLocale = to = locales[i];
  2787. if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) {
  2788. onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
  2789. key,
  2790. target: targetLocale
  2791. }));
  2792. }
  2793. if (locale !== targetLocale) {
  2794. const emitter = context.__v_emitter;
  2795. if (emitter) {
  2796. emitter.emit("fallback", {
  2797. type,
  2798. key,
  2799. from,
  2800. to,
  2801. groupId: `${type}:${key}`
  2802. });
  2803. }
  2804. }
  2805. datetimeFormat = datetimeFormats[targetLocale] || {};
  2806. format3 = datetimeFormat[key];
  2807. if (isPlainObject2(format3))
  2808. break;
  2809. handleMissing(context, key, targetLocale, missingWarn, type);
  2810. from = to;
  2811. }
  2812. if (!isPlainObject2(format3) || !isString2(targetLocale)) {
  2813. return unresolving ? NOT_REOSLVED : key;
  2814. }
  2815. let id = `${targetLocale}__${key}`;
  2816. if (!isEmptyObject2(overrides)) {
  2817. id = `${id}__${JSON.stringify(overrides)}`;
  2818. }
  2819. let formatter = __datetimeFormatters.get(id);
  2820. if (!formatter) {
  2821. formatter = new Intl.DateTimeFormat(targetLocale, assign2({}, format3, overrides));
  2822. __datetimeFormatters.set(id, formatter);
  2823. }
  2824. return !part ? formatter.format(value) : formatter.formatToParts(value);
  2825. }
  2826. function parseDateTimeArgs(...args) {
  2827. const [arg1, arg2, arg3, arg4] = args;
  2828. const options = {};
  2829. let overrides = {};
  2830. let value;
  2831. if (isString2(arg1)) {
  2832. const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
  2833. if (!matches) {
  2834. throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
  2835. }
  2836. const dateTime = matches[3] ? matches[3].trim().startsWith("T") ? `${matches[1].trim()}${matches[3].trim()}` : `${matches[1].trim()}T${matches[3].trim()}` : matches[1].trim();
  2837. value = new Date(dateTime);
  2838. try {
  2839. value.toISOString();
  2840. } catch (e) {
  2841. throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
  2842. }
  2843. } else if (isDate2(arg1)) {
  2844. if (isNaN(arg1.getTime())) {
  2845. throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
  2846. }
  2847. value = arg1;
  2848. } else if (isNumber2(arg1)) {
  2849. value = arg1;
  2850. } else {
  2851. throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
  2852. }
  2853. if (isString2(arg2)) {
  2854. options.key = arg2;
  2855. } else if (isPlainObject2(arg2)) {
  2856. Object.keys(arg2).forEach((key) => {
  2857. if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
  2858. overrides[key] = arg2[key];
  2859. } else {
  2860. options[key] = arg2[key];
  2861. }
  2862. });
  2863. }
  2864. if (isString2(arg3)) {
  2865. options.locale = arg3;
  2866. } else if (isPlainObject2(arg3)) {
  2867. overrides = arg3;
  2868. }
  2869. if (isPlainObject2(arg4)) {
  2870. overrides = arg4;
  2871. }
  2872. return [options.key || "", value, options, overrides];
  2873. }
  2874. function clearDateTimeFormat(ctx, locale, format3) {
  2875. const context = ctx;
  2876. for (const key in format3) {
  2877. const id = `${locale}__${key}`;
  2878. if (!context.__datetimeFormatters.has(id)) {
  2879. continue;
  2880. }
  2881. context.__datetimeFormatters.delete(id);
  2882. }
  2883. }
  2884. function number(context, ...args) {
  2885. const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
  2886. const { __numberFormatters } = context;
  2887. if (!Availabilities.numberFormat) {
  2888. onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
  2889. return MISSING_RESOLVE_VALUE;
  2890. }
  2891. const [key, value, options, overrides] = parseNumberArgs(...args);
  2892. const missingWarn = isBoolean2(options.missingWarn) ? options.missingWarn : context.missingWarn;
  2893. const fallbackWarn = isBoolean2(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
  2894. const part = !!options.part;
  2895. const locale = getLocale(context, options);
  2896. const locales = localeFallbacker(
  2897. context,
  2898. // eslint-disable-line @typescript-eslint/no-explicit-any
  2899. fallbackLocale,
  2900. locale
  2901. );
  2902. if (!isString2(key) || key === "") {
  2903. return new Intl.NumberFormat(locale, overrides).format(value);
  2904. }
  2905. let numberFormat = {};
  2906. let targetLocale;
  2907. let format3 = null;
  2908. let from = locale;
  2909. let to = null;
  2910. const type = "number format";
  2911. for (let i = 0; i < locales.length; i++) {
  2912. targetLocale = to = locales[i];
  2913. if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) {
  2914. onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
  2915. key,
  2916. target: targetLocale
  2917. }));
  2918. }
  2919. if (locale !== targetLocale) {
  2920. const emitter = context.__v_emitter;
  2921. if (emitter) {
  2922. emitter.emit("fallback", {
  2923. type,
  2924. key,
  2925. from,
  2926. to,
  2927. groupId: `${type}:${key}`
  2928. });
  2929. }
  2930. }
  2931. numberFormat = numberFormats[targetLocale] || {};
  2932. format3 = numberFormat[key];
  2933. if (isPlainObject2(format3))
  2934. break;
  2935. handleMissing(context, key, targetLocale, missingWarn, type);
  2936. from = to;
  2937. }
  2938. if (!isPlainObject2(format3) || !isString2(targetLocale)) {
  2939. return unresolving ? NOT_REOSLVED : key;
  2940. }
  2941. let id = `${targetLocale}__${key}`;
  2942. if (!isEmptyObject2(overrides)) {
  2943. id = `${id}__${JSON.stringify(overrides)}`;
  2944. }
  2945. let formatter = __numberFormatters.get(id);
  2946. if (!formatter) {
  2947. formatter = new Intl.NumberFormat(targetLocale, assign2({}, format3, overrides));
  2948. __numberFormatters.set(id, formatter);
  2949. }
  2950. return !part ? formatter.format(value) : formatter.formatToParts(value);
  2951. }
  2952. function parseNumberArgs(...args) {
  2953. const [arg1, arg2, arg3, arg4] = args;
  2954. const options = {};
  2955. let overrides = {};
  2956. if (!isNumber2(arg1)) {
  2957. throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
  2958. }
  2959. const value = arg1;
  2960. if (isString2(arg2)) {
  2961. options.key = arg2;
  2962. } else if (isPlainObject2(arg2)) {
  2963. Object.keys(arg2).forEach((key) => {
  2964. if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
  2965. overrides[key] = arg2[key];
  2966. } else {
  2967. options[key] = arg2[key];
  2968. }
  2969. });
  2970. }
  2971. if (isString2(arg3)) {
  2972. options.locale = arg3;
  2973. } else if (isPlainObject2(arg3)) {
  2974. overrides = arg3;
  2975. }
  2976. if (isPlainObject2(arg4)) {
  2977. overrides = arg4;
  2978. }
  2979. return [options.key || "", value, options, overrides];
  2980. }
  2981. function clearNumberFormat(ctx, locale, format3) {
  2982. const context = ctx;
  2983. for (const key in format3) {
  2984. const id = `${locale}__${key}`;
  2985. if (!context.__numberFormatters.has(id)) {
  2986. continue;
  2987. }
  2988. context.__numberFormatters.delete(id);
  2989. }
  2990. }
  2991. var inBrowser2, mark2, measure2, RE_ARGS2, generateFormatCacheKey2, friendlyJSONstringify2, isNumber2, isDate2, isRegExp2, isEmptyObject2, assign2, isArray2, isFunction2, isString2, isBoolean2, isObject2, isPromise2, objectToString2, toTypeString2, isPlainObject2, toDisplayString2, RANGE2, hasWarned2, CompileWarnCodes, warnMessages$1, CompileErrorCodes, errorMessages$1, RE_HTML_TAG, detectHtmlTag, CHAR_SP, CHAR_CR, CHAR_LF, CHAR_LS, CHAR_PS, EOF, DOT, LITERAL_DELIMITER, ERROR_DOMAIN$3, ERROR_DOMAIN$2, KNOWN_ESCAPES, ERROR_DOMAIN$1, ERROR_DOMAIN, generate, pathStateMachine, literalValueRE, cache, DEFAULT_MODIFIER, DEFAULT_MESSAGE, DEFAULT_MESSAGE_DATA_TYPE, DEFAULT_NORMALIZE, DEFAULT_INTERPOLATE, devtools, translateDevTools, code$1, inc$1, CoreWarnCodes, warnMessages, code, inc, CoreErrorCodes, errorMessages, _resolveLocale, VERSION, NOT_REOSLVED, DEFAULT_LOCALE, MISSING_RESOLVE_VALUE, capitalize, _compiler, _resolver, _fallbacker, _additionalMeta, setAdditionalMeta, getAdditionalMeta, _fallbackContext, setFallbackContext, getFallbackContext, _cid, WARN_MESSAGE, defaultOnCacheKey, compileCache, isMessageAST, compileToFunction, NOOP_MESSAGE_FUNCTION, isMessageFunction, intlDefined, Availabilities, DATETIME_FORMAT_OPTIONS_KEYS, NUMBER_FORMAT_OPTIONS_KEYS;
  2992. var init_core_base_esm_browser = __esm({
  2993. "node_modules/.pnpm/@intlify+core-base@9.13.1/node_modules/@intlify/core-base/dist/core-base.esm-browser.js"() {
  2994. inBrowser2 = typeof window !== "undefined";
  2995. {
  2996. const perf = inBrowser2 && window.performance;
  2997. if (perf && perf.mark && perf.measure && perf.clearMarks && // @ts-ignore browser compat
  2998. perf.clearMeasures) {
  2999. mark2 = (tag) => {
  3000. perf.mark(tag);
  3001. };
  3002. measure2 = (name, startTag, endTag) => {
  3003. perf.measure(name, startTag, endTag);
  3004. perf.clearMarks(startTag);
  3005. perf.clearMarks(endTag);
  3006. };
  3007. }
  3008. }
  3009. RE_ARGS2 = /\{([0-9a-zA-Z]+)\}/g;
  3010. generateFormatCacheKey2 = (locale, key, source) => friendlyJSONstringify2({ l: locale, k: key, s: source });
  3011. friendlyJSONstringify2 = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
  3012. isNumber2 = (val) => typeof val === "number" && isFinite(val);
  3013. isDate2 = (val) => toTypeString2(val) === "[object Date]";
  3014. isRegExp2 = (val) => toTypeString2(val) === "[object RegExp]";
  3015. isEmptyObject2 = (val) => isPlainObject2(val) && Object.keys(val).length === 0;
  3016. assign2 = Object.assign;
  3017. isArray2 = Array.isArray;
  3018. isFunction2 = (val) => typeof val === "function";
  3019. isString2 = (val) => typeof val === "string";
  3020. isBoolean2 = (val) => typeof val === "boolean";
  3021. isObject2 = (val) => val !== null && typeof val === "object";
  3022. isPromise2 = (val) => {
  3023. return isObject2(val) && isFunction2(val.then) && isFunction2(val.catch);
  3024. };
  3025. objectToString2 = Object.prototype.toString;
  3026. toTypeString2 = (value) => objectToString2.call(value);
  3027. isPlainObject2 = (val) => {
  3028. if (!isObject2(val))
  3029. return false;
  3030. const proto = Object.getPrototypeOf(val);
  3031. return proto === null || proto.constructor === Object;
  3032. };
  3033. toDisplayString2 = (val) => {
  3034. return val == null ? "" : isArray2(val) || isPlainObject2(val) && val.toString === objectToString2 ? JSON.stringify(val, null, 2) : String(val);
  3035. };
  3036. RANGE2 = 2;
  3037. hasWarned2 = {};
  3038. CompileWarnCodes = {
  3039. USE_MODULO_SYNTAX: 1,
  3040. __EXTEND_POINT__: 2
  3041. };
  3042. warnMessages$1 = {
  3043. [CompileWarnCodes.USE_MODULO_SYNTAX]: `Use modulo before '{{0}}'.`
  3044. };
  3045. CompileErrorCodes = {
  3046. // tokenizer error codes
  3047. EXPECTED_TOKEN: 1,
  3048. INVALID_TOKEN_IN_PLACEHOLDER: 2,
  3049. UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
  3050. UNKNOWN_ESCAPE_SEQUENCE: 4,
  3051. INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
  3052. UNBALANCED_CLOSING_BRACE: 6,
  3053. UNTERMINATED_CLOSING_BRACE: 7,
  3054. EMPTY_PLACEHOLDER: 8,
  3055. NOT_ALLOW_NEST_PLACEHOLDER: 9,
  3056. INVALID_LINKED_FORMAT: 10,
  3057. // parser error codes
  3058. MUST_HAVE_MESSAGES_IN_PLURAL: 11,
  3059. UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
  3060. UNEXPECTED_EMPTY_LINKED_KEY: 13,
  3061. UNEXPECTED_LEXICAL_ANALYSIS: 14,
  3062. // generator error codes
  3063. UNHANDLED_CODEGEN_NODE_TYPE: 15,
  3064. // minifier error codes
  3065. UNHANDLED_MINIFIER_NODE_TYPE: 16,
  3066. // Special value for higher-order compilers to pick up the last code
  3067. // to avoid collision of error codes. This should always be kept as the last
  3068. // item.
  3069. __EXTEND_POINT__: 17
  3070. };
  3071. errorMessages$1 = {
  3072. // tokenizer error messages
  3073. [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
  3074. [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
  3075. [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
  3076. [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
  3077. [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
  3078. [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
  3079. [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
  3080. [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
  3081. [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
  3082. [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
  3083. // parser error messages
  3084. [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
  3085. [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
  3086. [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
  3087. [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`,
  3088. // generator error messages
  3089. [CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]: `unhandled codegen node type: '{0}'`,
  3090. // minimizer error messages
  3091. [CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]: `unhandled mimifier node type: '{0}'`
  3092. };
  3093. RE_HTML_TAG = /<\/?[\w\s="/.':;#-\/]+>/;
  3094. detectHtmlTag = (source) => RE_HTML_TAG.test(source);
  3095. CHAR_SP = " ";
  3096. CHAR_CR = "\r";
  3097. CHAR_LF = "\n";
  3098. CHAR_LS = String.fromCharCode(8232);
  3099. CHAR_PS = String.fromCharCode(8233);
  3100. EOF = void 0;
  3101. DOT = ".";
  3102. LITERAL_DELIMITER = "'";
  3103. ERROR_DOMAIN$3 = "tokenizer";
  3104. ERROR_DOMAIN$2 = "parser";
  3105. KNOWN_ESCAPES = /(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;
  3106. ERROR_DOMAIN$1 = "minifier";
  3107. ERROR_DOMAIN = "parser";
  3108. generate = (ast, options = {}) => {
  3109. const mode = isString2(options.mode) ? options.mode : "normal";
  3110. const filename = isString2(options.filename) ? options.filename : "message.intl";
  3111. const sourceMap = !!options.sourceMap;
  3112. const breakLineCode = options.breakLineCode != null ? options.breakLineCode : mode === "arrow" ? ";" : "\n";
  3113. const needIndent = options.needIndent ? options.needIndent : mode !== "arrow";
  3114. const helpers = ast.helpers || [];
  3115. const generator = createCodeGenerator(ast, {
  3116. mode,
  3117. filename,
  3118. sourceMap,
  3119. breakLineCode,
  3120. needIndent
  3121. });
  3122. generator.push(mode === "normal" ? `function __msg__ (ctx) {` : `(ctx) => {`);
  3123. generator.indent(needIndent);
  3124. if (helpers.length > 0) {
  3125. generator.push(`const { ${join2(helpers.map((s) => `${s}: _${s}`), ", ")} } = ctx`);
  3126. generator.newline();
  3127. }
  3128. generator.push(`return `);
  3129. generateNode(generator, ast);
  3130. generator.deindent(needIndent);
  3131. generator.push(`}`);
  3132. delete ast.helpers;
  3133. const { code: code2, map } = generator.context();
  3134. return {
  3135. ast,
  3136. code: code2,
  3137. map: map ? map.toJSON() : void 0
  3138. // eslint-disable-line @typescript-eslint/no-explicit-any
  3139. };
  3140. };
  3141. pathStateMachine = [];
  3142. pathStateMachine[
  3143. 0
  3144. /* States.BEFORE_PATH */
  3145. ] = {
  3146. [
  3147. "w"
  3148. /* PathCharTypes.WORKSPACE */
  3149. ]: [
  3150. 0
  3151. /* States.BEFORE_PATH */
  3152. ],
  3153. [
  3154. "i"
  3155. /* PathCharTypes.IDENT */
  3156. ]: [
  3157. 3,
  3158. 0
  3159. /* Actions.APPEND */
  3160. ],
  3161. [
  3162. "["
  3163. /* PathCharTypes.LEFT_BRACKET */
  3164. ]: [
  3165. 4
  3166. /* States.IN_SUB_PATH */
  3167. ],
  3168. [
  3169. "o"
  3170. /* PathCharTypes.END_OF_FAIL */
  3171. ]: [
  3172. 7
  3173. /* States.AFTER_PATH */
  3174. ]
  3175. };
  3176. pathStateMachine[
  3177. 1
  3178. /* States.IN_PATH */
  3179. ] = {
  3180. [
  3181. "w"
  3182. /* PathCharTypes.WORKSPACE */
  3183. ]: [
  3184. 1
  3185. /* States.IN_PATH */
  3186. ],
  3187. [
  3188. "."
  3189. /* PathCharTypes.DOT */
  3190. ]: [
  3191. 2
  3192. /* States.BEFORE_IDENT */
  3193. ],
  3194. [
  3195. "["
  3196. /* PathCharTypes.LEFT_BRACKET */
  3197. ]: [
  3198. 4
  3199. /* States.IN_SUB_PATH */
  3200. ],
  3201. [
  3202. "o"
  3203. /* PathCharTypes.END_OF_FAIL */
  3204. ]: [
  3205. 7
  3206. /* States.AFTER_PATH */
  3207. ]
  3208. };
  3209. pathStateMachine[
  3210. 2
  3211. /* States.BEFORE_IDENT */
  3212. ] = {
  3213. [
  3214. "w"
  3215. /* PathCharTypes.WORKSPACE */
  3216. ]: [
  3217. 2
  3218. /* States.BEFORE_IDENT */
  3219. ],
  3220. [
  3221. "i"
  3222. /* PathCharTypes.IDENT */
  3223. ]: [
  3224. 3,
  3225. 0
  3226. /* Actions.APPEND */
  3227. ],
  3228. [
  3229. "0"
  3230. /* PathCharTypes.ZERO */
  3231. ]: [
  3232. 3,
  3233. 0
  3234. /* Actions.APPEND */
  3235. ]
  3236. };
  3237. pathStateMachine[
  3238. 3
  3239. /* States.IN_IDENT */
  3240. ] = {
  3241. [
  3242. "i"
  3243. /* PathCharTypes.IDENT */
  3244. ]: [
  3245. 3,
  3246. 0
  3247. /* Actions.APPEND */
  3248. ],
  3249. [
  3250. "0"
  3251. /* PathCharTypes.ZERO */
  3252. ]: [
  3253. 3,
  3254. 0
  3255. /* Actions.APPEND */
  3256. ],
  3257. [
  3258. "w"
  3259. /* PathCharTypes.WORKSPACE */
  3260. ]: [
  3261. 1,
  3262. 1
  3263. /* Actions.PUSH */
  3264. ],
  3265. [
  3266. "."
  3267. /* PathCharTypes.DOT */
  3268. ]: [
  3269. 2,
  3270. 1
  3271. /* Actions.PUSH */
  3272. ],
  3273. [
  3274. "["
  3275. /* PathCharTypes.LEFT_BRACKET */
  3276. ]: [
  3277. 4,
  3278. 1
  3279. /* Actions.PUSH */
  3280. ],
  3281. [
  3282. "o"
  3283. /* PathCharTypes.END_OF_FAIL */
  3284. ]: [
  3285. 7,
  3286. 1
  3287. /* Actions.PUSH */
  3288. ]
  3289. };
  3290. pathStateMachine[
  3291. 4
  3292. /* States.IN_SUB_PATH */
  3293. ] = {
  3294. [
  3295. "'"
  3296. /* PathCharTypes.SINGLE_QUOTE */
  3297. ]: [
  3298. 5,
  3299. 0
  3300. /* Actions.APPEND */
  3301. ],
  3302. [
  3303. '"'
  3304. /* PathCharTypes.DOUBLE_QUOTE */
  3305. ]: [
  3306. 6,
  3307. 0
  3308. /* Actions.APPEND */
  3309. ],
  3310. [
  3311. "["
  3312. /* PathCharTypes.LEFT_BRACKET */
  3313. ]: [
  3314. 4,
  3315. 2
  3316. /* Actions.INC_SUB_PATH_DEPTH */
  3317. ],
  3318. [
  3319. "]"
  3320. /* PathCharTypes.RIGHT_BRACKET */
  3321. ]: [
  3322. 1,
  3323. 3
  3324. /* Actions.PUSH_SUB_PATH */
  3325. ],
  3326. [
  3327. "o"
  3328. /* PathCharTypes.END_OF_FAIL */
  3329. ]: 8,
  3330. [
  3331. "l"
  3332. /* PathCharTypes.ELSE */
  3333. ]: [
  3334. 4,
  3335. 0
  3336. /* Actions.APPEND */
  3337. ]
  3338. };
  3339. pathStateMachine[
  3340. 5
  3341. /* States.IN_SINGLE_QUOTE */
  3342. ] = {
  3343. [
  3344. "'"
  3345. /* PathCharTypes.SINGLE_QUOTE */
  3346. ]: [
  3347. 4,
  3348. 0
  3349. /* Actions.APPEND */
  3350. ],
  3351. [
  3352. "o"
  3353. /* PathCharTypes.END_OF_FAIL */
  3354. ]: 8,
  3355. [
  3356. "l"
  3357. /* PathCharTypes.ELSE */
  3358. ]: [
  3359. 5,
  3360. 0
  3361. /* Actions.APPEND */
  3362. ]
  3363. };
  3364. pathStateMachine[
  3365. 6
  3366. /* States.IN_DOUBLE_QUOTE */
  3367. ] = {
  3368. [
  3369. '"'
  3370. /* PathCharTypes.DOUBLE_QUOTE */
  3371. ]: [
  3372. 4,
  3373. 0
  3374. /* Actions.APPEND */
  3375. ],
  3376. [
  3377. "o"
  3378. /* PathCharTypes.END_OF_FAIL */
  3379. ]: 8,
  3380. [
  3381. "l"
  3382. /* PathCharTypes.ELSE */
  3383. ]: [
  3384. 6,
  3385. 0
  3386. /* Actions.APPEND */
  3387. ]
  3388. };
  3389. literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
  3390. cache = /* @__PURE__ */ new Map();
  3391. DEFAULT_MODIFIER = (str) => str;
  3392. DEFAULT_MESSAGE = (ctx) => "";
  3393. DEFAULT_MESSAGE_DATA_TYPE = "text";
  3394. DEFAULT_NORMALIZE = (values) => values.length === 0 ? "" : join2(values);
  3395. DEFAULT_INTERPOLATE = toDisplayString2;
  3396. devtools = null;
  3397. translateDevTools = createDevToolsHook(
  3398. "function:translate"
  3399. /* IntlifyDevToolsHooks.FunctionTranslate */
  3400. );
  3401. code$1 = CompileWarnCodes.__EXTEND_POINT__;
  3402. inc$1 = incrementer2(code$1);
  3403. CoreWarnCodes = {
  3404. NOT_FOUND_KEY: code$1,
  3405. // 2
  3406. FALLBACK_TO_TRANSLATE: inc$1(),
  3407. // 3
  3408. CANNOT_FORMAT_NUMBER: inc$1(),
  3409. // 4
  3410. FALLBACK_TO_NUMBER_FORMAT: inc$1(),
  3411. // 5
  3412. CANNOT_FORMAT_DATE: inc$1(),
  3413. // 6
  3414. FALLBACK_TO_DATE_FORMAT: inc$1(),
  3415. // 7
  3416. EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: inc$1(),
  3417. // 8
  3418. __EXTEND_POINT__: inc$1()
  3419. // 9
  3420. };
  3421. warnMessages = {
  3422. [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
  3423. [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
  3424. [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
  3425. [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
  3426. [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
  3427. [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
  3428. [CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER]: `This project is using Custom Message Compiler, which is an experimental feature. It may receive breaking changes or be removed in the future.`
  3429. };
  3430. code = CompileErrorCodes.__EXTEND_POINT__;
  3431. inc = incrementer2(code);
  3432. CoreErrorCodes = {
  3433. INVALID_ARGUMENT: code,
  3434. // 17
  3435. INVALID_DATE_ARGUMENT: inc(),
  3436. // 18
  3437. INVALID_ISO_DATE_ARGUMENT: inc(),
  3438. // 19
  3439. NOT_SUPPORT_NON_STRING_MESSAGE: inc(),
  3440. // 20
  3441. NOT_SUPPORT_LOCALE_PROMISE_VALUE: inc(),
  3442. // 21
  3443. NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: inc(),
  3444. // 22
  3445. NOT_SUPPORT_LOCALE_TYPE: inc(),
  3446. // 23
  3447. __EXTEND_POINT__: inc()
  3448. // 24
  3449. };
  3450. errorMessages = {
  3451. [CoreErrorCodes.INVALID_ARGUMENT]: "Invalid arguments",
  3452. [CoreErrorCodes.INVALID_DATE_ARGUMENT]: "The date provided is an invalid Date object.Make sure your Date represents a valid date.",
  3453. [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: "The argument provided is not a valid ISO date string",
  3454. [CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: "Not support non-string message",
  3455. [CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE]: "cannot support promise value",
  3456. [CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
  3457. [CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
  3458. };
  3459. VERSION = "9.13.1";
  3460. NOT_REOSLVED = -1;
  3461. DEFAULT_LOCALE = "en-US";
  3462. MISSING_RESOLVE_VALUE = "";
  3463. capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
  3464. _additionalMeta = null;
  3465. setAdditionalMeta = (meta) => {
  3466. _additionalMeta = meta;
  3467. };
  3468. getAdditionalMeta = () => _additionalMeta;
  3469. _fallbackContext = null;
  3470. setFallbackContext = (context) => {
  3471. _fallbackContext = context;
  3472. };
  3473. getFallbackContext = () => _fallbackContext;
  3474. _cid = 0;
  3475. WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
  3476. defaultOnCacheKey = (message) => message;
  3477. compileCache = /* @__PURE__ */ Object.create(null);
  3478. isMessageAST = (val) => isObject2(val) && (val.t === 0 || val.type === 0) && ("b" in val || "body" in val);
  3479. compileToFunction = (message, context) => {
  3480. if (!isString2(message)) {
  3481. throw createCoreError(CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE);
  3482. }
  3483. {
  3484. context.onWarn = onCompileWarn;
  3485. }
  3486. {
  3487. const warnHtmlMessage = isBoolean2(context.warnHtmlMessage) ? context.warnHtmlMessage : true;
  3488. checkHtmlMessage(message, warnHtmlMessage);
  3489. const onCacheKey = context.onCacheKey || defaultOnCacheKey;
  3490. const cacheKey = onCacheKey(message);
  3491. const cached = compileCache[cacheKey];
  3492. if (cached) {
  3493. return cached;
  3494. }
  3495. const { code: code2, detectError } = baseCompile(message, context);
  3496. const msg = new Function(`return ${code2}`)();
  3497. return !detectError ? compileCache[cacheKey] = msg : msg;
  3498. }
  3499. };
  3500. NOOP_MESSAGE_FUNCTION = () => "";
  3501. isMessageFunction = (val) => isFunction2(val);
  3502. intlDefined = typeof Intl !== "undefined";
  3503. Availabilities = {
  3504. dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
  3505. numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
  3506. };
  3507. DATETIME_FORMAT_OPTIONS_KEYS = [
  3508. "localeMatcher",
  3509. "weekday",
  3510. "era",
  3511. "year",
  3512. "month",
  3513. "day",
  3514. "hour",
  3515. "minute",
  3516. "second",
  3517. "timeZoneName",
  3518. "formatMatcher",
  3519. "hour12",
  3520. "timeZone",
  3521. "dateStyle",
  3522. "timeStyle",
  3523. "calendar",
  3524. "dayPeriod",
  3525. "numberingSystem",
  3526. "hourCycle",
  3527. "fractionalSecondDigits"
  3528. ];
  3529. NUMBER_FORMAT_OPTIONS_KEYS = [
  3530. "localeMatcher",
  3531. "style",
  3532. "currency",
  3533. "currencyDisplay",
  3534. "currencySign",
  3535. "useGrouping",
  3536. "minimumIntegerDigits",
  3537. "minimumFractionDigits",
  3538. "maximumFractionDigits",
  3539. "minimumSignificantDigits",
  3540. "maximumSignificantDigits",
  3541. "compactDisplay",
  3542. "notation",
  3543. "signDisplay",
  3544. "unit",
  3545. "unitDisplay",
  3546. "roundingMode",
  3547. "roundingPriority",
  3548. "roundingIncrement",
  3549. "trailingZeroDisplay"
  3550. ];
  3551. }
  3552. });
  3553. // node_modules/.pnpm/vue-i18n@9.13.1_vue@3.4.27/node_modules/vue-i18n/dist/vue-i18n.cjs
  3554. var require_vue_i18n = __commonJS({
  3555. "node_modules/.pnpm/vue-i18n@9.13.1_vue@3.4.27/node_modules/vue-i18n/dist/vue-i18n.cjs"(exports) {
  3556. "use strict";
  3557. var shared = (init_shared_esm_browser(), __toCommonJS(shared_esm_browser_exports));
  3558. var coreBase = (init_core_base_esm_browser(), __toCommonJS(core_base_esm_browser_exports));
  3559. var vue = require_vue();
  3560. var VERSION2 = "9.13.1";
  3561. var code$12 = coreBase.CoreWarnCodes.__EXTEND_POINT__;
  3562. var inc$12 = shared.incrementer(code$12);
  3563. var I18nWarnCodes = {
  3564. FALLBACK_TO_ROOT: code$12,
  3565. // 9
  3566. NOT_SUPPORTED_PRESERVE: inc$12(),
  3567. // 10
  3568. NOT_SUPPORTED_FORMATTER: inc$12(),
  3569. // 11
  3570. NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc$12(),
  3571. // 12
  3572. NOT_SUPPORTED_GET_CHOICE_INDEX: inc$12(),
  3573. // 13
  3574. COMPONENT_NAME_LEGACY_COMPATIBLE: inc$12(),
  3575. // 14
  3576. NOT_FOUND_PARENT_SCOPE: inc$12(),
  3577. // 15
  3578. IGNORE_OBJ_FLATTEN: inc$12(),
  3579. // 16
  3580. NOTICE_DROP_ALLOW_COMPOSITION: inc$12(),
  3581. // 17
  3582. NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG: inc$12()
  3583. // 18
  3584. };
  3585. var warnMessages2 = {
  3586. [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
  3587. [I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `Not supported 'preserve'.`,
  3588. [I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supported 'formatter'.`,
  3589. [I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supported 'preserveDirectiveContent'.`,
  3590. [I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
  3591. [I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
  3592. [I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
  3593. [I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`,
  3594. [I18nWarnCodes.NOTICE_DROP_ALLOW_COMPOSITION]: `'allowComposition' option will be dropped in the next major version. For more information, please see 👉 https://tinyurl.com/2p97mcze`,
  3595. [I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG]: `'translateExistCompatible' option will be dropped in the next major version.`
  3596. };
  3597. function getWarnMessage2(code3, ...args) {
  3598. return shared.format(warnMessages2[code3], ...args);
  3599. }
  3600. var code2 = coreBase.CoreErrorCodes.__EXTEND_POINT__;
  3601. var inc2 = shared.incrementer(code2);
  3602. var I18nErrorCodes = {
  3603. // composer module errors
  3604. UNEXPECTED_RETURN_TYPE: code2,
  3605. // 24
  3606. // legacy module errors
  3607. INVALID_ARGUMENT: inc2(),
  3608. // 25
  3609. // i18n module errors
  3610. MUST_BE_CALL_SETUP_TOP: inc2(),
  3611. // 26
  3612. NOT_INSTALLED: inc2(),
  3613. // 27
  3614. NOT_AVAILABLE_IN_LEGACY_MODE: inc2(),
  3615. // 28
  3616. // directive module errors
  3617. REQUIRED_VALUE: inc2(),
  3618. // 29
  3619. INVALID_VALUE: inc2(),
  3620. // 30
  3621. // vue-devtools errors
  3622. CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: inc2(),
  3623. // 31
  3624. NOT_INSTALLED_WITH_PROVIDE: inc2(),
  3625. // 32
  3626. // unexpected error
  3627. UNEXPECTED_ERROR: inc2(),
  3628. // 33
  3629. // not compatible legacy vue-i18n constructor
  3630. NOT_COMPATIBLE_LEGACY_VUE_I18N: inc2(),
  3631. // 34
  3632. // bridge support vue 2.x only
  3633. BRIDGE_SUPPORT_VUE_2_ONLY: inc2(),
  3634. // 35
  3635. // need to define `i18n` option in `allowComposition: true` and `useScope: 'local' at `useI18n``
  3636. MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION: inc2(),
  3637. // 36
  3638. // Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
  3639. NOT_AVAILABLE_COMPOSITION_IN_LEGACY: inc2(),
  3640. // 37
  3641. // for enhancement
  3642. __EXTEND_POINT__: inc2()
  3643. // 38
  3644. };
  3645. function createI18nError(code3, ...args) {
  3646. return coreBase.createCompileError(code3, null, { messages: errorMessages2, args });
  3647. }
  3648. var errorMessages2 = {
  3649. [I18nErrorCodes.UNEXPECTED_RETURN_TYPE]: "Unexpected return type in composer",
  3650. [I18nErrorCodes.INVALID_ARGUMENT]: "Invalid argument",
  3651. [I18nErrorCodes.MUST_BE_CALL_SETUP_TOP]: "Must be called at the top of a `setup` function",
  3652. [I18nErrorCodes.NOT_INSTALLED]: "Need to install with `app.use` function",
  3653. [I18nErrorCodes.UNEXPECTED_ERROR]: "Unexpected error",
  3654. [I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE]: "Not available in legacy mode",
  3655. [I18nErrorCodes.REQUIRED_VALUE]: `Required in value: {0}`,
  3656. [I18nErrorCodes.INVALID_VALUE]: `Invalid value`,
  3657. [I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
  3658. [I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE]: "Need to install with `provide` function",
  3659. [I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: "Not compatible legacy VueI18n.",
  3660. [I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]: "vue-i18n-bridge support Vue 2.x only",
  3661. [I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION]: "Must define ‘i18n’ option or custom block in Composition API with using local scope in Legacy API mode",
  3662. [I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY]: "Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly"
  3663. };
  3664. var TranslateVNodeSymbol = shared.makeSymbol("__translateVNode");
  3665. var DatetimePartsSymbol = shared.makeSymbol("__datetimeParts");
  3666. var NumberPartsSymbol = shared.makeSymbol("__numberParts");
  3667. var EnableEmitter = shared.makeSymbol("__enableEmitter");
  3668. var DisableEmitter = shared.makeSymbol("__disableEmitter");
  3669. var SetPluralRulesSymbol = shared.makeSymbol("__setPluralRules");
  3670. shared.makeSymbol("__intlifyMeta");
  3671. var InejctWithOptionSymbol = shared.makeSymbol("__injectWithOption");
  3672. var DisposeSymbol = shared.makeSymbol("__dispose");
  3673. var __VUE_I18N_BRIDGE__ = "__VUE_I18N_BRIDGE__";
  3674. function handleFlatJson(obj) {
  3675. if (!shared.isObject(obj)) {
  3676. return obj;
  3677. }
  3678. for (const key in obj) {
  3679. if (!shared.hasOwn(obj, key)) {
  3680. continue;
  3681. }
  3682. if (!key.includes(".")) {
  3683. if (shared.isObject(obj[key])) {
  3684. handleFlatJson(obj[key]);
  3685. }
  3686. } else {
  3687. const subKeys = key.split(".");
  3688. const lastIndex = subKeys.length - 1;
  3689. let currentObj = obj;
  3690. let hasStringValue = false;
  3691. for (let i = 0; i < lastIndex; i++) {
  3692. if (!(subKeys[i] in currentObj)) {
  3693. currentObj[subKeys[i]] = {};
  3694. }
  3695. if (!shared.isObject(currentObj[subKeys[i]])) {
  3696. shared.warn(getWarnMessage2(I18nWarnCodes.IGNORE_OBJ_FLATTEN, {
  3697. key: subKeys[i]
  3698. }));
  3699. hasStringValue = true;
  3700. break;
  3701. }
  3702. currentObj = currentObj[subKeys[i]];
  3703. }
  3704. if (!hasStringValue) {
  3705. currentObj[subKeys[lastIndex]] = obj[key];
  3706. delete obj[key];
  3707. }
  3708. if (shared.isObject(currentObj[subKeys[lastIndex]])) {
  3709. handleFlatJson(currentObj[subKeys[lastIndex]]);
  3710. }
  3711. }
  3712. }
  3713. return obj;
  3714. }
  3715. function getLocaleMessages(locale, options) {
  3716. const { messages, __i18n, messageResolver, flatJson } = options;
  3717. const ret = shared.isPlainObject(messages) ? messages : shared.isArray(__i18n) ? {} : { [locale]: {} };
  3718. if (shared.isArray(__i18n)) {
  3719. __i18n.forEach((custom) => {
  3720. if ("locale" in custom && "resource" in custom) {
  3721. const { locale: locale2, resource } = custom;
  3722. if (locale2) {
  3723. ret[locale2] = ret[locale2] || {};
  3724. shared.deepCopy(resource, ret[locale2]);
  3725. } else {
  3726. shared.deepCopy(resource, ret);
  3727. }
  3728. } else {
  3729. shared.isString(custom) && shared.deepCopy(JSON.parse(custom), ret);
  3730. }
  3731. });
  3732. }
  3733. if (messageResolver == null && flatJson) {
  3734. for (const key in ret) {
  3735. if (shared.hasOwn(ret, key)) {
  3736. handleFlatJson(ret[key]);
  3737. }
  3738. }
  3739. }
  3740. return ret;
  3741. }
  3742. function getComponentOptions(instance) {
  3743. return instance.type;
  3744. }
  3745. function adjustI18nResources(gl, options, componentOptions) {
  3746. let messages = shared.isObject(options.messages) ? options.messages : {};
  3747. if ("__i18nGlobal" in componentOptions) {
  3748. messages = getLocaleMessages(gl.locale.value, {
  3749. messages,
  3750. __i18n: componentOptions.__i18nGlobal
  3751. });
  3752. }
  3753. const locales = Object.keys(messages);
  3754. if (locales.length) {
  3755. locales.forEach((locale) => {
  3756. gl.mergeLocaleMessage(locale, messages[locale]);
  3757. });
  3758. }
  3759. {
  3760. if (shared.isObject(options.datetimeFormats)) {
  3761. const locales2 = Object.keys(options.datetimeFormats);
  3762. if (locales2.length) {
  3763. locales2.forEach((locale) => {
  3764. gl.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
  3765. });
  3766. }
  3767. }
  3768. if (shared.isObject(options.numberFormats)) {
  3769. const locales2 = Object.keys(options.numberFormats);
  3770. if (locales2.length) {
  3771. locales2.forEach((locale) => {
  3772. gl.mergeNumberFormat(locale, options.numberFormats[locale]);
  3773. });
  3774. }
  3775. }
  3776. }
  3777. }
  3778. function createTextNode(key) {
  3779. return vue.createVNode(vue.Text, null, key, 0);
  3780. }
  3781. var DEVTOOLS_META = "__INTLIFY_META__";
  3782. var NOOP_RETURN_ARRAY = () => [];
  3783. var NOOP_RETURN_FALSE = () => false;
  3784. var composerID = 0;
  3785. function defineCoreMissingHandler(missing) {
  3786. return (ctx, locale, key, type) => {
  3787. return missing(locale, key, vue.getCurrentInstance() || void 0, type);
  3788. };
  3789. }
  3790. var getMetaInfo = () => {
  3791. const instance = vue.getCurrentInstance();
  3792. let meta = null;
  3793. return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META]) ? { [DEVTOOLS_META]: meta } : null;
  3794. };
  3795. function createComposer(options = {}, VueI18nLegacy) {
  3796. const { __root, __injectWithOption } = options;
  3797. const _isGlobal = __root === void 0;
  3798. const flatJson = options.flatJson;
  3799. const _ref = shared.inBrowser ? vue.ref : vue.shallowRef;
  3800. const translateExistCompatible = !!options.translateExistCompatible;
  3801. {
  3802. if (translateExistCompatible && true) {
  3803. shared.warnOnce(getWarnMessage2(I18nWarnCodes.NOTICE_DROP_TRANSLATE_EXIST_COMPATIBLE_FLAG));
  3804. }
  3805. }
  3806. let _inheritLocale = shared.isBoolean(options.inheritLocale) ? options.inheritLocale : true;
  3807. const _locale = _ref(
  3808. // prettier-ignore
  3809. __root && _inheritLocale ? __root.locale.value : shared.isString(options.locale) ? options.locale : coreBase.DEFAULT_LOCALE
  3810. );
  3811. const _fallbackLocale = _ref(
  3812. // prettier-ignore
  3813. __root && _inheritLocale ? __root.fallbackLocale.value : shared.isString(options.fallbackLocale) || shared.isArray(options.fallbackLocale) || shared.isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale.value
  3814. );
  3815. const _messages = _ref(getLocaleMessages(_locale.value, options));
  3816. const _datetimeFormats = _ref(shared.isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [_locale.value]: {} });
  3817. const _numberFormats = _ref(shared.isPlainObject(options.numberFormats) ? options.numberFormats : { [_locale.value]: {} });
  3818. let _missingWarn = __root ? __root.missingWarn : shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn) ? options.missingWarn : true;
  3819. let _fallbackWarn = __root ? __root.fallbackWarn : shared.isBoolean(options.fallbackWarn) || shared.isRegExp(options.fallbackWarn) ? options.fallbackWarn : true;
  3820. let _fallbackRoot = __root ? __root.fallbackRoot : shared.isBoolean(options.fallbackRoot) ? options.fallbackRoot : true;
  3821. let _fallbackFormat = !!options.fallbackFormat;
  3822. let _missing = shared.isFunction(options.missing) ? options.missing : null;
  3823. let _runtimeMissing = shared.isFunction(options.missing) ? defineCoreMissingHandler(options.missing) : null;
  3824. let _postTranslation = shared.isFunction(options.postTranslation) ? options.postTranslation : null;
  3825. let _warnHtmlMessage = __root ? __root.warnHtmlMessage : shared.isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
  3826. let _escapeParameter = !!options.escapeParameter;
  3827. const _modifiers = __root ? __root.modifiers : shared.isPlainObject(options.modifiers) ? options.modifiers : {};
  3828. let _pluralRules = options.pluralRules || __root && __root.pluralRules;
  3829. let _context;
  3830. const getCoreContext = () => {
  3831. _isGlobal && coreBase.setFallbackContext(null);
  3832. const ctxOptions = {
  3833. version: VERSION2,
  3834. locale: _locale.value,
  3835. fallbackLocale: _fallbackLocale.value,
  3836. messages: _messages.value,
  3837. modifiers: _modifiers,
  3838. pluralRules: _pluralRules,
  3839. missing: _runtimeMissing === null ? void 0 : _runtimeMissing,
  3840. missingWarn: _missingWarn,
  3841. fallbackWarn: _fallbackWarn,
  3842. fallbackFormat: _fallbackFormat,
  3843. unresolving: true,
  3844. postTranslation: _postTranslation === null ? void 0 : _postTranslation,
  3845. warnHtmlMessage: _warnHtmlMessage,
  3846. escapeParameter: _escapeParameter,
  3847. messageResolver: options.messageResolver,
  3848. messageCompiler: options.messageCompiler,
  3849. __meta: { framework: "vue" }
  3850. };
  3851. {
  3852. ctxOptions.datetimeFormats = _datetimeFormats.value;
  3853. ctxOptions.numberFormats = _numberFormats.value;
  3854. ctxOptions.__datetimeFormatters = shared.isPlainObject(_context) ? _context.__datetimeFormatters : void 0;
  3855. ctxOptions.__numberFormatters = shared.isPlainObject(_context) ? _context.__numberFormatters : void 0;
  3856. }
  3857. {
  3858. ctxOptions.__v_emitter = shared.isPlainObject(_context) ? _context.__v_emitter : void 0;
  3859. }
  3860. const ctx = coreBase.createCoreContext(ctxOptions);
  3861. _isGlobal && coreBase.setFallbackContext(ctx);
  3862. return ctx;
  3863. };
  3864. _context = getCoreContext();
  3865. coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  3866. function trackReactivityValues() {
  3867. return [
  3868. _locale.value,
  3869. _fallbackLocale.value,
  3870. _messages.value,
  3871. _datetimeFormats.value,
  3872. _numberFormats.value
  3873. ];
  3874. }
  3875. const locale = vue.computed({
  3876. get: () => _locale.value,
  3877. set: (val) => {
  3878. _locale.value = val;
  3879. _context.locale = _locale.value;
  3880. }
  3881. });
  3882. const fallbackLocale = vue.computed({
  3883. get: () => _fallbackLocale.value,
  3884. set: (val) => {
  3885. _fallbackLocale.value = val;
  3886. _context.fallbackLocale = _fallbackLocale.value;
  3887. coreBase.updateFallbackLocale(_context, _locale.value, val);
  3888. }
  3889. });
  3890. const messages = vue.computed(() => _messages.value);
  3891. const datetimeFormats = vue.computed(() => _datetimeFormats.value);
  3892. const numberFormats = vue.computed(() => _numberFormats.value);
  3893. function getPostTranslationHandler() {
  3894. return shared.isFunction(_postTranslation) ? _postTranslation : null;
  3895. }
  3896. function setPostTranslationHandler(handler) {
  3897. _postTranslation = handler;
  3898. _context.postTranslation = handler;
  3899. }
  3900. function getMissingHandler() {
  3901. return _missing;
  3902. }
  3903. function setMissingHandler(handler) {
  3904. if (handler !== null) {
  3905. _runtimeMissing = defineCoreMissingHandler(handler);
  3906. }
  3907. _missing = handler;
  3908. _context.missing = _runtimeMissing;
  3909. }
  3910. function isResolvedTranslateMessage(type, arg) {
  3911. return type !== "translate" || !arg.resolvedMessage;
  3912. }
  3913. const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
  3914. trackReactivityValues();
  3915. let ret;
  3916. try {
  3917. if (true) {
  3918. coreBase.setAdditionalMeta(getMetaInfo());
  3919. }
  3920. if (!_isGlobal) {
  3921. _context.fallbackContext = __root ? coreBase.getFallbackContext() : void 0;
  3922. }
  3923. ret = fn(_context);
  3924. } finally {
  3925. {
  3926. coreBase.setAdditionalMeta(null);
  3927. }
  3928. if (!_isGlobal) {
  3929. _context.fallbackContext = void 0;
  3930. }
  3931. }
  3932. if (warnType !== "translate exists" && // for not `te` (e.g `t`)
  3933. shared.isNumber(ret) && ret === coreBase.NOT_REOSLVED || warnType === "translate exists" && !ret) {
  3934. const [key, arg2] = argumentParser();
  3935. if (__root && shared.isString(key) && isResolvedTranslateMessage(warnType, arg2)) {
  3936. if (_fallbackRoot && (coreBase.isTranslateFallbackWarn(_fallbackWarn, key) || coreBase.isTranslateMissingWarn(_missingWarn, key))) {
  3937. shared.warn(getWarnMessage2(I18nWarnCodes.FALLBACK_TO_ROOT, {
  3938. key,
  3939. type: warnType
  3940. }));
  3941. }
  3942. {
  3943. const { __v_emitter: emitter } = _context;
  3944. if (emitter && _fallbackRoot) {
  3945. emitter.emit("fallback", {
  3946. type: warnType,
  3947. key,
  3948. to: "global",
  3949. groupId: `${warnType}:${key}`
  3950. });
  3951. }
  3952. }
  3953. }
  3954. return __root && _fallbackRoot ? fallbackSuccess(__root) : fallbackFail(key);
  3955. } else if (successCondition(ret)) {
  3956. return ret;
  3957. } else {
  3958. throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
  3959. }
  3960. };
  3961. function t(...args) {
  3962. return wrapWithDeps((context) => Reflect.apply(coreBase.translate, null, [context, ...args]), () => coreBase.parseTranslateArgs(...args), "translate", (root) => Reflect.apply(root.t, root, [...args]), (key) => key, (val) => shared.isString(val));
  3963. }
  3964. function rt(...args) {
  3965. const [arg1, arg2, arg3] = args;
  3966. if (arg3 && !shared.isObject(arg3)) {
  3967. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  3968. }
  3969. return t(...[arg1, arg2, shared.assign({ resolvedMessage: true }, arg3 || {})]);
  3970. }
  3971. function d(...args) {
  3972. return wrapWithDeps((context) => Reflect.apply(coreBase.datetime, null, [context, ...args]), () => coreBase.parseDateTimeArgs(...args), "datetime format", (root) => Reflect.apply(root.d, root, [...args]), () => coreBase.MISSING_RESOLVE_VALUE, (val) => shared.isString(val));
  3973. }
  3974. function n(...args) {
  3975. return wrapWithDeps((context) => Reflect.apply(coreBase.number, null, [context, ...args]), () => coreBase.parseNumberArgs(...args), "number format", (root) => Reflect.apply(root.n, root, [...args]), () => coreBase.MISSING_RESOLVE_VALUE, (val) => shared.isString(val));
  3976. }
  3977. function normalize(values) {
  3978. return values.map((val) => shared.isString(val) || shared.isNumber(val) || shared.isBoolean(val) ? createTextNode(String(val)) : val);
  3979. }
  3980. const interpolate = (val) => val;
  3981. const processor = {
  3982. normalize,
  3983. interpolate,
  3984. type: "vnode"
  3985. };
  3986. function translateVNode(...args) {
  3987. return wrapWithDeps(
  3988. (context) => {
  3989. let ret;
  3990. const _context2 = context;
  3991. try {
  3992. _context2.processor = processor;
  3993. ret = Reflect.apply(coreBase.translate, null, [_context2, ...args]);
  3994. } finally {
  3995. _context2.processor = null;
  3996. }
  3997. return ret;
  3998. },
  3999. () => coreBase.parseTranslateArgs(...args),
  4000. "translate",
  4001. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4002. (root) => root[TranslateVNodeSymbol](...args),
  4003. (key) => [createTextNode(key)],
  4004. (val) => shared.isArray(val)
  4005. );
  4006. }
  4007. function numberParts(...args) {
  4008. return wrapWithDeps(
  4009. (context) => Reflect.apply(coreBase.number, null, [context, ...args]),
  4010. () => coreBase.parseNumberArgs(...args),
  4011. "number format",
  4012. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4013. (root) => root[NumberPartsSymbol](...args),
  4014. NOOP_RETURN_ARRAY,
  4015. (val) => shared.isString(val) || shared.isArray(val)
  4016. );
  4017. }
  4018. function datetimeParts(...args) {
  4019. return wrapWithDeps(
  4020. (context) => Reflect.apply(coreBase.datetime, null, [context, ...args]),
  4021. () => coreBase.parseDateTimeArgs(...args),
  4022. "datetime format",
  4023. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4024. (root) => root[DatetimePartsSymbol](...args),
  4025. NOOP_RETURN_ARRAY,
  4026. (val) => shared.isString(val) || shared.isArray(val)
  4027. );
  4028. }
  4029. function setPluralRules(rules) {
  4030. _pluralRules = rules;
  4031. _context.pluralRules = _pluralRules;
  4032. }
  4033. function te(key, locale2) {
  4034. return wrapWithDeps(() => {
  4035. if (!key) {
  4036. return false;
  4037. }
  4038. const targetLocale = shared.isString(locale2) ? locale2 : _locale.value;
  4039. const message = getLocaleMessage(targetLocale);
  4040. const resolved = _context.messageResolver(message, key);
  4041. return !translateExistCompatible ? coreBase.isMessageAST(resolved) || coreBase.isMessageFunction(resolved) || shared.isString(resolved) : resolved != null;
  4042. }, () => [key], "translate exists", (root) => {
  4043. return Reflect.apply(root.te, root, [key, locale2]);
  4044. }, NOOP_RETURN_FALSE, (val) => shared.isBoolean(val));
  4045. }
  4046. function resolveMessages(key) {
  4047. let messages2 = null;
  4048. const locales = coreBase.fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
  4049. for (let i = 0; i < locales.length; i++) {
  4050. const targetLocaleMessages = _messages.value[locales[i]] || {};
  4051. const messageValue = _context.messageResolver(targetLocaleMessages, key);
  4052. if (messageValue != null) {
  4053. messages2 = messageValue;
  4054. break;
  4055. }
  4056. }
  4057. return messages2;
  4058. }
  4059. function tm(key) {
  4060. const messages2 = resolveMessages(key);
  4061. return messages2 != null ? messages2 : __root ? __root.tm(key) || {} : {};
  4062. }
  4063. function getLocaleMessage(locale2) {
  4064. return _messages.value[locale2] || {};
  4065. }
  4066. function setLocaleMessage(locale2, message) {
  4067. if (flatJson) {
  4068. const _message = { [locale2]: message };
  4069. for (const key in _message) {
  4070. if (shared.hasOwn(_message, key)) {
  4071. handleFlatJson(_message[key]);
  4072. }
  4073. }
  4074. message = _message[locale2];
  4075. }
  4076. _messages.value[locale2] = message;
  4077. _context.messages = _messages.value;
  4078. }
  4079. function mergeLocaleMessage(locale2, message) {
  4080. _messages.value[locale2] = _messages.value[locale2] || {};
  4081. const _message = { [locale2]: message };
  4082. if (flatJson) {
  4083. for (const key in _message) {
  4084. if (shared.hasOwn(_message, key)) {
  4085. handleFlatJson(_message[key]);
  4086. }
  4087. }
  4088. }
  4089. message = _message[locale2];
  4090. shared.deepCopy(message, _messages.value[locale2]);
  4091. _context.messages = _messages.value;
  4092. }
  4093. function getDateTimeFormat(locale2) {
  4094. return _datetimeFormats.value[locale2] || {};
  4095. }
  4096. function setDateTimeFormat(locale2, format3) {
  4097. _datetimeFormats.value[locale2] = format3;
  4098. _context.datetimeFormats = _datetimeFormats.value;
  4099. coreBase.clearDateTimeFormat(_context, locale2, format3);
  4100. }
  4101. function mergeDateTimeFormat(locale2, format3) {
  4102. _datetimeFormats.value[locale2] = shared.assign(_datetimeFormats.value[locale2] || {}, format3);
  4103. _context.datetimeFormats = _datetimeFormats.value;
  4104. coreBase.clearDateTimeFormat(_context, locale2, format3);
  4105. }
  4106. function getNumberFormat(locale2) {
  4107. return _numberFormats.value[locale2] || {};
  4108. }
  4109. function setNumberFormat(locale2, format3) {
  4110. _numberFormats.value[locale2] = format3;
  4111. _context.numberFormats = _numberFormats.value;
  4112. coreBase.clearNumberFormat(_context, locale2, format3);
  4113. }
  4114. function mergeNumberFormat(locale2, format3) {
  4115. _numberFormats.value[locale2] = shared.assign(_numberFormats.value[locale2] || {}, format3);
  4116. _context.numberFormats = _numberFormats.value;
  4117. coreBase.clearNumberFormat(_context, locale2, format3);
  4118. }
  4119. composerID++;
  4120. if (__root && shared.inBrowser) {
  4121. vue.watch(__root.locale, (val) => {
  4122. if (_inheritLocale) {
  4123. _locale.value = val;
  4124. _context.locale = val;
  4125. coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  4126. }
  4127. });
  4128. vue.watch(__root.fallbackLocale, (val) => {
  4129. if (_inheritLocale) {
  4130. _fallbackLocale.value = val;
  4131. _context.fallbackLocale = val;
  4132. coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  4133. }
  4134. });
  4135. }
  4136. const composer = {
  4137. id: composerID,
  4138. locale,
  4139. fallbackLocale,
  4140. get inheritLocale() {
  4141. return _inheritLocale;
  4142. },
  4143. set inheritLocale(val) {
  4144. _inheritLocale = val;
  4145. if (val && __root) {
  4146. _locale.value = __root.locale.value;
  4147. _fallbackLocale.value = __root.fallbackLocale.value;
  4148. coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  4149. }
  4150. },
  4151. get availableLocales() {
  4152. return Object.keys(_messages.value).sort();
  4153. },
  4154. messages,
  4155. get modifiers() {
  4156. return _modifiers;
  4157. },
  4158. get pluralRules() {
  4159. return _pluralRules || {};
  4160. },
  4161. get isGlobal() {
  4162. return _isGlobal;
  4163. },
  4164. get missingWarn() {
  4165. return _missingWarn;
  4166. },
  4167. set missingWarn(val) {
  4168. _missingWarn = val;
  4169. _context.missingWarn = _missingWarn;
  4170. },
  4171. get fallbackWarn() {
  4172. return _fallbackWarn;
  4173. },
  4174. set fallbackWarn(val) {
  4175. _fallbackWarn = val;
  4176. _context.fallbackWarn = _fallbackWarn;
  4177. },
  4178. get fallbackRoot() {
  4179. return _fallbackRoot;
  4180. },
  4181. set fallbackRoot(val) {
  4182. _fallbackRoot = val;
  4183. },
  4184. get fallbackFormat() {
  4185. return _fallbackFormat;
  4186. },
  4187. set fallbackFormat(val) {
  4188. _fallbackFormat = val;
  4189. _context.fallbackFormat = _fallbackFormat;
  4190. },
  4191. get warnHtmlMessage() {
  4192. return _warnHtmlMessage;
  4193. },
  4194. set warnHtmlMessage(val) {
  4195. _warnHtmlMessage = val;
  4196. _context.warnHtmlMessage = val;
  4197. },
  4198. get escapeParameter() {
  4199. return _escapeParameter;
  4200. },
  4201. set escapeParameter(val) {
  4202. _escapeParameter = val;
  4203. _context.escapeParameter = val;
  4204. },
  4205. t,
  4206. getLocaleMessage,
  4207. setLocaleMessage,
  4208. mergeLocaleMessage,
  4209. getPostTranslationHandler,
  4210. setPostTranslationHandler,
  4211. getMissingHandler,
  4212. setMissingHandler,
  4213. [SetPluralRulesSymbol]: setPluralRules
  4214. };
  4215. {
  4216. composer.datetimeFormats = datetimeFormats;
  4217. composer.numberFormats = numberFormats;
  4218. composer.rt = rt;
  4219. composer.te = te;
  4220. composer.tm = tm;
  4221. composer.d = d;
  4222. composer.n = n;
  4223. composer.getDateTimeFormat = getDateTimeFormat;
  4224. composer.setDateTimeFormat = setDateTimeFormat;
  4225. composer.mergeDateTimeFormat = mergeDateTimeFormat;
  4226. composer.getNumberFormat = getNumberFormat;
  4227. composer.setNumberFormat = setNumberFormat;
  4228. composer.mergeNumberFormat = mergeNumberFormat;
  4229. composer[InejctWithOptionSymbol] = __injectWithOption;
  4230. composer[TranslateVNodeSymbol] = translateVNode;
  4231. composer[DatetimePartsSymbol] = datetimeParts;
  4232. composer[NumberPartsSymbol] = numberParts;
  4233. }
  4234. {
  4235. composer[EnableEmitter] = (emitter) => {
  4236. _context.__v_emitter = emitter;
  4237. };
  4238. composer[DisableEmitter] = () => {
  4239. _context.__v_emitter = void 0;
  4240. };
  4241. }
  4242. return composer;
  4243. }
  4244. function convertComposerOptions(options) {
  4245. const locale = shared.isString(options.locale) ? options.locale : coreBase.DEFAULT_LOCALE;
  4246. const fallbackLocale = shared.isString(options.fallbackLocale) || shared.isArray(options.fallbackLocale) || shared.isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : locale;
  4247. const missing = shared.isFunction(options.missing) ? options.missing : void 0;
  4248. const missingWarn = shared.isBoolean(options.silentTranslationWarn) || shared.isRegExp(options.silentTranslationWarn) ? !options.silentTranslationWarn : true;
  4249. const fallbackWarn = shared.isBoolean(options.silentFallbackWarn) || shared.isRegExp(options.silentFallbackWarn) ? !options.silentFallbackWarn : true;
  4250. const fallbackRoot = shared.isBoolean(options.fallbackRoot) ? options.fallbackRoot : true;
  4251. const fallbackFormat = !!options.formatFallbackMessages;
  4252. const modifiers = shared.isPlainObject(options.modifiers) ? options.modifiers : {};
  4253. const pluralizationRules = options.pluralizationRules;
  4254. const postTranslation = shared.isFunction(options.postTranslation) ? options.postTranslation : void 0;
  4255. const warnHtmlMessage = shared.isString(options.warnHtmlInMessage) ? options.warnHtmlInMessage !== "off" : true;
  4256. const escapeParameter = !!options.escapeParameterHtml;
  4257. const inheritLocale = shared.isBoolean(options.sync) ? options.sync : true;
  4258. if (options.formatter) {
  4259. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_FORMATTER));
  4260. }
  4261. if (options.preserveDirectiveContent) {
  4262. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE));
  4263. }
  4264. let messages = options.messages;
  4265. if (shared.isPlainObject(options.sharedMessages)) {
  4266. const sharedMessages = options.sharedMessages;
  4267. const locales = Object.keys(sharedMessages);
  4268. messages = locales.reduce((messages2, locale2) => {
  4269. const message = messages2[locale2] || (messages2[locale2] = {});
  4270. shared.assign(message, sharedMessages[locale2]);
  4271. return messages2;
  4272. }, messages || {});
  4273. }
  4274. const { __i18n, __root, __injectWithOption } = options;
  4275. const datetimeFormats = options.datetimeFormats;
  4276. const numberFormats = options.numberFormats;
  4277. const flatJson = options.flatJson;
  4278. const translateExistCompatible = options.translateExistCompatible;
  4279. return {
  4280. locale,
  4281. fallbackLocale,
  4282. messages,
  4283. flatJson,
  4284. datetimeFormats,
  4285. numberFormats,
  4286. missing,
  4287. missingWarn,
  4288. fallbackWarn,
  4289. fallbackRoot,
  4290. fallbackFormat,
  4291. modifiers,
  4292. pluralRules: pluralizationRules,
  4293. postTranslation,
  4294. warnHtmlMessage,
  4295. escapeParameter,
  4296. messageResolver: options.messageResolver,
  4297. inheritLocale,
  4298. translateExistCompatible,
  4299. __i18n,
  4300. __root,
  4301. __injectWithOption
  4302. };
  4303. }
  4304. function createVueI18n(options = {}, VueI18nLegacy) {
  4305. {
  4306. const composer = createComposer(convertComposerOptions(options));
  4307. const { __extender } = options;
  4308. const vueI18n = {
  4309. // id
  4310. id: composer.id,
  4311. // locale
  4312. get locale() {
  4313. return composer.locale.value;
  4314. },
  4315. set locale(val) {
  4316. composer.locale.value = val;
  4317. },
  4318. // fallbackLocale
  4319. get fallbackLocale() {
  4320. return composer.fallbackLocale.value;
  4321. },
  4322. set fallbackLocale(val) {
  4323. composer.fallbackLocale.value = val;
  4324. },
  4325. // messages
  4326. get messages() {
  4327. return composer.messages.value;
  4328. },
  4329. // datetimeFormats
  4330. get datetimeFormats() {
  4331. return composer.datetimeFormats.value;
  4332. },
  4333. // numberFormats
  4334. get numberFormats() {
  4335. return composer.numberFormats.value;
  4336. },
  4337. // availableLocales
  4338. get availableLocales() {
  4339. return composer.availableLocales;
  4340. },
  4341. // formatter
  4342. get formatter() {
  4343. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_FORMATTER));
  4344. return {
  4345. interpolate() {
  4346. return [];
  4347. }
  4348. };
  4349. },
  4350. set formatter(val) {
  4351. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_FORMATTER));
  4352. },
  4353. // missing
  4354. get missing() {
  4355. return composer.getMissingHandler();
  4356. },
  4357. set missing(handler) {
  4358. composer.setMissingHandler(handler);
  4359. },
  4360. // silentTranslationWarn
  4361. get silentTranslationWarn() {
  4362. return shared.isBoolean(composer.missingWarn) ? !composer.missingWarn : composer.missingWarn;
  4363. },
  4364. set silentTranslationWarn(val) {
  4365. composer.missingWarn = shared.isBoolean(val) ? !val : val;
  4366. },
  4367. // silentFallbackWarn
  4368. get silentFallbackWarn() {
  4369. return shared.isBoolean(composer.fallbackWarn) ? !composer.fallbackWarn : composer.fallbackWarn;
  4370. },
  4371. set silentFallbackWarn(val) {
  4372. composer.fallbackWarn = shared.isBoolean(val) ? !val : val;
  4373. },
  4374. // modifiers
  4375. get modifiers() {
  4376. return composer.modifiers;
  4377. },
  4378. // formatFallbackMessages
  4379. get formatFallbackMessages() {
  4380. return composer.fallbackFormat;
  4381. },
  4382. set formatFallbackMessages(val) {
  4383. composer.fallbackFormat = val;
  4384. },
  4385. // postTranslation
  4386. get postTranslation() {
  4387. return composer.getPostTranslationHandler();
  4388. },
  4389. set postTranslation(handler) {
  4390. composer.setPostTranslationHandler(handler);
  4391. },
  4392. // sync
  4393. get sync() {
  4394. return composer.inheritLocale;
  4395. },
  4396. set sync(val) {
  4397. composer.inheritLocale = val;
  4398. },
  4399. // warnInHtmlMessage
  4400. get warnHtmlInMessage() {
  4401. return composer.warnHtmlMessage ? "warn" : "off";
  4402. },
  4403. set warnHtmlInMessage(val) {
  4404. composer.warnHtmlMessage = val !== "off";
  4405. },
  4406. // escapeParameterHtml
  4407. get escapeParameterHtml() {
  4408. return composer.escapeParameter;
  4409. },
  4410. set escapeParameterHtml(val) {
  4411. composer.escapeParameter = val;
  4412. },
  4413. // preserveDirectiveContent
  4414. get preserveDirectiveContent() {
  4415. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE));
  4416. return true;
  4417. },
  4418. set preserveDirectiveContent(val) {
  4419. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE));
  4420. },
  4421. // pluralizationRules
  4422. get pluralizationRules() {
  4423. return composer.pluralRules || {};
  4424. },
  4425. // for internal
  4426. __composer: composer,
  4427. // t
  4428. t(...args) {
  4429. const [arg1, arg2, arg3] = args;
  4430. const options2 = {};
  4431. let list = null;
  4432. let named = null;
  4433. if (!shared.isString(arg1)) {
  4434. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  4435. }
  4436. const key = arg1;
  4437. if (shared.isString(arg2)) {
  4438. options2.locale = arg2;
  4439. } else if (shared.isArray(arg2)) {
  4440. list = arg2;
  4441. } else if (shared.isPlainObject(arg2)) {
  4442. named = arg2;
  4443. }
  4444. if (shared.isArray(arg3)) {
  4445. list = arg3;
  4446. } else if (shared.isPlainObject(arg3)) {
  4447. named = arg3;
  4448. }
  4449. return Reflect.apply(composer.t, composer, [
  4450. key,
  4451. list || named || {},
  4452. options2
  4453. ]);
  4454. },
  4455. rt(...args) {
  4456. return Reflect.apply(composer.rt, composer, [...args]);
  4457. },
  4458. // tc
  4459. tc(...args) {
  4460. const [arg1, arg2, arg3] = args;
  4461. const options2 = { plural: 1 };
  4462. let list = null;
  4463. let named = null;
  4464. if (!shared.isString(arg1)) {
  4465. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  4466. }
  4467. const key = arg1;
  4468. if (shared.isString(arg2)) {
  4469. options2.locale = arg2;
  4470. } else if (shared.isNumber(arg2)) {
  4471. options2.plural = arg2;
  4472. } else if (shared.isArray(arg2)) {
  4473. list = arg2;
  4474. } else if (shared.isPlainObject(arg2)) {
  4475. named = arg2;
  4476. }
  4477. if (shared.isString(arg3)) {
  4478. options2.locale = arg3;
  4479. } else if (shared.isArray(arg3)) {
  4480. list = arg3;
  4481. } else if (shared.isPlainObject(arg3)) {
  4482. named = arg3;
  4483. }
  4484. return Reflect.apply(composer.t, composer, [
  4485. key,
  4486. list || named || {},
  4487. options2
  4488. ]);
  4489. },
  4490. // te
  4491. te(key, locale) {
  4492. return composer.te(key, locale);
  4493. },
  4494. // tm
  4495. tm(key) {
  4496. return composer.tm(key);
  4497. },
  4498. // getLocaleMessage
  4499. getLocaleMessage(locale) {
  4500. return composer.getLocaleMessage(locale);
  4501. },
  4502. // setLocaleMessage
  4503. setLocaleMessage(locale, message) {
  4504. composer.setLocaleMessage(locale, message);
  4505. },
  4506. // mergeLocaleMessage
  4507. mergeLocaleMessage(locale, message) {
  4508. composer.mergeLocaleMessage(locale, message);
  4509. },
  4510. // d
  4511. d(...args) {
  4512. return Reflect.apply(composer.d, composer, [...args]);
  4513. },
  4514. // getDateTimeFormat
  4515. getDateTimeFormat(locale) {
  4516. return composer.getDateTimeFormat(locale);
  4517. },
  4518. // setDateTimeFormat
  4519. setDateTimeFormat(locale, format3) {
  4520. composer.setDateTimeFormat(locale, format3);
  4521. },
  4522. // mergeDateTimeFormat
  4523. mergeDateTimeFormat(locale, format3) {
  4524. composer.mergeDateTimeFormat(locale, format3);
  4525. },
  4526. // n
  4527. n(...args) {
  4528. return Reflect.apply(composer.n, composer, [...args]);
  4529. },
  4530. // getNumberFormat
  4531. getNumberFormat(locale) {
  4532. return composer.getNumberFormat(locale);
  4533. },
  4534. // setNumberFormat
  4535. setNumberFormat(locale, format3) {
  4536. composer.setNumberFormat(locale, format3);
  4537. },
  4538. // mergeNumberFormat
  4539. mergeNumberFormat(locale, format3) {
  4540. composer.mergeNumberFormat(locale, format3);
  4541. },
  4542. // getChoiceIndex
  4543. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  4544. getChoiceIndex(choice, choicesLength) {
  4545. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX));
  4546. return -1;
  4547. }
  4548. };
  4549. vueI18n.__extender = __extender;
  4550. {
  4551. vueI18n.__enableEmitter = (emitter) => {
  4552. const __composer = composer;
  4553. __composer[EnableEmitter] && __composer[EnableEmitter](emitter);
  4554. };
  4555. vueI18n.__disableEmitter = () => {
  4556. const __composer = composer;
  4557. __composer[DisableEmitter] && __composer[DisableEmitter]();
  4558. };
  4559. }
  4560. return vueI18n;
  4561. }
  4562. }
  4563. var baseFormatProps = {
  4564. tag: {
  4565. type: [String, Object]
  4566. },
  4567. locale: {
  4568. type: String
  4569. },
  4570. scope: {
  4571. type: String,
  4572. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  4573. validator: (val) => val === "parent" || val === "global",
  4574. default: "parent"
  4575. /* ComponentI18nScope */
  4576. },
  4577. i18n: {
  4578. type: Object
  4579. }
  4580. };
  4581. function getInterpolateArg({ slots }, keys) {
  4582. if (keys.length === 1 && keys[0] === "default") {
  4583. const ret = slots.default ? slots.default() : [];
  4584. return ret.reduce((slot, current) => {
  4585. return [
  4586. ...slot,
  4587. // prettier-ignore
  4588. ...current.type === vue.Fragment ? current.children : [current]
  4589. ];
  4590. }, []);
  4591. } else {
  4592. return keys.reduce((arg, key) => {
  4593. const slot = slots[key];
  4594. if (slot) {
  4595. arg[key] = slot();
  4596. }
  4597. return arg;
  4598. }, {});
  4599. }
  4600. }
  4601. function getFragmentableTag(tag) {
  4602. return vue.Fragment;
  4603. }
  4604. var TranslationImpl = vue.defineComponent({
  4605. /* eslint-disable */
  4606. name: "i18n-t",
  4607. props: shared.assign({
  4608. keypath: {
  4609. type: String,
  4610. required: true
  4611. },
  4612. plural: {
  4613. type: [Number, String],
  4614. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4615. validator: (val) => shared.isNumber(val) || !isNaN(val)
  4616. }
  4617. }, baseFormatProps),
  4618. /* eslint-enable */
  4619. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4620. setup(props, context) {
  4621. const { slots, attrs } = context;
  4622. const i18n = props.i18n || useI18n({
  4623. useScope: props.scope,
  4624. __useComponent: true
  4625. });
  4626. return () => {
  4627. const keys = Object.keys(slots).filter((key) => key !== "_");
  4628. const options = {};
  4629. if (props.locale) {
  4630. options.locale = props.locale;
  4631. }
  4632. if (props.plural !== void 0) {
  4633. options.plural = shared.isString(props.plural) ? +props.plural : props.plural;
  4634. }
  4635. const arg = getInterpolateArg(context, keys);
  4636. const children = i18n[TranslateVNodeSymbol](props.keypath, arg, options);
  4637. const assignedAttrs = shared.assign({}, attrs);
  4638. const tag = shared.isString(props.tag) || shared.isObject(props.tag) ? props.tag : getFragmentableTag();
  4639. return vue.h(tag, assignedAttrs, children);
  4640. };
  4641. }
  4642. });
  4643. var Translation = TranslationImpl;
  4644. var I18nT = Translation;
  4645. function isVNode(target) {
  4646. return shared.isArray(target) && !shared.isString(target[0]);
  4647. }
  4648. function renderFormatter(props, context, slotKeys, partFormatter) {
  4649. const { slots, attrs } = context;
  4650. return () => {
  4651. const options = { part: true };
  4652. let overrides = {};
  4653. if (props.locale) {
  4654. options.locale = props.locale;
  4655. }
  4656. if (shared.isString(props.format)) {
  4657. options.key = props.format;
  4658. } else if (shared.isObject(props.format)) {
  4659. if (shared.isString(props.format.key)) {
  4660. options.key = props.format.key;
  4661. }
  4662. overrides = Object.keys(props.format).reduce((options2, prop) => {
  4663. return slotKeys.includes(prop) ? shared.assign({}, options2, { [prop]: props.format[prop] }) : options2;
  4664. }, {});
  4665. }
  4666. const parts = partFormatter(...[props.value, options, overrides]);
  4667. let children = [options.key];
  4668. if (shared.isArray(parts)) {
  4669. children = parts.map((part, index) => {
  4670. const slot = slots[part.type];
  4671. const node = slot ? slot({ [part.type]: part.value, index, parts }) : [part.value];
  4672. if (isVNode(node)) {
  4673. node[0].key = `${part.type}-${index}`;
  4674. }
  4675. return node;
  4676. });
  4677. } else if (shared.isString(parts)) {
  4678. children = [parts];
  4679. }
  4680. const assignedAttrs = shared.assign({}, attrs);
  4681. const tag = shared.isString(props.tag) || shared.isObject(props.tag) ? props.tag : getFragmentableTag();
  4682. return vue.h(tag, assignedAttrs, children);
  4683. };
  4684. }
  4685. var NumberFormatImpl = vue.defineComponent({
  4686. /* eslint-disable */
  4687. name: "i18n-n",
  4688. props: shared.assign({
  4689. value: {
  4690. type: Number,
  4691. required: true
  4692. },
  4693. format: {
  4694. type: [String, Object]
  4695. }
  4696. }, baseFormatProps),
  4697. /* eslint-enable */
  4698. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4699. setup(props, context) {
  4700. const i18n = props.i18n || useI18n({
  4701. useScope: props.scope,
  4702. __useComponent: true
  4703. });
  4704. return renderFormatter(props, context, coreBase.NUMBER_FORMAT_OPTIONS_KEYS, (...args) => (
  4705. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4706. i18n[NumberPartsSymbol](...args)
  4707. ));
  4708. }
  4709. });
  4710. var NumberFormat = NumberFormatImpl;
  4711. var I18nN = NumberFormat;
  4712. var DatetimeFormatImpl = vue.defineComponent({
  4713. /* eslint-disable */
  4714. name: "i18n-d",
  4715. props: shared.assign({
  4716. value: {
  4717. type: [Number, Date],
  4718. required: true
  4719. },
  4720. format: {
  4721. type: [String, Object]
  4722. }
  4723. }, baseFormatProps),
  4724. /* eslint-enable */
  4725. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4726. setup(props, context) {
  4727. const i18n = props.i18n || useI18n({
  4728. useScope: props.scope,
  4729. __useComponent: true
  4730. });
  4731. return renderFormatter(props, context, coreBase.DATETIME_FORMAT_OPTIONS_KEYS, (...args) => (
  4732. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4733. i18n[DatetimePartsSymbol](...args)
  4734. ));
  4735. }
  4736. });
  4737. var DatetimeFormat = DatetimeFormatImpl;
  4738. var I18nD = DatetimeFormat;
  4739. function getComposer$1(i18n, instance) {
  4740. const i18nInternal = i18n;
  4741. if (i18n.mode === "composition") {
  4742. return i18nInternal.__getInstance(instance) || i18n.global;
  4743. } else {
  4744. const vueI18n = i18nInternal.__getInstance(instance);
  4745. return vueI18n != null ? vueI18n.__composer : i18n.global.__composer;
  4746. }
  4747. }
  4748. function vTDirective(i18n) {
  4749. const _process = (binding) => {
  4750. const { instance, modifiers, value } = binding;
  4751. if (!instance || !instance.$) {
  4752. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  4753. }
  4754. const composer = getComposer$1(i18n, instance.$);
  4755. if (modifiers.preserve) {
  4756. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_SUPPORTED_PRESERVE));
  4757. }
  4758. const parsedValue = parseValue(value);
  4759. return [
  4760. Reflect.apply(composer.t, composer, [...makeParams(parsedValue)]),
  4761. composer
  4762. ];
  4763. };
  4764. const register = (el, binding) => {
  4765. const [textContent, composer] = _process(binding);
  4766. if (shared.inBrowser && i18n.global === composer) {
  4767. el.__i18nWatcher = vue.watch(composer.locale, () => {
  4768. binding.instance && binding.instance.$forceUpdate();
  4769. });
  4770. }
  4771. el.__composer = composer;
  4772. el.textContent = textContent;
  4773. };
  4774. const unregister = (el) => {
  4775. if (shared.inBrowser && el.__i18nWatcher) {
  4776. el.__i18nWatcher();
  4777. el.__i18nWatcher = void 0;
  4778. delete el.__i18nWatcher;
  4779. }
  4780. if (el.__composer) {
  4781. el.__composer = void 0;
  4782. delete el.__composer;
  4783. }
  4784. };
  4785. const update = (el, { value }) => {
  4786. if (el.__composer) {
  4787. const composer = el.__composer;
  4788. const parsedValue = parseValue(value);
  4789. el.textContent = Reflect.apply(composer.t, composer, [
  4790. ...makeParams(parsedValue)
  4791. ]);
  4792. }
  4793. };
  4794. const getSSRProps = (binding) => {
  4795. const [textContent] = _process(binding);
  4796. return { textContent };
  4797. };
  4798. return {
  4799. created: register,
  4800. unmounted: unregister,
  4801. beforeUpdate: update,
  4802. getSSRProps
  4803. };
  4804. }
  4805. function parseValue(value) {
  4806. if (shared.isString(value)) {
  4807. return { path: value };
  4808. } else if (shared.isPlainObject(value)) {
  4809. if (!("path" in value)) {
  4810. throw createI18nError(I18nErrorCodes.REQUIRED_VALUE, "path");
  4811. }
  4812. return value;
  4813. } else {
  4814. throw createI18nError(I18nErrorCodes.INVALID_VALUE);
  4815. }
  4816. }
  4817. function makeParams(value) {
  4818. const { path, locale, args, choice, plural } = value;
  4819. const options = {};
  4820. const named = args || {};
  4821. if (shared.isString(locale)) {
  4822. options.locale = locale;
  4823. }
  4824. if (shared.isNumber(choice)) {
  4825. options.plural = choice;
  4826. }
  4827. if (shared.isNumber(plural)) {
  4828. options.plural = plural;
  4829. }
  4830. return [path, named, options];
  4831. }
  4832. function apply(app, i18n, ...options) {
  4833. const pluginOptions = shared.isPlainObject(options[0]) ? options[0] : {};
  4834. const useI18nComponentName = !!pluginOptions.useI18nComponentName;
  4835. const globalInstall = shared.isBoolean(pluginOptions.globalInstall) ? pluginOptions.globalInstall : true;
  4836. if (globalInstall && useI18nComponentName) {
  4837. shared.warn(getWarnMessage2(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
  4838. name: Translation.name
  4839. }));
  4840. }
  4841. if (globalInstall) {
  4842. [!useI18nComponentName ? Translation.name : "i18n", "I18nT"].forEach((name) => app.component(name, Translation));
  4843. [NumberFormat.name, "I18nN"].forEach((name) => app.component(name, NumberFormat));
  4844. [DatetimeFormat.name, "I18nD"].forEach((name) => app.component(name, DatetimeFormat));
  4845. }
  4846. {
  4847. app.directive("t", vTDirective(i18n));
  4848. }
  4849. }
  4850. function defineMixin(vuei18n, composer, i18n) {
  4851. return {
  4852. beforeCreate() {
  4853. const instance = vue.getCurrentInstance();
  4854. if (!instance) {
  4855. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  4856. }
  4857. const options = this.$options;
  4858. if (options.i18n) {
  4859. const optionsI18n = options.i18n;
  4860. if (options.__i18n) {
  4861. optionsI18n.__i18n = options.__i18n;
  4862. }
  4863. optionsI18n.__root = composer;
  4864. if (this === this.$root) {
  4865. this.$i18n = mergeToGlobal(vuei18n, optionsI18n);
  4866. } else {
  4867. optionsI18n.__injectWithOption = true;
  4868. optionsI18n.__extender = i18n.__vueI18nExtend;
  4869. this.$i18n = createVueI18n(optionsI18n);
  4870. const _vueI18n = this.$i18n;
  4871. if (_vueI18n.__extender) {
  4872. _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
  4873. }
  4874. }
  4875. } else if (options.__i18n) {
  4876. if (this === this.$root) {
  4877. this.$i18n = mergeToGlobal(vuei18n, options);
  4878. } else {
  4879. this.$i18n = createVueI18n({
  4880. __i18n: options.__i18n,
  4881. __injectWithOption: true,
  4882. __extender: i18n.__vueI18nExtend,
  4883. __root: composer
  4884. });
  4885. const _vueI18n = this.$i18n;
  4886. if (_vueI18n.__extender) {
  4887. _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
  4888. }
  4889. }
  4890. } else {
  4891. this.$i18n = vuei18n;
  4892. }
  4893. if (options.__i18nGlobal) {
  4894. adjustI18nResources(composer, options, options);
  4895. }
  4896. this.$t = (...args) => this.$i18n.t(...args);
  4897. this.$rt = (...args) => this.$i18n.rt(...args);
  4898. this.$tc = (...args) => this.$i18n.tc(...args);
  4899. this.$te = (key, locale) => this.$i18n.te(key, locale);
  4900. this.$d = (...args) => this.$i18n.d(...args);
  4901. this.$n = (...args) => this.$i18n.n(...args);
  4902. this.$tm = (key) => this.$i18n.tm(key);
  4903. i18n.__setInstance(instance, this.$i18n);
  4904. },
  4905. mounted() {
  4906. },
  4907. unmounted() {
  4908. const instance = vue.getCurrentInstance();
  4909. if (!instance) {
  4910. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  4911. }
  4912. const _vueI18n = this.$i18n;
  4913. delete this.$t;
  4914. delete this.$rt;
  4915. delete this.$tc;
  4916. delete this.$te;
  4917. delete this.$d;
  4918. delete this.$n;
  4919. delete this.$tm;
  4920. if (_vueI18n.__disposer) {
  4921. _vueI18n.__disposer();
  4922. delete _vueI18n.__disposer;
  4923. delete _vueI18n.__extender;
  4924. }
  4925. i18n.__deleteInstance(instance);
  4926. delete this.$i18n;
  4927. }
  4928. };
  4929. }
  4930. function mergeToGlobal(g, options) {
  4931. g.locale = options.locale || g.locale;
  4932. g.fallbackLocale = options.fallbackLocale || g.fallbackLocale;
  4933. g.missing = options.missing || g.missing;
  4934. g.silentTranslationWarn = options.silentTranslationWarn || g.silentFallbackWarn;
  4935. g.silentFallbackWarn = options.silentFallbackWarn || g.silentFallbackWarn;
  4936. g.formatFallbackMessages = options.formatFallbackMessages || g.formatFallbackMessages;
  4937. g.postTranslation = options.postTranslation || g.postTranslation;
  4938. g.warnHtmlInMessage = options.warnHtmlInMessage || g.warnHtmlInMessage;
  4939. g.escapeParameterHtml = options.escapeParameterHtml || g.escapeParameterHtml;
  4940. g.sync = options.sync || g.sync;
  4941. g.__composer[SetPluralRulesSymbol](options.pluralizationRules || g.pluralizationRules);
  4942. const messages = getLocaleMessages(g.locale, {
  4943. messages: options.messages,
  4944. __i18n: options.__i18n
  4945. });
  4946. Object.keys(messages).forEach((locale) => g.mergeLocaleMessage(locale, messages[locale]));
  4947. if (options.datetimeFormats) {
  4948. Object.keys(options.datetimeFormats).forEach((locale) => g.mergeDateTimeFormat(locale, options.datetimeFormats[locale]));
  4949. }
  4950. if (options.numberFormats) {
  4951. Object.keys(options.numberFormats).forEach((locale) => g.mergeNumberFormat(locale, options.numberFormats[locale]));
  4952. }
  4953. return g;
  4954. }
  4955. var I18nInjectionKey = shared.makeSymbol("global-vue-i18n");
  4956. function createI18n(options = {}, VueI18nLegacy) {
  4957. const __legacyMode = shared.isBoolean(options.legacy) ? options.legacy : true;
  4958. const __globalInjection = shared.isBoolean(options.globalInjection) ? options.globalInjection : true;
  4959. const __allowComposition = __legacyMode ? !!options.allowComposition : true;
  4960. const __instances = /* @__PURE__ */ new Map();
  4961. const [globalScope, __global] = createGlobal(options, __legacyMode);
  4962. const symbol = shared.makeSymbol("vue-i18n");
  4963. {
  4964. if (__legacyMode && __allowComposition && true) {
  4965. shared.warn(getWarnMessage2(I18nWarnCodes.NOTICE_DROP_ALLOW_COMPOSITION));
  4966. }
  4967. }
  4968. function __getInstance(component) {
  4969. return __instances.get(component) || null;
  4970. }
  4971. function __setInstance(component, instance) {
  4972. __instances.set(component, instance);
  4973. }
  4974. function __deleteInstance(component) {
  4975. __instances.delete(component);
  4976. }
  4977. {
  4978. const i18n = {
  4979. // mode
  4980. get mode() {
  4981. return __legacyMode ? "legacy" : "composition";
  4982. },
  4983. // allowComposition
  4984. get allowComposition() {
  4985. return __allowComposition;
  4986. },
  4987. // install plugin
  4988. async install(app, ...options2) {
  4989. app.__VUE_I18N_SYMBOL__ = symbol;
  4990. app.provide(app.__VUE_I18N_SYMBOL__, i18n);
  4991. if (shared.isPlainObject(options2[0])) {
  4992. const opts = options2[0];
  4993. i18n.__composerExtend = opts.__composerExtend;
  4994. i18n.__vueI18nExtend = opts.__vueI18nExtend;
  4995. }
  4996. let globalReleaseHandler = null;
  4997. if (!__legacyMode && __globalInjection) {
  4998. globalReleaseHandler = injectGlobalFields(app, i18n.global);
  4999. }
  5000. {
  5001. apply(app, i18n, ...options2);
  5002. }
  5003. if (__legacyMode) {
  5004. app.mixin(defineMixin(__global, __global.__composer, i18n));
  5005. }
  5006. const unmountApp = app.unmount;
  5007. app.unmount = () => {
  5008. globalReleaseHandler && globalReleaseHandler();
  5009. i18n.dispose();
  5010. unmountApp();
  5011. };
  5012. },
  5013. // global accessor
  5014. get global() {
  5015. return __global;
  5016. },
  5017. dispose() {
  5018. globalScope.stop();
  5019. },
  5020. // @internal
  5021. __instances,
  5022. // @internal
  5023. __getInstance,
  5024. // @internal
  5025. __setInstance,
  5026. // @internal
  5027. __deleteInstance
  5028. };
  5029. return i18n;
  5030. }
  5031. }
  5032. function useI18n(options = {}) {
  5033. const instance = vue.getCurrentInstance();
  5034. if (instance == null) {
  5035. throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
  5036. }
  5037. if (!instance.isCE && instance.appContext.app != null && !instance.appContext.app.__VUE_I18N_SYMBOL__) {
  5038. throw createI18nError(I18nErrorCodes.NOT_INSTALLED);
  5039. }
  5040. const i18n = getI18nInstance(instance);
  5041. const gl = getGlobalComposer(i18n);
  5042. const componentOptions = getComponentOptions(instance);
  5043. const scope = getScope(options, componentOptions);
  5044. {
  5045. if (i18n.mode === "legacy" && !options.__useComponent) {
  5046. if (!i18n.allowComposition) {
  5047. throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
  5048. }
  5049. return useI18nForLegacy(instance, scope, gl, options);
  5050. }
  5051. }
  5052. if (scope === "global") {
  5053. adjustI18nResources(gl, options, componentOptions);
  5054. return gl;
  5055. }
  5056. if (scope === "parent") {
  5057. let composer2 = getComposer(i18n, instance, options.__useComponent);
  5058. if (composer2 == null) {
  5059. {
  5060. shared.warn(getWarnMessage2(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
  5061. }
  5062. composer2 = gl;
  5063. }
  5064. return composer2;
  5065. }
  5066. const i18nInternal = i18n;
  5067. let composer = i18nInternal.__getInstance(instance);
  5068. if (composer == null) {
  5069. const composerOptions = shared.assign({}, options);
  5070. if ("__i18n" in componentOptions) {
  5071. composerOptions.__i18n = componentOptions.__i18n;
  5072. }
  5073. if (gl) {
  5074. composerOptions.__root = gl;
  5075. }
  5076. composer = createComposer(composerOptions);
  5077. if (i18nInternal.__composerExtend) {
  5078. composer[DisposeSymbol] = i18nInternal.__composerExtend(composer);
  5079. }
  5080. setupLifeCycle(i18nInternal, instance, composer);
  5081. i18nInternal.__setInstance(instance, composer);
  5082. }
  5083. return composer;
  5084. }
  5085. var castToVueI18n = (i18n) => {
  5086. if (!(__VUE_I18N_BRIDGE__ in i18n)) {
  5087. throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N);
  5088. }
  5089. return i18n;
  5090. };
  5091. function createGlobal(options, legacyMode, VueI18nLegacy) {
  5092. const scope = vue.effectScope();
  5093. {
  5094. const obj = legacyMode ? scope.run(() => createVueI18n(options)) : scope.run(() => createComposer(options));
  5095. if (obj == null) {
  5096. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  5097. }
  5098. return [scope, obj];
  5099. }
  5100. }
  5101. function getI18nInstance(instance) {
  5102. {
  5103. const i18n = vue.inject(!instance.isCE ? instance.appContext.app.__VUE_I18N_SYMBOL__ : I18nInjectionKey);
  5104. if (!i18n) {
  5105. throw createI18nError(!instance.isCE ? I18nErrorCodes.UNEXPECTED_ERROR : I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE);
  5106. }
  5107. return i18n;
  5108. }
  5109. }
  5110. function getScope(options, componentOptions) {
  5111. return shared.isEmptyObject(options) ? "__i18n" in componentOptions ? "local" : "global" : !options.useScope ? "local" : options.useScope;
  5112. }
  5113. function getGlobalComposer(i18n) {
  5114. return i18n.mode === "composition" ? i18n.global : i18n.global.__composer;
  5115. }
  5116. function getComposer(i18n, target, useComponent = false) {
  5117. let composer = null;
  5118. const root = target.root;
  5119. let current = getParentComponentInstance(target, useComponent);
  5120. while (current != null) {
  5121. const i18nInternal = i18n;
  5122. if (i18n.mode === "composition") {
  5123. composer = i18nInternal.__getInstance(current);
  5124. } else {
  5125. {
  5126. const vueI18n = i18nInternal.__getInstance(current);
  5127. if (vueI18n != null) {
  5128. composer = vueI18n.__composer;
  5129. if (useComponent && composer && !composer[InejctWithOptionSymbol]) {
  5130. composer = null;
  5131. }
  5132. }
  5133. }
  5134. }
  5135. if (composer != null) {
  5136. break;
  5137. }
  5138. if (root === current) {
  5139. break;
  5140. }
  5141. current = current.parent;
  5142. }
  5143. return composer;
  5144. }
  5145. function getParentComponentInstance(target, useComponent = false) {
  5146. if (target == null) {
  5147. return null;
  5148. }
  5149. {
  5150. return !useComponent ? target.parent : target.vnode.ctx || target.parent;
  5151. }
  5152. }
  5153. function setupLifeCycle(i18n, target, composer) {
  5154. {
  5155. vue.onMounted(() => {
  5156. }, target);
  5157. vue.onUnmounted(() => {
  5158. const _composer = composer;
  5159. i18n.__deleteInstance(target);
  5160. const dispose = _composer[DisposeSymbol];
  5161. if (dispose) {
  5162. dispose();
  5163. delete _composer[DisposeSymbol];
  5164. }
  5165. }, target);
  5166. }
  5167. }
  5168. function useI18nForLegacy(instance, scope, root, options = {}) {
  5169. const isLocalScope = scope === "local";
  5170. const _composer = vue.shallowRef(null);
  5171. if (isLocalScope && instance.proxy && !(instance.proxy.$options.i18n || instance.proxy.$options.__i18n)) {
  5172. throw createI18nError(I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION);
  5173. }
  5174. const _inheritLocale = shared.isBoolean(options.inheritLocale) ? options.inheritLocale : !shared.isString(options.locale);
  5175. const _locale = vue.ref(
  5176. // prettier-ignore
  5177. !isLocalScope || _inheritLocale ? root.locale.value : shared.isString(options.locale) ? options.locale : coreBase.DEFAULT_LOCALE
  5178. );
  5179. const _fallbackLocale = vue.ref(
  5180. // prettier-ignore
  5181. !isLocalScope || _inheritLocale ? root.fallbackLocale.value : shared.isString(options.fallbackLocale) || shared.isArray(options.fallbackLocale) || shared.isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale.value
  5182. );
  5183. const _messages = vue.ref(getLocaleMessages(_locale.value, options));
  5184. const _datetimeFormats = vue.ref(shared.isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [_locale.value]: {} });
  5185. const _numberFormats = vue.ref(shared.isPlainObject(options.numberFormats) ? options.numberFormats : { [_locale.value]: {} });
  5186. const _missingWarn = isLocalScope ? root.missingWarn : shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn) ? options.missingWarn : true;
  5187. const _fallbackWarn = isLocalScope ? root.fallbackWarn : shared.isBoolean(options.fallbackWarn) || shared.isRegExp(options.fallbackWarn) ? options.fallbackWarn : true;
  5188. const _fallbackRoot = isLocalScope ? root.fallbackRoot : shared.isBoolean(options.fallbackRoot) ? options.fallbackRoot : true;
  5189. const _fallbackFormat = !!options.fallbackFormat;
  5190. const _missing = shared.isFunction(options.missing) ? options.missing : null;
  5191. const _postTranslation = shared.isFunction(options.postTranslation) ? options.postTranslation : null;
  5192. const _warnHtmlMessage = isLocalScope ? root.warnHtmlMessage : shared.isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
  5193. const _escapeParameter = !!options.escapeParameter;
  5194. const _modifiers = isLocalScope ? root.modifiers : shared.isPlainObject(options.modifiers) ? options.modifiers : {};
  5195. const _pluralRules = options.pluralRules || isLocalScope && root.pluralRules;
  5196. function trackReactivityValues() {
  5197. return [
  5198. _locale.value,
  5199. _fallbackLocale.value,
  5200. _messages.value,
  5201. _datetimeFormats.value,
  5202. _numberFormats.value
  5203. ];
  5204. }
  5205. const locale = vue.computed({
  5206. get: () => {
  5207. return _composer.value ? _composer.value.locale.value : _locale.value;
  5208. },
  5209. set: (val) => {
  5210. if (_composer.value) {
  5211. _composer.value.locale.value = val;
  5212. }
  5213. _locale.value = val;
  5214. }
  5215. });
  5216. const fallbackLocale = vue.computed({
  5217. get: () => {
  5218. return _composer.value ? _composer.value.fallbackLocale.value : _fallbackLocale.value;
  5219. },
  5220. set: (val) => {
  5221. if (_composer.value) {
  5222. _composer.value.fallbackLocale.value = val;
  5223. }
  5224. _fallbackLocale.value = val;
  5225. }
  5226. });
  5227. const messages = vue.computed(() => {
  5228. if (_composer.value) {
  5229. return _composer.value.messages.value;
  5230. } else {
  5231. return _messages.value;
  5232. }
  5233. });
  5234. const datetimeFormats = vue.computed(() => _datetimeFormats.value);
  5235. const numberFormats = vue.computed(() => _numberFormats.value);
  5236. function getPostTranslationHandler() {
  5237. return _composer.value ? _composer.value.getPostTranslationHandler() : _postTranslation;
  5238. }
  5239. function setPostTranslationHandler(handler) {
  5240. if (_composer.value) {
  5241. _composer.value.setPostTranslationHandler(handler);
  5242. }
  5243. }
  5244. function getMissingHandler() {
  5245. return _composer.value ? _composer.value.getMissingHandler() : _missing;
  5246. }
  5247. function setMissingHandler(handler) {
  5248. if (_composer.value) {
  5249. _composer.value.setMissingHandler(handler);
  5250. }
  5251. }
  5252. function warpWithDeps(fn) {
  5253. trackReactivityValues();
  5254. return fn();
  5255. }
  5256. function t(...args) {
  5257. return _composer.value ? warpWithDeps(() => Reflect.apply(_composer.value.t, null, [...args])) : warpWithDeps(() => "");
  5258. }
  5259. function rt(...args) {
  5260. return _composer.value ? Reflect.apply(_composer.value.rt, null, [...args]) : "";
  5261. }
  5262. function d(...args) {
  5263. return _composer.value ? warpWithDeps(() => Reflect.apply(_composer.value.d, null, [...args])) : warpWithDeps(() => "");
  5264. }
  5265. function n(...args) {
  5266. return _composer.value ? warpWithDeps(() => Reflect.apply(_composer.value.n, null, [...args])) : warpWithDeps(() => "");
  5267. }
  5268. function tm(key) {
  5269. return _composer.value ? _composer.value.tm(key) : {};
  5270. }
  5271. function te(key, locale2) {
  5272. return _composer.value ? _composer.value.te(key, locale2) : false;
  5273. }
  5274. function getLocaleMessage(locale2) {
  5275. return _composer.value ? _composer.value.getLocaleMessage(locale2) : {};
  5276. }
  5277. function setLocaleMessage(locale2, message) {
  5278. if (_composer.value) {
  5279. _composer.value.setLocaleMessage(locale2, message);
  5280. _messages.value[locale2] = message;
  5281. }
  5282. }
  5283. function mergeLocaleMessage(locale2, message) {
  5284. if (_composer.value) {
  5285. _composer.value.mergeLocaleMessage(locale2, message);
  5286. }
  5287. }
  5288. function getDateTimeFormat(locale2) {
  5289. return _composer.value ? _composer.value.getDateTimeFormat(locale2) : {};
  5290. }
  5291. function setDateTimeFormat(locale2, format3) {
  5292. if (_composer.value) {
  5293. _composer.value.setDateTimeFormat(locale2, format3);
  5294. _datetimeFormats.value[locale2] = format3;
  5295. }
  5296. }
  5297. function mergeDateTimeFormat(locale2, format3) {
  5298. if (_composer.value) {
  5299. _composer.value.mergeDateTimeFormat(locale2, format3);
  5300. }
  5301. }
  5302. function getNumberFormat(locale2) {
  5303. return _composer.value ? _composer.value.getNumberFormat(locale2) : {};
  5304. }
  5305. function setNumberFormat(locale2, format3) {
  5306. if (_composer.value) {
  5307. _composer.value.setNumberFormat(locale2, format3);
  5308. _numberFormats.value[locale2] = format3;
  5309. }
  5310. }
  5311. function mergeNumberFormat(locale2, format3) {
  5312. if (_composer.value) {
  5313. _composer.value.mergeNumberFormat(locale2, format3);
  5314. }
  5315. }
  5316. const wrapper = {
  5317. get id() {
  5318. return _composer.value ? _composer.value.id : -1;
  5319. },
  5320. locale,
  5321. fallbackLocale,
  5322. messages,
  5323. datetimeFormats,
  5324. numberFormats,
  5325. get inheritLocale() {
  5326. return _composer.value ? _composer.value.inheritLocale : _inheritLocale;
  5327. },
  5328. set inheritLocale(val) {
  5329. if (_composer.value) {
  5330. _composer.value.inheritLocale = val;
  5331. }
  5332. },
  5333. get availableLocales() {
  5334. return _composer.value ? _composer.value.availableLocales : Object.keys(_messages.value);
  5335. },
  5336. get modifiers() {
  5337. return _composer.value ? _composer.value.modifiers : _modifiers;
  5338. },
  5339. get pluralRules() {
  5340. return _composer.value ? _composer.value.pluralRules : _pluralRules;
  5341. },
  5342. get isGlobal() {
  5343. return _composer.value ? _composer.value.isGlobal : false;
  5344. },
  5345. get missingWarn() {
  5346. return _composer.value ? _composer.value.missingWarn : _missingWarn;
  5347. },
  5348. set missingWarn(val) {
  5349. if (_composer.value) {
  5350. _composer.value.missingWarn = val;
  5351. }
  5352. },
  5353. get fallbackWarn() {
  5354. return _composer.value ? _composer.value.fallbackWarn : _fallbackWarn;
  5355. },
  5356. set fallbackWarn(val) {
  5357. if (_composer.value) {
  5358. _composer.value.missingWarn = val;
  5359. }
  5360. },
  5361. get fallbackRoot() {
  5362. return _composer.value ? _composer.value.fallbackRoot : _fallbackRoot;
  5363. },
  5364. set fallbackRoot(val) {
  5365. if (_composer.value) {
  5366. _composer.value.fallbackRoot = val;
  5367. }
  5368. },
  5369. get fallbackFormat() {
  5370. return _composer.value ? _composer.value.fallbackFormat : _fallbackFormat;
  5371. },
  5372. set fallbackFormat(val) {
  5373. if (_composer.value) {
  5374. _composer.value.fallbackFormat = val;
  5375. }
  5376. },
  5377. get warnHtmlMessage() {
  5378. return _composer.value ? _composer.value.warnHtmlMessage : _warnHtmlMessage;
  5379. },
  5380. set warnHtmlMessage(val) {
  5381. if (_composer.value) {
  5382. _composer.value.warnHtmlMessage = val;
  5383. }
  5384. },
  5385. get escapeParameter() {
  5386. return _composer.value ? _composer.value.escapeParameter : _escapeParameter;
  5387. },
  5388. set escapeParameter(val) {
  5389. if (_composer.value) {
  5390. _composer.value.escapeParameter = val;
  5391. }
  5392. },
  5393. t,
  5394. getPostTranslationHandler,
  5395. setPostTranslationHandler,
  5396. getMissingHandler,
  5397. setMissingHandler,
  5398. rt,
  5399. d,
  5400. n,
  5401. tm,
  5402. te,
  5403. getLocaleMessage,
  5404. setLocaleMessage,
  5405. mergeLocaleMessage,
  5406. getDateTimeFormat,
  5407. setDateTimeFormat,
  5408. mergeDateTimeFormat,
  5409. getNumberFormat,
  5410. setNumberFormat,
  5411. mergeNumberFormat
  5412. };
  5413. function sync(composer) {
  5414. composer.locale.value = _locale.value;
  5415. composer.fallbackLocale.value = _fallbackLocale.value;
  5416. Object.keys(_messages.value).forEach((locale2) => {
  5417. composer.mergeLocaleMessage(locale2, _messages.value[locale2]);
  5418. });
  5419. Object.keys(_datetimeFormats.value).forEach((locale2) => {
  5420. composer.mergeDateTimeFormat(locale2, _datetimeFormats.value[locale2]);
  5421. });
  5422. Object.keys(_numberFormats.value).forEach((locale2) => {
  5423. composer.mergeNumberFormat(locale2, _numberFormats.value[locale2]);
  5424. });
  5425. composer.escapeParameter = _escapeParameter;
  5426. composer.fallbackFormat = _fallbackFormat;
  5427. composer.fallbackRoot = _fallbackRoot;
  5428. composer.fallbackWarn = _fallbackWarn;
  5429. composer.missingWarn = _missingWarn;
  5430. composer.warnHtmlMessage = _warnHtmlMessage;
  5431. }
  5432. vue.onBeforeMount(() => {
  5433. if (instance.proxy == null || instance.proxy.$i18n == null) {
  5434. throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY);
  5435. }
  5436. const composer = _composer.value = instance.proxy.$i18n.__composer;
  5437. if (scope === "global") {
  5438. _locale.value = composer.locale.value;
  5439. _fallbackLocale.value = composer.fallbackLocale.value;
  5440. _messages.value = composer.messages.value;
  5441. _datetimeFormats.value = composer.datetimeFormats.value;
  5442. _numberFormats.value = composer.numberFormats.value;
  5443. } else if (isLocalScope) {
  5444. sync(composer);
  5445. }
  5446. });
  5447. return wrapper;
  5448. }
  5449. var globalExportProps = [
  5450. "locale",
  5451. "fallbackLocale",
  5452. "availableLocales"
  5453. ];
  5454. var globalExportMethods = ["t", "rt", "d", "n", "tm", "te"];
  5455. function injectGlobalFields(app, composer) {
  5456. const i18n = /* @__PURE__ */ Object.create(null);
  5457. globalExportProps.forEach((prop) => {
  5458. const desc = Object.getOwnPropertyDescriptor(composer, prop);
  5459. if (!desc) {
  5460. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  5461. }
  5462. const wrap = vue.isRef(desc.value) ? {
  5463. get() {
  5464. return desc.value.value;
  5465. },
  5466. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  5467. set(val) {
  5468. desc.value.value = val;
  5469. }
  5470. } : {
  5471. get() {
  5472. return desc.get && desc.get();
  5473. }
  5474. };
  5475. Object.defineProperty(i18n, prop, wrap);
  5476. });
  5477. app.config.globalProperties.$i18n = i18n;
  5478. globalExportMethods.forEach((method) => {
  5479. const desc = Object.getOwnPropertyDescriptor(composer, method);
  5480. if (!desc || !desc.value) {
  5481. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  5482. }
  5483. Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
  5484. });
  5485. const dispose = () => {
  5486. delete app.config.globalProperties.$i18n;
  5487. globalExportMethods.forEach((method) => {
  5488. delete app.config.globalProperties[`$${method}`];
  5489. });
  5490. };
  5491. return dispose;
  5492. }
  5493. {
  5494. coreBase.registerMessageCompiler(coreBase.compile);
  5495. }
  5496. coreBase.registerMessageResolver(coreBase.resolveValue);
  5497. coreBase.registerLocaleFallbacker(coreBase.fallbackWithLocaleChain);
  5498. {
  5499. const target = shared.getGlobalThis();
  5500. target.__INTLIFY__ = true;
  5501. coreBase.setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
  5502. }
  5503. exports.DatetimeFormat = DatetimeFormat;
  5504. exports.I18nD = I18nD;
  5505. exports.I18nInjectionKey = I18nInjectionKey;
  5506. exports.I18nN = I18nN;
  5507. exports.I18nT = I18nT;
  5508. exports.NumberFormat = NumberFormat;
  5509. exports.Translation = Translation;
  5510. exports.VERSION = VERSION2;
  5511. exports.castToVueI18n = castToVueI18n;
  5512. exports.createI18n = createI18n;
  5513. exports.useI18n = useI18n;
  5514. exports.vTDirective = vTDirective;
  5515. }
  5516. });
  5517. // node_modules/.pnpm/vue-i18n@9.13.1_vue@3.4.27/node_modules/vue-i18n/dist/vue-i18n.cjs.js
  5518. var require_vue_i18n_cjs = __commonJS({
  5519. "node_modules/.pnpm/vue-i18n@9.13.1_vue@3.4.27/node_modules/vue-i18n/dist/vue-i18n.cjs.js"(exports, module) {
  5520. module.exports = require_vue_i18n();
  5521. }
  5522. });
  5523. export default require_vue_i18n_cjs();
  5524. /*! Bundled license information:
  5525. @intlify/shared/dist/shared.esm-browser.js:
  5526. (*!
  5527. * shared v9.13.1
  5528. * (c) 2024 kazuya kawaguchi
  5529. * Released under the MIT License.
  5530. *)
  5531. @intlify/core-base/dist/core-base.esm-browser.js:
  5532. (*!
  5533. * core-base v9.13.1
  5534. * (c) 2024 kazuya kawaguchi
  5535. * Released under the MIT License.
  5536. *)
  5537. vue-i18n/dist/vue-i18n.cjs:
  5538. (*!
  5539. * vue-i18n v9.13.1
  5540. * (c) 2024 kazuya kawaguchi
  5541. * Released under the MIT License.
  5542. *)
  5543. */
  5544. //# sourceMappingURL=vue-i18n.js.map