vue-i18n.runtime.esm-browser.js 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707
  1. /*!
  2. * vue-i18n v9.2.2
  3. * (c) 2022 kazuya kawaguchi
  4. * Released under the MIT License.
  5. */
  6. import { createVNode, Text, ref, computed, watch, getCurrentInstance, Fragment, h, effectScope, inject, onMounted, onUnmounted, shallowRef, onBeforeMount, isRef } from 'vue';
  7. /**
  8. * Original Utilities
  9. * written by kazuya kawaguchi
  10. */
  11. const inBrowser = typeof window !== 'undefined';
  12. let mark;
  13. let measure;
  14. {
  15. const perf = inBrowser && window.performance;
  16. if (perf &&
  17. perf.mark &&
  18. perf.measure &&
  19. perf.clearMarks &&
  20. perf.clearMeasures) {
  21. mark = (tag) => perf.mark(tag);
  22. measure = (name, startTag, endTag) => {
  23. perf.measure(name, startTag, endTag);
  24. perf.clearMarks(startTag);
  25. perf.clearMarks(endTag);
  26. };
  27. }
  28. }
  29. const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
  30. /* eslint-disable */
  31. function format(message, ...args) {
  32. if (args.length === 1 && isObject(args[0])) {
  33. args = args[0];
  34. }
  35. if (!args || !args.hasOwnProperty) {
  36. args = {};
  37. }
  38. return message.replace(RE_ARGS, (match, identifier) => {
  39. return args.hasOwnProperty(identifier) ? args[identifier] : '';
  40. });
  41. }
  42. const hasSymbol = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
  43. const makeSymbol = (name) => hasSymbol ? Symbol(name) : name;
  44. const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
  45. const friendlyJSONstringify = (json) => JSON.stringify(json)
  46. .replace(/\u2028/g, '\\u2028')
  47. .replace(/\u2029/g, '\\u2029')
  48. .replace(/\u0027/g, '\\u0027');
  49. const isNumber = (val) => typeof val === 'number' && isFinite(val);
  50. const isDate = (val) => toTypeString(val) === '[object Date]';
  51. const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
  52. const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
  53. function warn(msg, err) {
  54. if (typeof console !== 'undefined') {
  55. console.warn(`[intlify] ` + msg);
  56. /* istanbul ignore if */
  57. if (err) {
  58. console.warn(err.stack);
  59. }
  60. }
  61. }
  62. const assign = Object.assign;
  63. let _globalThis;
  64. const getGlobalThis = () => {
  65. // prettier-ignore
  66. return (_globalThis ||
  67. (_globalThis =
  68. typeof globalThis !== 'undefined'
  69. ? globalThis
  70. : typeof self !== 'undefined'
  71. ? self
  72. : typeof window !== 'undefined'
  73. ? window
  74. : typeof global !== 'undefined'
  75. ? global
  76. : {}));
  77. };
  78. function escapeHtml(rawText) {
  79. return rawText
  80. .replace(/</g, '&lt;')
  81. .replace(/>/g, '&gt;')
  82. .replace(/"/g, '&quot;')
  83. .replace(/'/g, '&apos;');
  84. }
  85. const hasOwnProperty = Object.prototype.hasOwnProperty;
  86. function hasOwn(obj, key) {
  87. return hasOwnProperty.call(obj, key);
  88. }
  89. /* eslint-enable */
  90. /**
  91. * Useful Utilities By Evan you
  92. * Modified by kazuya kawaguchi
  93. * MIT License
  94. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
  95. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
  96. */
  97. const isArray = Array.isArray;
  98. const isFunction = (val) => typeof val === 'function';
  99. const isString = (val) => typeof val === 'string';
  100. const isBoolean = (val) => typeof val === 'boolean';
  101. const isObject = (val) => // eslint-disable-line
  102. val !== null && typeof val === 'object';
  103. const objectToString = Object.prototype.toString;
  104. const toTypeString = (value) => objectToString.call(value);
  105. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  106. // for converting list and named values to displayed strings.
  107. const toDisplayString = (val) => {
  108. return val == null
  109. ? ''
  110. : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
  111. ? JSON.stringify(val, null, 2)
  112. : String(val);
  113. };
  114. const RANGE = 2;
  115. function generateCodeFrame(source, start = 0, end = source.length) {
  116. const lines = source.split(/\r?\n/);
  117. let count = 0;
  118. const res = [];
  119. for (let i = 0; i < lines.length; i++) {
  120. count += lines[i].length + 1;
  121. if (count >= start) {
  122. for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
  123. if (j < 0 || j >= lines.length)
  124. continue;
  125. const line = j + 1;
  126. res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
  127. const lineLength = lines[j].length;
  128. if (j === i) {
  129. // push underline
  130. const pad = start - (count - lineLength) + 1;
  131. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  132. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  133. }
  134. else if (j > i) {
  135. if (end > count) {
  136. const length = Math.max(Math.min(end - count, lineLength), 1);
  137. res.push(` | ` + '^'.repeat(length));
  138. }
  139. count += lineLength + 1;
  140. }
  141. }
  142. break;
  143. }
  144. }
  145. return res.join('\n');
  146. }
  147. /**
  148. * Event emitter, forked from the below:
  149. * - original repository url: https://github.com/developit/mitt
  150. * - code url: https://github.com/developit/mitt/blob/master/src/index.ts
  151. * - author: Jason Miller (https://github.com/developit)
  152. * - license: MIT
  153. */
  154. /**
  155. * Create a event emitter
  156. *
  157. * @returns An event emitter
  158. */
  159. function createEmitter() {
  160. const events = new Map();
  161. const emitter = {
  162. events,
  163. on(event, handler) {
  164. const handlers = events.get(event);
  165. const added = handlers && handlers.push(handler);
  166. if (!added) {
  167. events.set(event, [handler]);
  168. }
  169. },
  170. off(event, handler) {
  171. const handlers = events.get(event);
  172. if (handlers) {
  173. handlers.splice(handlers.indexOf(handler) >>> 0, 1);
  174. }
  175. },
  176. emit(event, payload) {
  177. (events.get(event) || [])
  178. .slice()
  179. .map(handler => handler(payload));
  180. (events.get('*') || [])
  181. .slice()
  182. .map(handler => handler(event, payload));
  183. }
  184. };
  185. return emitter;
  186. }
  187. const CompileErrorCodes = {
  188. // tokenizer error codes
  189. EXPECTED_TOKEN: 1,
  190. INVALID_TOKEN_IN_PLACEHOLDER: 2,
  191. UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
  192. UNKNOWN_ESCAPE_SEQUENCE: 4,
  193. INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
  194. UNBALANCED_CLOSING_BRACE: 6,
  195. UNTERMINATED_CLOSING_BRACE: 7,
  196. EMPTY_PLACEHOLDER: 8,
  197. NOT_ALLOW_NEST_PLACEHOLDER: 9,
  198. INVALID_LINKED_FORMAT: 10,
  199. // parser error codes
  200. MUST_HAVE_MESSAGES_IN_PLURAL: 11,
  201. UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
  202. UNEXPECTED_EMPTY_LINKED_KEY: 13,
  203. UNEXPECTED_LEXICAL_ANALYSIS: 14,
  204. // Special value for higher-order compilers to pick up the last code
  205. // to avoid collision of error codes. This should always be kept as the last
  206. // item.
  207. __EXTEND_POINT__: 15
  208. };
  209. /** @internal */
  210. const errorMessages$2 = {
  211. // tokenizer error messages
  212. [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
  213. [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
  214. [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
  215. [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
  216. [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
  217. [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
  218. [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
  219. [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
  220. [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
  221. [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
  222. // parser error messages
  223. [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
  224. [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
  225. [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
  226. [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`
  227. };
  228. function createCompileError(code, loc, options = {}) {
  229. const { domain, messages, args } = options;
  230. const msg = format((messages || errorMessages$2)[code] || '', ...(args || []))
  231. ;
  232. const error = new SyntaxError(String(msg));
  233. error.code = code;
  234. if (loc) {
  235. error.location = loc;
  236. }
  237. error.domain = domain;
  238. return error;
  239. }
  240. const pathStateMachine = [];
  241. pathStateMachine[0 /* BEFORE_PATH */] = {
  242. ["w" /* WORKSPACE */]: [0 /* BEFORE_PATH */],
  243. ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
  244. ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
  245. ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
  246. };
  247. pathStateMachine[1 /* IN_PATH */] = {
  248. ["w" /* WORKSPACE */]: [1 /* IN_PATH */],
  249. ["." /* DOT */]: [2 /* BEFORE_IDENT */],
  250. ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
  251. ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
  252. };
  253. pathStateMachine[2 /* BEFORE_IDENT */] = {
  254. ["w" /* WORKSPACE */]: [2 /* BEFORE_IDENT */],
  255. ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
  256. ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */]
  257. };
  258. pathStateMachine[3 /* IN_IDENT */] = {
  259. ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
  260. ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */],
  261. ["w" /* WORKSPACE */]: [1 /* IN_PATH */, 1 /* PUSH */],
  262. ["." /* DOT */]: [2 /* BEFORE_IDENT */, 1 /* PUSH */],
  263. ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */, 1 /* PUSH */],
  264. ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */, 1 /* PUSH */]
  265. };
  266. pathStateMachine[4 /* IN_SUB_PATH */] = {
  267. ["'" /* SINGLE_QUOTE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */],
  268. ["\"" /* DOUBLE_QUOTE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */],
  269. ["[" /* LEFT_BRACKET */]: [
  270. 4 /* IN_SUB_PATH */,
  271. 2 /* INC_SUB_PATH_DEPTH */
  272. ],
  273. ["]" /* RIGHT_BRACKET */]: [1 /* IN_PATH */, 3 /* PUSH_SUB_PATH */],
  274. ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
  275. ["l" /* ELSE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */]
  276. };
  277. pathStateMachine[5 /* IN_SINGLE_QUOTE */] = {
  278. ["'" /* SINGLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
  279. ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
  280. ["l" /* ELSE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */]
  281. };
  282. pathStateMachine[6 /* IN_DOUBLE_QUOTE */] = {
  283. ["\"" /* DOUBLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
  284. ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
  285. ["l" /* ELSE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */]
  286. };
  287. /**
  288. * Check if an expression is a literal value.
  289. */
  290. const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
  291. function isLiteral(exp) {
  292. return literalValueRE.test(exp);
  293. }
  294. /**
  295. * Strip quotes from a string
  296. */
  297. function stripQuotes(str) {
  298. const a = str.charCodeAt(0);
  299. const b = str.charCodeAt(str.length - 1);
  300. return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
  301. }
  302. /**
  303. * Determine the type of a character in a keypath.
  304. */
  305. function getPathCharType(ch) {
  306. if (ch === undefined || ch === null) {
  307. return "o" /* END_OF_FAIL */;
  308. }
  309. const code = ch.charCodeAt(0);
  310. switch (code) {
  311. case 0x5b: // [
  312. case 0x5d: // ]
  313. case 0x2e: // .
  314. case 0x22: // "
  315. case 0x27: // '
  316. return ch;
  317. case 0x5f: // _
  318. case 0x24: // $
  319. case 0x2d: // -
  320. return "i" /* IDENT */;
  321. case 0x09: // Tab (HT)
  322. case 0x0a: // Newline (LF)
  323. case 0x0d: // Return (CR)
  324. case 0xa0: // No-break space (NBSP)
  325. case 0xfeff: // Byte Order Mark (BOM)
  326. case 0x2028: // Line Separator (LS)
  327. case 0x2029: // Paragraph Separator (PS)
  328. return "w" /* WORKSPACE */;
  329. }
  330. return "i" /* IDENT */;
  331. }
  332. /**
  333. * Format a subPath, return its plain form if it is
  334. * a literal string or number. Otherwise prepend the
  335. * dynamic indicator (*).
  336. */
  337. function formatSubPath(path) {
  338. const trimmed = path.trim();
  339. // invalid leading 0
  340. if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
  341. return false;
  342. }
  343. return isLiteral(trimmed)
  344. ? stripQuotes(trimmed)
  345. : "*" /* ASTARISK */ + trimmed;
  346. }
  347. /**
  348. * Parse a string path into an array of segments
  349. */
  350. function parse(path) {
  351. const keys = [];
  352. let index = -1;
  353. let mode = 0 /* BEFORE_PATH */;
  354. let subPathDepth = 0;
  355. let c;
  356. let key; // eslint-disable-line
  357. let newChar;
  358. let type;
  359. let transition;
  360. let action;
  361. let typeMap;
  362. const actions = [];
  363. actions[0 /* APPEND */] = () => {
  364. if (key === undefined) {
  365. key = newChar;
  366. }
  367. else {
  368. key += newChar;
  369. }
  370. };
  371. actions[1 /* PUSH */] = () => {
  372. if (key !== undefined) {
  373. keys.push(key);
  374. key = undefined;
  375. }
  376. };
  377. actions[2 /* INC_SUB_PATH_DEPTH */] = () => {
  378. actions[0 /* APPEND */]();
  379. subPathDepth++;
  380. };
  381. actions[3 /* PUSH_SUB_PATH */] = () => {
  382. if (subPathDepth > 0) {
  383. subPathDepth--;
  384. mode = 4 /* IN_SUB_PATH */;
  385. actions[0 /* APPEND */]();
  386. }
  387. else {
  388. subPathDepth = 0;
  389. if (key === undefined) {
  390. return false;
  391. }
  392. key = formatSubPath(key);
  393. if (key === false) {
  394. return false;
  395. }
  396. else {
  397. actions[1 /* PUSH */]();
  398. }
  399. }
  400. };
  401. function maybeUnescapeQuote() {
  402. const nextChar = path[index + 1];
  403. if ((mode === 5 /* IN_SINGLE_QUOTE */ &&
  404. nextChar === "'" /* SINGLE_QUOTE */) ||
  405. (mode === 6 /* IN_DOUBLE_QUOTE */ &&
  406. nextChar === "\"" /* DOUBLE_QUOTE */)) {
  407. index++;
  408. newChar = '\\' + nextChar;
  409. actions[0 /* APPEND */]();
  410. return true;
  411. }
  412. }
  413. while (mode !== null) {
  414. index++;
  415. c = path[index];
  416. if (c === '\\' && maybeUnescapeQuote()) {
  417. continue;
  418. }
  419. type = getPathCharType(c);
  420. typeMap = pathStateMachine[mode];
  421. transition = typeMap[type] || typeMap["l" /* ELSE */] || 8 /* ERROR */;
  422. // check parse error
  423. if (transition === 8 /* ERROR */) {
  424. return;
  425. }
  426. mode = transition[0];
  427. if (transition[1] !== undefined) {
  428. action = actions[transition[1]];
  429. if (action) {
  430. newChar = c;
  431. if (action() === false) {
  432. return;
  433. }
  434. }
  435. }
  436. // check parse finish
  437. if (mode === 7 /* AFTER_PATH */) {
  438. return keys;
  439. }
  440. }
  441. }
  442. // path token cache
  443. const cache = new Map();
  444. /**
  445. * key-value message resolver
  446. *
  447. * @remarks
  448. * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
  449. *
  450. * @param obj - A target object to be resolved with path
  451. * @param path - A {@link Path | path} to resolve the value of message
  452. *
  453. * @returns A resolved {@link PathValue | path value}
  454. *
  455. * @VueI18nGeneral
  456. */
  457. function resolveWithKeyValue(obj, path) {
  458. return isObject(obj) ? obj[path] : null;
  459. }
  460. /**
  461. * message resolver
  462. *
  463. * @remarks
  464. * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
  465. *
  466. * @param obj - A target object to be resolved with path
  467. * @param path - A {@link Path | path} to resolve the value of message
  468. *
  469. * @returns A resolved {@link PathValue | path value}
  470. *
  471. * @VueI18nGeneral
  472. */
  473. function resolveValue(obj, path) {
  474. // check object
  475. if (!isObject(obj)) {
  476. return null;
  477. }
  478. // parse path
  479. let hit = cache.get(path);
  480. if (!hit) {
  481. hit = parse(path);
  482. if (hit) {
  483. cache.set(path, hit);
  484. }
  485. }
  486. // check hit
  487. if (!hit) {
  488. return null;
  489. }
  490. // resolve path value
  491. const len = hit.length;
  492. let last = obj;
  493. let i = 0;
  494. while (i < len) {
  495. const val = last[hit[i]];
  496. if (val === undefined) {
  497. return null;
  498. }
  499. last = val;
  500. i++;
  501. }
  502. return last;
  503. }
  504. const DEFAULT_MODIFIER = (str) => str;
  505. const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
  506. const DEFAULT_MESSAGE_DATA_TYPE = 'text';
  507. const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
  508. const DEFAULT_INTERPOLATE = toDisplayString;
  509. function pluralDefault(choice, choicesLength) {
  510. choice = Math.abs(choice);
  511. if (choicesLength === 2) {
  512. // prettier-ignore
  513. return choice
  514. ? choice > 1
  515. ? 1
  516. : 0
  517. : 1;
  518. }
  519. return choice ? Math.min(choice, 2) : 0;
  520. }
  521. function getPluralIndex(options) {
  522. // prettier-ignore
  523. const index = isNumber(options.pluralIndex)
  524. ? options.pluralIndex
  525. : -1;
  526. // prettier-ignore
  527. return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
  528. ? isNumber(options.named.count)
  529. ? options.named.count
  530. : isNumber(options.named.n)
  531. ? options.named.n
  532. : index
  533. : index;
  534. }
  535. function normalizeNamed(pluralIndex, props) {
  536. if (!props.count) {
  537. props.count = pluralIndex;
  538. }
  539. if (!props.n) {
  540. props.n = pluralIndex;
  541. }
  542. }
  543. function createMessageContext(options = {}) {
  544. const locale = options.locale;
  545. const pluralIndex = getPluralIndex(options);
  546. const pluralRule = isObject(options.pluralRules) &&
  547. isString(locale) &&
  548. isFunction(options.pluralRules[locale])
  549. ? options.pluralRules[locale]
  550. : pluralDefault;
  551. const orgPluralRule = isObject(options.pluralRules) &&
  552. isString(locale) &&
  553. isFunction(options.pluralRules[locale])
  554. ? pluralDefault
  555. : undefined;
  556. const plural = (messages) => {
  557. return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
  558. };
  559. const _list = options.list || [];
  560. const list = (index) => _list[index];
  561. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  562. const _named = options.named || {};
  563. isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
  564. const named = (key) => _named[key];
  565. function message(key) {
  566. // prettier-ignore
  567. const msg = isFunction(options.messages)
  568. ? options.messages(key)
  569. : isObject(options.messages)
  570. ? options.messages[key]
  571. : false;
  572. return !msg
  573. ? options.parent
  574. ? options.parent.message(key) // resolve from parent messages
  575. : DEFAULT_MESSAGE
  576. : msg;
  577. }
  578. const _modifier = (name) => options.modifiers
  579. ? options.modifiers[name]
  580. : DEFAULT_MODIFIER;
  581. const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
  582. ? options.processor.normalize
  583. : DEFAULT_NORMALIZE;
  584. const interpolate = isPlainObject(options.processor) &&
  585. isFunction(options.processor.interpolate)
  586. ? options.processor.interpolate
  587. : DEFAULT_INTERPOLATE;
  588. const type = isPlainObject(options.processor) && isString(options.processor.type)
  589. ? options.processor.type
  590. : DEFAULT_MESSAGE_DATA_TYPE;
  591. const linked = (key, ...args) => {
  592. const [arg1, arg2] = args;
  593. let type = 'text';
  594. let modifier = '';
  595. if (args.length === 1) {
  596. if (isObject(arg1)) {
  597. modifier = arg1.modifier || modifier;
  598. type = arg1.type || type;
  599. }
  600. else if (isString(arg1)) {
  601. modifier = arg1 || modifier;
  602. }
  603. }
  604. else if (args.length === 2) {
  605. if (isString(arg1)) {
  606. modifier = arg1 || modifier;
  607. }
  608. if (isString(arg2)) {
  609. type = arg2 || type;
  610. }
  611. }
  612. let msg = message(key)(ctx);
  613. // The message in vnode resolved with linked are returned as an array by processor.nomalize
  614. if (type === 'vnode' && isArray(msg) && modifier) {
  615. msg = msg[0];
  616. }
  617. return modifier ? _modifier(modifier)(msg, type) : msg;
  618. };
  619. const ctx = {
  620. ["list" /* LIST */]: list,
  621. ["named" /* NAMED */]: named,
  622. ["plural" /* PLURAL */]: plural,
  623. ["linked" /* LINKED */]: linked,
  624. ["message" /* MESSAGE */]: message,
  625. ["type" /* TYPE */]: type,
  626. ["interpolate" /* INTERPOLATE */]: interpolate,
  627. ["normalize" /* NORMALIZE */]: normalize
  628. };
  629. return ctx;
  630. }
  631. const IntlifyDevToolsHooks = {
  632. I18nInit: 'i18n:init',
  633. FunctionTranslate: 'function:translate'
  634. };
  635. let devtools = null;
  636. function setDevToolsHook(hook) {
  637. devtools = hook;
  638. }
  639. function initI18nDevTools(i18n, version, meta) {
  640. // TODO: queue if devtools is undefined
  641. devtools &&
  642. devtools.emit(IntlifyDevToolsHooks.I18nInit, {
  643. timestamp: Date.now(),
  644. i18n,
  645. version,
  646. meta
  647. });
  648. }
  649. const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
  650. function createDevToolsHook(hook) {
  651. return (payloads) => devtools && devtools.emit(hook, payloads);
  652. }
  653. const CoreWarnCodes = {
  654. NOT_FOUND_KEY: 1,
  655. FALLBACK_TO_TRANSLATE: 2,
  656. CANNOT_FORMAT_NUMBER: 3,
  657. FALLBACK_TO_NUMBER_FORMAT: 4,
  658. CANNOT_FORMAT_DATE: 5,
  659. FALLBACK_TO_DATE_FORMAT: 6,
  660. __EXTEND_POINT__: 7
  661. };
  662. /** @internal */
  663. const warnMessages$1 = {
  664. [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
  665. [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
  666. [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
  667. [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
  668. [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
  669. [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`
  670. };
  671. function getWarnMessage$1(code, ...args) {
  672. return format(warnMessages$1[code], ...args);
  673. }
  674. /**
  675. * Fallback with simple implemenation
  676. *
  677. * @remarks
  678. * A fallback locale function implemented with a simple fallback algorithm.
  679. *
  680. * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
  681. *
  682. * @param ctx - A {@link CoreContext | context}
  683. * @param fallback - A {@link FallbackLocale | fallback locale}
  684. * @param start - A starting {@link Locale | locale}
  685. *
  686. * @returns Fallback locales
  687. *
  688. * @VueI18nGeneral
  689. */
  690. function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
  691. ) {
  692. // prettier-ignore
  693. return [...new Set([
  694. start,
  695. ...(isArray(fallback)
  696. ? fallback
  697. : isObject(fallback)
  698. ? Object.keys(fallback)
  699. : isString(fallback)
  700. ? [fallback]
  701. : [start])
  702. ])];
  703. }
  704. /**
  705. * Fallback with locale chain
  706. *
  707. * @remarks
  708. * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
  709. *
  710. * @param ctx - A {@link CoreContext | context}
  711. * @param fallback - A {@link FallbackLocale | fallback locale}
  712. * @param start - A starting {@link Locale | locale}
  713. *
  714. * @returns Fallback locales
  715. *
  716. * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
  717. *
  718. * @VueI18nGeneral
  719. */
  720. function fallbackWithLocaleChain(ctx, fallback, start) {
  721. const startLocale = isString(start) ? start : DEFAULT_LOCALE;
  722. const context = ctx;
  723. if (!context.__localeChainCache) {
  724. context.__localeChainCache = new Map();
  725. }
  726. let chain = context.__localeChainCache.get(startLocale);
  727. if (!chain) {
  728. chain = [];
  729. // first block defined by start
  730. let block = [start];
  731. // while any intervening block found
  732. while (isArray(block)) {
  733. block = appendBlockToChain(chain, block, fallback);
  734. }
  735. // prettier-ignore
  736. // last block defined by default
  737. const defaults = isArray(fallback) || !isPlainObject(fallback)
  738. ? fallback
  739. : fallback['default']
  740. ? fallback['default']
  741. : null;
  742. // convert defaults to array
  743. block = isString(defaults) ? [defaults] : defaults;
  744. if (isArray(block)) {
  745. appendBlockToChain(chain, block, false);
  746. }
  747. context.__localeChainCache.set(startLocale, chain);
  748. }
  749. return chain;
  750. }
  751. function appendBlockToChain(chain, block, blocks) {
  752. let follow = true;
  753. for (let i = 0; i < block.length && isBoolean(follow); i++) {
  754. const locale = block[i];
  755. if (isString(locale)) {
  756. follow = appendLocaleToChain(chain, block[i], blocks);
  757. }
  758. }
  759. return follow;
  760. }
  761. function appendLocaleToChain(chain, locale, blocks) {
  762. let follow;
  763. const tokens = locale.split('-');
  764. do {
  765. const target = tokens.join('-');
  766. follow = appendItemToChain(chain, target, blocks);
  767. tokens.splice(-1, 1);
  768. } while (tokens.length && follow === true);
  769. return follow;
  770. }
  771. function appendItemToChain(chain, target, blocks) {
  772. let follow = false;
  773. if (!chain.includes(target)) {
  774. follow = true;
  775. if (target) {
  776. follow = target[target.length - 1] !== '!';
  777. const locale = target.replace(/!/g, '');
  778. chain.push(locale);
  779. if ((isArray(blocks) || isPlainObject(blocks)) &&
  780. blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
  781. ) {
  782. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  783. follow = blocks[locale];
  784. }
  785. }
  786. }
  787. return follow;
  788. }
  789. /* eslint-disable @typescript-eslint/no-explicit-any */
  790. /**
  791. * Intlify core-base version
  792. * @internal
  793. */
  794. const VERSION$1 = '9.2.2';
  795. const NOT_REOSLVED = -1;
  796. const DEFAULT_LOCALE = 'en-US';
  797. const MISSING_RESOLVE_VALUE = '';
  798. const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
  799. function getDefaultLinkedModifiers() {
  800. return {
  801. upper: (val, type) => {
  802. // prettier-ignore
  803. return type === 'text' && isString(val)
  804. ? val.toUpperCase()
  805. : type === 'vnode' && isObject(val) && '__v_isVNode' in val
  806. ? val.children.toUpperCase()
  807. : val;
  808. },
  809. lower: (val, type) => {
  810. // prettier-ignore
  811. return type === 'text' && isString(val)
  812. ? val.toLowerCase()
  813. : type === 'vnode' && isObject(val) && '__v_isVNode' in val
  814. ? val.children.toLowerCase()
  815. : val;
  816. },
  817. capitalize: (val, type) => {
  818. // prettier-ignore
  819. return (type === 'text' && isString(val)
  820. ? capitalize(val)
  821. : type === 'vnode' && isObject(val) && '__v_isVNode' in val
  822. ? capitalize(val.children)
  823. : val);
  824. }
  825. };
  826. }
  827. let _compiler;
  828. let _resolver;
  829. /**
  830. * Register the message resolver
  831. *
  832. * @param resolver - A {@link MessageResolver} function
  833. *
  834. * @VueI18nGeneral
  835. */
  836. function registerMessageResolver(resolver) {
  837. _resolver = resolver;
  838. }
  839. let _fallbacker;
  840. /**
  841. * Register the locale fallbacker
  842. *
  843. * @param fallbacker - A {@link LocaleFallbacker} function
  844. *
  845. * @VueI18nGeneral
  846. */
  847. function registerLocaleFallbacker(fallbacker) {
  848. _fallbacker = fallbacker;
  849. }
  850. // Additional Meta for Intlify DevTools
  851. let _additionalMeta = null;
  852. const setAdditionalMeta = (meta) => {
  853. _additionalMeta = meta;
  854. };
  855. const getAdditionalMeta = () => _additionalMeta;
  856. let _fallbackContext = null;
  857. const setFallbackContext = (context) => {
  858. _fallbackContext = context;
  859. };
  860. const getFallbackContext = () => _fallbackContext;
  861. // ID for CoreContext
  862. let _cid = 0;
  863. function createCoreContext(options = {}) {
  864. // setup options
  865. const version = isString(options.version) ? options.version : VERSION$1;
  866. const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
  867. const fallbackLocale = isArray(options.fallbackLocale) ||
  868. isPlainObject(options.fallbackLocale) ||
  869. isString(options.fallbackLocale) ||
  870. options.fallbackLocale === false
  871. ? options.fallbackLocale
  872. : locale;
  873. const messages = isPlainObject(options.messages)
  874. ? options.messages
  875. : { [locale]: {} };
  876. const datetimeFormats = isPlainObject(options.datetimeFormats)
  877. ? options.datetimeFormats
  878. : { [locale]: {} }
  879. ;
  880. const numberFormats = isPlainObject(options.numberFormats)
  881. ? options.numberFormats
  882. : { [locale]: {} }
  883. ;
  884. const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
  885. const pluralRules = options.pluralRules || {};
  886. const missing = isFunction(options.missing) ? options.missing : null;
  887. const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
  888. ? options.missingWarn
  889. : true;
  890. const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
  891. ? options.fallbackWarn
  892. : true;
  893. const fallbackFormat = !!options.fallbackFormat;
  894. const unresolving = !!options.unresolving;
  895. const postTranslation = isFunction(options.postTranslation)
  896. ? options.postTranslation
  897. : null;
  898. const processor = isPlainObject(options.processor) ? options.processor : null;
  899. const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
  900. ? options.warnHtmlMessage
  901. : true;
  902. const escapeParameter = !!options.escapeParameter;
  903. const messageCompiler = isFunction(options.messageCompiler)
  904. ? options.messageCompiler
  905. : _compiler;
  906. const messageResolver = isFunction(options.messageResolver)
  907. ? options.messageResolver
  908. : _resolver || resolveWithKeyValue;
  909. const localeFallbacker = isFunction(options.localeFallbacker)
  910. ? options.localeFallbacker
  911. : _fallbacker || fallbackWithSimple;
  912. const fallbackContext = isObject(options.fallbackContext)
  913. ? options.fallbackContext
  914. : undefined;
  915. const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
  916. // setup internal options
  917. const internalOptions = options;
  918. const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
  919. ? internalOptions.__datetimeFormatters
  920. : new Map()
  921. ;
  922. const __numberFormatters = isObject(internalOptions.__numberFormatters)
  923. ? internalOptions.__numberFormatters
  924. : new Map()
  925. ;
  926. const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
  927. _cid++;
  928. const context = {
  929. version,
  930. cid: _cid,
  931. locale,
  932. fallbackLocale,
  933. messages,
  934. modifiers,
  935. pluralRules,
  936. missing,
  937. missingWarn,
  938. fallbackWarn,
  939. fallbackFormat,
  940. unresolving,
  941. postTranslation,
  942. processor,
  943. warnHtmlMessage,
  944. escapeParameter,
  945. messageCompiler,
  946. messageResolver,
  947. localeFallbacker,
  948. fallbackContext,
  949. onWarn,
  950. __meta
  951. };
  952. {
  953. context.datetimeFormats = datetimeFormats;
  954. context.numberFormats = numberFormats;
  955. context.__datetimeFormatters = __datetimeFormatters;
  956. context.__numberFormatters = __numberFormatters;
  957. }
  958. // for vue-devtools timeline event
  959. {
  960. context.__v_emitter =
  961. internalOptions.__v_emitter != null
  962. ? internalOptions.__v_emitter
  963. : undefined;
  964. }
  965. // NOTE: experimental !!
  966. {
  967. initI18nDevTools(context, version, __meta);
  968. }
  969. return context;
  970. }
  971. /** @internal */
  972. function isTranslateFallbackWarn(fallback, key) {
  973. return fallback instanceof RegExp ? fallback.test(key) : fallback;
  974. }
  975. /** @internal */
  976. function isTranslateMissingWarn(missing, key) {
  977. return missing instanceof RegExp ? missing.test(key) : missing;
  978. }
  979. /** @internal */
  980. function handleMissing(context, key, locale, missingWarn, type) {
  981. const { missing, onWarn } = context;
  982. // for vue-devtools timeline event
  983. {
  984. const emitter = context.__v_emitter;
  985. if (emitter) {
  986. emitter.emit("missing" /* MISSING */, {
  987. locale,
  988. key,
  989. type,
  990. groupId: `${type}:${key}`
  991. });
  992. }
  993. }
  994. if (missing !== null) {
  995. const ret = missing(context, locale, key, type);
  996. return isString(ret) ? ret : key;
  997. }
  998. else {
  999. if (isTranslateMissingWarn(missingWarn, key)) {
  1000. onWarn(getWarnMessage$1(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
  1001. }
  1002. return key;
  1003. }
  1004. }
  1005. /** @internal */
  1006. function updateFallbackLocale(ctx, locale, fallback) {
  1007. const context = ctx;
  1008. context.__localeChainCache = new Map();
  1009. ctx.localeFallbacker(ctx, fallback, locale);
  1010. }
  1011. /* eslint-enable @typescript-eslint/no-explicit-any */
  1012. let code$2 = CompileErrorCodes.__EXTEND_POINT__;
  1013. const inc$2 = () => ++code$2;
  1014. const CoreErrorCodes = {
  1015. INVALID_ARGUMENT: code$2,
  1016. INVALID_DATE_ARGUMENT: inc$2(),
  1017. INVALID_ISO_DATE_ARGUMENT: inc$2(),
  1018. __EXTEND_POINT__: inc$2() // 18
  1019. };
  1020. function createCoreError(code) {
  1021. return createCompileError(code, null, { messages: errorMessages$1 } );
  1022. }
  1023. /** @internal */
  1024. const errorMessages$1 = {
  1025. [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
  1026. [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
  1027. 'Make sure your Date represents a valid date.',
  1028. [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string'
  1029. };
  1030. const NOOP_MESSAGE_FUNCTION = () => '';
  1031. const isMessageFunction = (val) => isFunction(val);
  1032. // implementation of `translate` function
  1033. function translate(context, ...args) {
  1034. const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
  1035. const [key, options] = parseTranslateArgs(...args);
  1036. const missingWarn = isBoolean(options.missingWarn)
  1037. ? options.missingWarn
  1038. : context.missingWarn;
  1039. const fallbackWarn = isBoolean(options.fallbackWarn)
  1040. ? options.fallbackWarn
  1041. : context.fallbackWarn;
  1042. const escapeParameter = isBoolean(options.escapeParameter)
  1043. ? options.escapeParameter
  1044. : context.escapeParameter;
  1045. const resolvedMessage = !!options.resolvedMessage;
  1046. // prettier-ignore
  1047. const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
  1048. ? !isBoolean(options.default)
  1049. ? options.default
  1050. : (!messageCompiler ? () => key : key)
  1051. : fallbackFormat // default by `fallbackFormat` option
  1052. ? (!messageCompiler ? () => key : key)
  1053. : '';
  1054. const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
  1055. const locale = isString(options.locale) ? options.locale : context.locale;
  1056. // escape params
  1057. escapeParameter && escapeParams(options);
  1058. // resolve message format
  1059. // eslint-disable-next-line prefer-const
  1060. let [formatScope, targetLocale, message] = !resolvedMessage
  1061. ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
  1062. : [
  1063. key,
  1064. locale,
  1065. messages[locale] || {}
  1066. ];
  1067. // NOTE:
  1068. // Fix to work around `ssrTransfrom` bug in Vite.
  1069. // https://github.com/vitejs/vite/issues/4306
  1070. // To get around this, use temporary variables.
  1071. // https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
  1072. let format = formatScope;
  1073. // if you use default message, set it as message format!
  1074. let cacheBaseKey = key;
  1075. if (!resolvedMessage &&
  1076. !(isString(format) || isMessageFunction(format))) {
  1077. if (enableDefaultMsg) {
  1078. format = defaultMsgOrKey;
  1079. cacheBaseKey = format;
  1080. }
  1081. }
  1082. // checking message format and target locale
  1083. if (!resolvedMessage &&
  1084. (!(isString(format) || isMessageFunction(format)) ||
  1085. !isString(targetLocale))) {
  1086. return unresolving ? NOT_REOSLVED : key;
  1087. }
  1088. if (isString(format) && context.messageCompiler == null) {
  1089. warn(`The message format compilation is not supported in this build. ` +
  1090. `Because message compiler isn't included. ` +
  1091. `You need to pre-compilation all message format. ` +
  1092. `So translate function return '${key}'.`);
  1093. return key;
  1094. }
  1095. // setup compile error detecting
  1096. let occurred = false;
  1097. const errorDetector = () => {
  1098. occurred = true;
  1099. };
  1100. // compile message format
  1101. const msg = !isMessageFunction(format)
  1102. ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
  1103. : format;
  1104. // if occurred compile error, return the message format
  1105. if (occurred) {
  1106. return format;
  1107. }
  1108. // evaluate message with context
  1109. const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
  1110. const msgContext = createMessageContext(ctxOptions);
  1111. const messaged = evaluateMessage(context, msg, msgContext);
  1112. // if use post translation option, proceed it with handler
  1113. const ret = postTranslation
  1114. ? postTranslation(messaged, key)
  1115. : messaged;
  1116. // NOTE: experimental !!
  1117. {
  1118. // prettier-ignore
  1119. const payloads = {
  1120. timestamp: Date.now(),
  1121. key: isString(key)
  1122. ? key
  1123. : isMessageFunction(format)
  1124. ? format.key
  1125. : '',
  1126. locale: targetLocale || (isMessageFunction(format)
  1127. ? format.locale
  1128. : ''),
  1129. format: isString(format)
  1130. ? format
  1131. : isMessageFunction(format)
  1132. ? format.source
  1133. : '',
  1134. message: ret
  1135. };
  1136. payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
  1137. translateDevTools(payloads);
  1138. }
  1139. return ret;
  1140. }
  1141. function escapeParams(options) {
  1142. if (isArray(options.list)) {
  1143. options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
  1144. }
  1145. else if (isObject(options.named)) {
  1146. Object.keys(options.named).forEach(key => {
  1147. if (isString(options.named[key])) {
  1148. options.named[key] = escapeHtml(options.named[key]);
  1149. }
  1150. });
  1151. }
  1152. }
  1153. function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
  1154. const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
  1155. const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
  1156. let message = {};
  1157. let targetLocale;
  1158. let format = null;
  1159. let from = locale;
  1160. let to = null;
  1161. const type = 'translate';
  1162. for (let i = 0; i < locales.length; i++) {
  1163. targetLocale = to = locales[i];
  1164. if (locale !== targetLocale &&
  1165. isTranslateFallbackWarn(fallbackWarn, key)) {
  1166. onWarn(getWarnMessage$1(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
  1167. key,
  1168. target: targetLocale
  1169. }));
  1170. }
  1171. // for vue-devtools timeline event
  1172. if (locale !== targetLocale) {
  1173. const emitter = context.__v_emitter;
  1174. if (emitter) {
  1175. emitter.emit("fallback" /* FALBACK */, {
  1176. type,
  1177. key,
  1178. from,
  1179. to,
  1180. groupId: `${type}:${key}`
  1181. });
  1182. }
  1183. }
  1184. message =
  1185. messages[targetLocale] || {};
  1186. // for vue-devtools timeline event
  1187. let start = null;
  1188. let startTag;
  1189. let endTag;
  1190. if (inBrowser) {
  1191. start = window.performance.now();
  1192. startTag = 'intlify-message-resolve-start';
  1193. endTag = 'intlify-message-resolve-end';
  1194. mark && mark(startTag);
  1195. }
  1196. if ((format = resolveValue(message, key)) === null) {
  1197. // if null, resolve with object key path
  1198. format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
  1199. }
  1200. // for vue-devtools timeline event
  1201. if (inBrowser) {
  1202. const end = window.performance.now();
  1203. const emitter = context.__v_emitter;
  1204. if (emitter && start && format) {
  1205. emitter.emit("message-resolve" /* MESSAGE_RESOLVE */, {
  1206. type: "message-resolve" /* MESSAGE_RESOLVE */,
  1207. key,
  1208. message: format,
  1209. time: end - start,
  1210. groupId: `${type}:${key}`
  1211. });
  1212. }
  1213. if (startTag && endTag && mark && measure) {
  1214. mark(endTag);
  1215. measure('intlify message resolve', startTag, endTag);
  1216. }
  1217. }
  1218. if (isString(format) || isFunction(format))
  1219. break;
  1220. const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
  1221. key, targetLocale, missingWarn, type);
  1222. if (missingRet !== key) {
  1223. format = missingRet;
  1224. }
  1225. from = to;
  1226. }
  1227. return [format, targetLocale, message];
  1228. }
  1229. function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
  1230. const { messageCompiler, warnHtmlMessage } = context;
  1231. if (isMessageFunction(format)) {
  1232. const msg = format;
  1233. msg.locale = msg.locale || targetLocale;
  1234. msg.key = msg.key || key;
  1235. return msg;
  1236. }
  1237. if (messageCompiler == null) {
  1238. const msg = (() => format);
  1239. msg.locale = targetLocale;
  1240. msg.key = key;
  1241. return msg;
  1242. }
  1243. // for vue-devtools timeline event
  1244. let start = null;
  1245. let startTag;
  1246. let endTag;
  1247. if (inBrowser) {
  1248. start = window.performance.now();
  1249. startTag = 'intlify-message-compilation-start';
  1250. endTag = 'intlify-message-compilation-end';
  1251. mark && mark(startTag);
  1252. }
  1253. const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
  1254. // for vue-devtools timeline event
  1255. if (inBrowser) {
  1256. const end = window.performance.now();
  1257. const emitter = context.__v_emitter;
  1258. if (emitter && start) {
  1259. emitter.emit("message-compilation" /* MESSAGE_COMPILATION */, {
  1260. type: "message-compilation" /* MESSAGE_COMPILATION */,
  1261. message: format,
  1262. time: end - start,
  1263. groupId: `${'translate'}:${key}`
  1264. });
  1265. }
  1266. if (startTag && endTag && mark && measure) {
  1267. mark(endTag);
  1268. measure('intlify message compilation', startTag, endTag);
  1269. }
  1270. }
  1271. msg.locale = targetLocale;
  1272. msg.key = key;
  1273. msg.source = format;
  1274. return msg;
  1275. }
  1276. function evaluateMessage(context, msg, msgCtx) {
  1277. // for vue-devtools timeline event
  1278. let start = null;
  1279. let startTag;
  1280. let endTag;
  1281. if (inBrowser) {
  1282. start = window.performance.now();
  1283. startTag = 'intlify-message-evaluation-start';
  1284. endTag = 'intlify-message-evaluation-end';
  1285. mark && mark(startTag);
  1286. }
  1287. const messaged = msg(msgCtx);
  1288. // for vue-devtools timeline event
  1289. if (inBrowser) {
  1290. const end = window.performance.now();
  1291. const emitter = context.__v_emitter;
  1292. if (emitter && start) {
  1293. emitter.emit("message-evaluation" /* MESSAGE_EVALUATION */, {
  1294. type: "message-evaluation" /* MESSAGE_EVALUATION */,
  1295. value: messaged,
  1296. time: end - start,
  1297. groupId: `${'translate'}:${msg.key}`
  1298. });
  1299. }
  1300. if (startTag && endTag && mark && measure) {
  1301. mark(endTag);
  1302. measure('intlify message evaluation', startTag, endTag);
  1303. }
  1304. }
  1305. return messaged;
  1306. }
  1307. /** @internal */
  1308. function parseTranslateArgs(...args) {
  1309. const [arg1, arg2, arg3] = args;
  1310. const options = {};
  1311. if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
  1312. throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
  1313. }
  1314. // prettier-ignore
  1315. const key = isNumber(arg1)
  1316. ? String(arg1)
  1317. : isMessageFunction(arg1)
  1318. ? arg1
  1319. : arg1;
  1320. if (isNumber(arg2)) {
  1321. options.plural = arg2;
  1322. }
  1323. else if (isString(arg2)) {
  1324. options.default = arg2;
  1325. }
  1326. else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
  1327. options.named = arg2;
  1328. }
  1329. else if (isArray(arg2)) {
  1330. options.list = arg2;
  1331. }
  1332. if (isNumber(arg3)) {
  1333. options.plural = arg3;
  1334. }
  1335. else if (isString(arg3)) {
  1336. options.default = arg3;
  1337. }
  1338. else if (isPlainObject(arg3)) {
  1339. assign(options, arg3);
  1340. }
  1341. return [key, options];
  1342. }
  1343. function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
  1344. return {
  1345. warnHtmlMessage,
  1346. onError: (err) => {
  1347. errorDetector && errorDetector(err);
  1348. {
  1349. const message = `Message compilation error: ${err.message}`;
  1350. const codeFrame = err.location &&
  1351. generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
  1352. const emitter = context.__v_emitter;
  1353. if (emitter) {
  1354. emitter.emit("compile-error" /* COMPILE_ERROR */, {
  1355. message: source,
  1356. error: err.message,
  1357. start: err.location && err.location.start.offset,
  1358. end: err.location && err.location.end.offset,
  1359. groupId: `${'translate'}:${key}`
  1360. });
  1361. }
  1362. console.error(codeFrame ? `${message}\n${codeFrame}` : message);
  1363. }
  1364. },
  1365. onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
  1366. };
  1367. }
  1368. function getMessageContextOptions(context, locale, message, options) {
  1369. const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
  1370. const resolveMessage = (key) => {
  1371. let val = resolveValue(message, key);
  1372. // fallback to root context
  1373. if (val == null && fallbackContext) {
  1374. const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
  1375. val = resolveValue(message, key);
  1376. }
  1377. if (isString(val)) {
  1378. let occurred = false;
  1379. const errorDetector = () => {
  1380. occurred = true;
  1381. };
  1382. const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
  1383. return !occurred
  1384. ? msg
  1385. : NOOP_MESSAGE_FUNCTION;
  1386. }
  1387. else if (isMessageFunction(val)) {
  1388. return val;
  1389. }
  1390. else {
  1391. // TODO: should be implemented warning message
  1392. return NOOP_MESSAGE_FUNCTION;
  1393. }
  1394. };
  1395. const ctxOptions = {
  1396. locale,
  1397. modifiers,
  1398. pluralRules,
  1399. messages: resolveMessage
  1400. };
  1401. if (context.processor) {
  1402. ctxOptions.processor = context.processor;
  1403. }
  1404. if (options.list) {
  1405. ctxOptions.list = options.list;
  1406. }
  1407. if (options.named) {
  1408. ctxOptions.named = options.named;
  1409. }
  1410. if (isNumber(options.plural)) {
  1411. ctxOptions.pluralIndex = options.plural;
  1412. }
  1413. return ctxOptions;
  1414. }
  1415. const intlDefined = typeof Intl !== 'undefined';
  1416. const Availabilities = {
  1417. dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
  1418. numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
  1419. };
  1420. // implementation of `datetime` function
  1421. function datetime(context, ...args) {
  1422. const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
  1423. const { __datetimeFormatters } = context;
  1424. if (!Availabilities.dateTimeFormat) {
  1425. onWarn(getWarnMessage$1(CoreWarnCodes.CANNOT_FORMAT_DATE));
  1426. return MISSING_RESOLVE_VALUE;
  1427. }
  1428. const [key, value, options, overrides] = parseDateTimeArgs(...args);
  1429. const missingWarn = isBoolean(options.missingWarn)
  1430. ? options.missingWarn
  1431. : context.missingWarn;
  1432. const fallbackWarn = isBoolean(options.fallbackWarn)
  1433. ? options.fallbackWarn
  1434. : context.fallbackWarn;
  1435. const part = !!options.part;
  1436. const locale = isString(options.locale) ? options.locale : context.locale;
  1437. const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
  1438. fallbackLocale, locale);
  1439. if (!isString(key) || key === '') {
  1440. return new Intl.DateTimeFormat(locale, overrides).format(value);
  1441. }
  1442. // resolve format
  1443. let datetimeFormat = {};
  1444. let targetLocale;
  1445. let format = null;
  1446. let from = locale;
  1447. let to = null;
  1448. const type = 'datetime format';
  1449. for (let i = 0; i < locales.length; i++) {
  1450. targetLocale = to = locales[i];
  1451. if (locale !== targetLocale &&
  1452. isTranslateFallbackWarn(fallbackWarn, key)) {
  1453. onWarn(getWarnMessage$1(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
  1454. key,
  1455. target: targetLocale
  1456. }));
  1457. }
  1458. // for vue-devtools timeline event
  1459. if (locale !== targetLocale) {
  1460. const emitter = context.__v_emitter;
  1461. if (emitter) {
  1462. emitter.emit("fallback" /* FALBACK */, {
  1463. type,
  1464. key,
  1465. from,
  1466. to,
  1467. groupId: `${type}:${key}`
  1468. });
  1469. }
  1470. }
  1471. datetimeFormat =
  1472. datetimeFormats[targetLocale] || {};
  1473. format = datetimeFormat[key];
  1474. if (isPlainObject(format))
  1475. break;
  1476. handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
  1477. from = to;
  1478. }
  1479. // checking format and target locale
  1480. if (!isPlainObject(format) || !isString(targetLocale)) {
  1481. return unresolving ? NOT_REOSLVED : key;
  1482. }
  1483. let id = `${targetLocale}__${key}`;
  1484. if (!isEmptyObject(overrides)) {
  1485. id = `${id}__${JSON.stringify(overrides)}`;
  1486. }
  1487. let formatter = __datetimeFormatters.get(id);
  1488. if (!formatter) {
  1489. formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
  1490. __datetimeFormatters.set(id, formatter);
  1491. }
  1492. return !part ? formatter.format(value) : formatter.formatToParts(value);
  1493. }
  1494. /** @internal */
  1495. const DATETIME_FORMAT_OPTIONS_KEYS = [
  1496. 'localeMatcher',
  1497. 'weekday',
  1498. 'era',
  1499. 'year',
  1500. 'month',
  1501. 'day',
  1502. 'hour',
  1503. 'minute',
  1504. 'second',
  1505. 'timeZoneName',
  1506. 'formatMatcher',
  1507. 'hour12',
  1508. 'timeZone',
  1509. 'dateStyle',
  1510. 'timeStyle',
  1511. 'calendar',
  1512. 'dayPeriod',
  1513. 'numberingSystem',
  1514. 'hourCycle',
  1515. 'fractionalSecondDigits'
  1516. ];
  1517. /** @internal */
  1518. function parseDateTimeArgs(...args) {
  1519. const [arg1, arg2, arg3, arg4] = args;
  1520. const options = {};
  1521. let overrides = {};
  1522. let value;
  1523. if (isString(arg1)) {
  1524. // Only allow ISO strings - other date formats are often supported,
  1525. // but may cause different results in different browsers.
  1526. const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
  1527. if (!matches) {
  1528. throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
  1529. }
  1530. // Some browsers can not parse the iso datetime separated by space,
  1531. // this is a compromise solution by replace the 'T'/' ' with 'T'
  1532. const dateTime = matches[3]
  1533. ? matches[3].trim().startsWith('T')
  1534. ? `${matches[1].trim()}${matches[3].trim()}`
  1535. : `${matches[1].trim()}T${matches[3].trim()}`
  1536. : matches[1].trim();
  1537. value = new Date(dateTime);
  1538. try {
  1539. // This will fail if the date is not valid
  1540. value.toISOString();
  1541. }
  1542. catch (e) {
  1543. throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
  1544. }
  1545. }
  1546. else if (isDate(arg1)) {
  1547. if (isNaN(arg1.getTime())) {
  1548. throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
  1549. }
  1550. value = arg1;
  1551. }
  1552. else if (isNumber(arg1)) {
  1553. value = arg1;
  1554. }
  1555. else {
  1556. throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
  1557. }
  1558. if (isString(arg2)) {
  1559. options.key = arg2;
  1560. }
  1561. else if (isPlainObject(arg2)) {
  1562. Object.keys(arg2).forEach(key => {
  1563. if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
  1564. overrides[key] = arg2[key];
  1565. }
  1566. else {
  1567. options[key] = arg2[key];
  1568. }
  1569. });
  1570. }
  1571. if (isString(arg3)) {
  1572. options.locale = arg3;
  1573. }
  1574. else if (isPlainObject(arg3)) {
  1575. overrides = arg3;
  1576. }
  1577. if (isPlainObject(arg4)) {
  1578. overrides = arg4;
  1579. }
  1580. return [options.key || '', value, options, overrides];
  1581. }
  1582. /** @internal */
  1583. function clearDateTimeFormat(ctx, locale, format) {
  1584. const context = ctx;
  1585. for (const key in format) {
  1586. const id = `${locale}__${key}`;
  1587. if (!context.__datetimeFormatters.has(id)) {
  1588. continue;
  1589. }
  1590. context.__datetimeFormatters.delete(id);
  1591. }
  1592. }
  1593. // implementation of `number` function
  1594. function number(context, ...args) {
  1595. const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
  1596. const { __numberFormatters } = context;
  1597. if (!Availabilities.numberFormat) {
  1598. onWarn(getWarnMessage$1(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
  1599. return MISSING_RESOLVE_VALUE;
  1600. }
  1601. const [key, value, options, overrides] = parseNumberArgs(...args);
  1602. const missingWarn = isBoolean(options.missingWarn)
  1603. ? options.missingWarn
  1604. : context.missingWarn;
  1605. const fallbackWarn = isBoolean(options.fallbackWarn)
  1606. ? options.fallbackWarn
  1607. : context.fallbackWarn;
  1608. const part = !!options.part;
  1609. const locale = isString(options.locale) ? options.locale : context.locale;
  1610. const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
  1611. fallbackLocale, locale);
  1612. if (!isString(key) || key === '') {
  1613. return new Intl.NumberFormat(locale, overrides).format(value);
  1614. }
  1615. // resolve format
  1616. let numberFormat = {};
  1617. let targetLocale;
  1618. let format = null;
  1619. let from = locale;
  1620. let to = null;
  1621. const type = 'number format';
  1622. for (let i = 0; i < locales.length; i++) {
  1623. targetLocale = to = locales[i];
  1624. if (locale !== targetLocale &&
  1625. isTranslateFallbackWarn(fallbackWarn, key)) {
  1626. onWarn(getWarnMessage$1(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
  1627. key,
  1628. target: targetLocale
  1629. }));
  1630. }
  1631. // for vue-devtools timeline event
  1632. if (locale !== targetLocale) {
  1633. const emitter = context.__v_emitter;
  1634. if (emitter) {
  1635. emitter.emit("fallback" /* FALBACK */, {
  1636. type,
  1637. key,
  1638. from,
  1639. to,
  1640. groupId: `${type}:${key}`
  1641. });
  1642. }
  1643. }
  1644. numberFormat =
  1645. numberFormats[targetLocale] || {};
  1646. format = numberFormat[key];
  1647. if (isPlainObject(format))
  1648. break;
  1649. handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
  1650. from = to;
  1651. }
  1652. // checking format and target locale
  1653. if (!isPlainObject(format) || !isString(targetLocale)) {
  1654. return unresolving ? NOT_REOSLVED : key;
  1655. }
  1656. let id = `${targetLocale}__${key}`;
  1657. if (!isEmptyObject(overrides)) {
  1658. id = `${id}__${JSON.stringify(overrides)}`;
  1659. }
  1660. let formatter = __numberFormatters.get(id);
  1661. if (!formatter) {
  1662. formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
  1663. __numberFormatters.set(id, formatter);
  1664. }
  1665. return !part ? formatter.format(value) : formatter.formatToParts(value);
  1666. }
  1667. /** @internal */
  1668. const NUMBER_FORMAT_OPTIONS_KEYS = [
  1669. 'localeMatcher',
  1670. 'style',
  1671. 'currency',
  1672. 'currencyDisplay',
  1673. 'currencySign',
  1674. 'useGrouping',
  1675. 'minimumIntegerDigits',
  1676. 'minimumFractionDigits',
  1677. 'maximumFractionDigits',
  1678. 'minimumSignificantDigits',
  1679. 'maximumSignificantDigits',
  1680. 'compactDisplay',
  1681. 'notation',
  1682. 'signDisplay',
  1683. 'unit',
  1684. 'unitDisplay',
  1685. 'roundingMode',
  1686. 'roundingPriority',
  1687. 'roundingIncrement',
  1688. 'trailingZeroDisplay'
  1689. ];
  1690. /** @internal */
  1691. function parseNumberArgs(...args) {
  1692. const [arg1, arg2, arg3, arg4] = args;
  1693. const options = {};
  1694. let overrides = {};
  1695. if (!isNumber(arg1)) {
  1696. throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
  1697. }
  1698. const value = arg1;
  1699. if (isString(arg2)) {
  1700. options.key = arg2;
  1701. }
  1702. else if (isPlainObject(arg2)) {
  1703. Object.keys(arg2).forEach(key => {
  1704. if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
  1705. overrides[key] = arg2[key];
  1706. }
  1707. else {
  1708. options[key] = arg2[key];
  1709. }
  1710. });
  1711. }
  1712. if (isString(arg3)) {
  1713. options.locale = arg3;
  1714. }
  1715. else if (isPlainObject(arg3)) {
  1716. overrides = arg3;
  1717. }
  1718. if (isPlainObject(arg4)) {
  1719. overrides = arg4;
  1720. }
  1721. return [options.key || '', value, options, overrides];
  1722. }
  1723. /** @internal */
  1724. function clearNumberFormat(ctx, locale, format) {
  1725. const context = ctx;
  1726. for (const key in format) {
  1727. const id = `${locale}__${key}`;
  1728. if (!context.__numberFormatters.has(id)) {
  1729. continue;
  1730. }
  1731. context.__numberFormatters.delete(id);
  1732. }
  1733. }
  1734. /**
  1735. * Vue I18n Version
  1736. *
  1737. * @remarks
  1738. * Semver format. Same format as the package.json `version` field.
  1739. *
  1740. * @VueI18nGeneral
  1741. */
  1742. const VERSION = '9.2.2';
  1743. /**
  1744. * This is only called development env
  1745. * istanbul-ignore-next
  1746. */
  1747. function initDev() {
  1748. {
  1749. {
  1750. console.info(`You are running a development build of vue-i18n.\n` +
  1751. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  1752. }
  1753. }
  1754. }
  1755. let code$1 = CoreWarnCodes.__EXTEND_POINT__;
  1756. const inc$1 = () => ++code$1;
  1757. const I18nWarnCodes = {
  1758. FALLBACK_TO_ROOT: code$1,
  1759. NOT_SUPPORTED_PRESERVE: inc$1(),
  1760. NOT_SUPPORTED_FORMATTER: inc$1(),
  1761. NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc$1(),
  1762. NOT_SUPPORTED_GET_CHOICE_INDEX: inc$1(),
  1763. COMPONENT_NAME_LEGACY_COMPATIBLE: inc$1(),
  1764. NOT_FOUND_PARENT_SCOPE: inc$1() // 13
  1765. };
  1766. const warnMessages = {
  1767. [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
  1768. [I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `Not supported 'preserve'.`,
  1769. [I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supported 'formatter'.`,
  1770. [I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supported 'preserveDirectiveContent'.`,
  1771. [I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
  1772. [I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
  1773. [I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`
  1774. };
  1775. function getWarnMessage(code, ...args) {
  1776. return format(warnMessages[code], ...args);
  1777. }
  1778. let code = CompileErrorCodes.__EXTEND_POINT__;
  1779. const inc = () => ++code;
  1780. const I18nErrorCodes = {
  1781. // composer module errors
  1782. UNEXPECTED_RETURN_TYPE: code,
  1783. // legacy module errors
  1784. INVALID_ARGUMENT: inc(),
  1785. // i18n module errors
  1786. MUST_BE_CALL_SETUP_TOP: inc(),
  1787. NOT_INSLALLED: inc(),
  1788. NOT_AVAILABLE_IN_LEGACY_MODE: inc(),
  1789. // directive module errors
  1790. REQUIRED_VALUE: inc(),
  1791. INVALID_VALUE: inc(),
  1792. // vue-devtools errors
  1793. CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: inc(),
  1794. NOT_INSLALLED_WITH_PROVIDE: inc(),
  1795. // unexpected error
  1796. UNEXPECTED_ERROR: inc(),
  1797. // not compatible legacy vue-i18n constructor
  1798. NOT_COMPATIBLE_LEGACY_VUE_I18N: inc(),
  1799. // bridge support vue 2.x only
  1800. BRIDGE_SUPPORT_VUE_2_ONLY: inc(),
  1801. // need to define `i18n` option in `allowComposition: true` and `useScope: 'local' at `useI18n``
  1802. MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION: inc(),
  1803. // Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
  1804. NOT_AVAILABLE_COMPOSITION_IN_LEGACY: inc(),
  1805. // for enhancement
  1806. __EXTEND_POINT__: inc() // 29
  1807. };
  1808. function createI18nError(code, ...args) {
  1809. return createCompileError(code, null, { messages: errorMessages, args } );
  1810. }
  1811. const errorMessages = {
  1812. [I18nErrorCodes.UNEXPECTED_RETURN_TYPE]: 'Unexpected return type in composer',
  1813. [I18nErrorCodes.INVALID_ARGUMENT]: 'Invalid argument',
  1814. [I18nErrorCodes.MUST_BE_CALL_SETUP_TOP]: 'Must be called at the top of a `setup` function',
  1815. [I18nErrorCodes.NOT_INSLALLED]: 'Need to install with `app.use` function',
  1816. [I18nErrorCodes.UNEXPECTED_ERROR]: 'Unexpected error',
  1817. [I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE]: 'Not available in legacy mode',
  1818. [I18nErrorCodes.REQUIRED_VALUE]: `Required in value: {0}`,
  1819. [I18nErrorCodes.INVALID_VALUE]: `Invalid value`,
  1820. [I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
  1821. [I18nErrorCodes.NOT_INSLALLED_WITH_PROVIDE]: 'Need to install with `provide` function',
  1822. [I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: 'Not compatible legacy VueI18n.',
  1823. [I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]: 'vue-i18n-bridge support Vue 2.x only',
  1824. [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',
  1825. [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'
  1826. };
  1827. const TransrateVNodeSymbol =
  1828. /* #__PURE__*/ makeSymbol('__transrateVNode');
  1829. const DatetimePartsSymbol = /* #__PURE__*/ makeSymbol('__datetimeParts');
  1830. const NumberPartsSymbol = /* #__PURE__*/ makeSymbol('__numberParts');
  1831. const EnableEmitter = /* #__PURE__*/ makeSymbol('__enableEmitter');
  1832. const DisableEmitter = /* #__PURE__*/ makeSymbol('__disableEmitter');
  1833. const SetPluralRulesSymbol = makeSymbol('__setPluralRules');
  1834. const InejctWithOption = /* #__PURE__*/ makeSymbol('__injectWithOption');
  1835. const __VUE_I18N_BRIDGE__ = '__VUE_I18N_BRIDGE__';
  1836. /* eslint-disable @typescript-eslint/no-explicit-any */
  1837. /**
  1838. * Transform flat json in obj to normal json in obj
  1839. */
  1840. function handleFlatJson(obj) {
  1841. // check obj
  1842. if (!isObject(obj)) {
  1843. return obj;
  1844. }
  1845. for (const key in obj) {
  1846. // check key
  1847. if (!hasOwn(obj, key)) {
  1848. continue;
  1849. }
  1850. // handle for normal json
  1851. if (!key.includes('.')) {
  1852. // recursive process value if value is also a object
  1853. if (isObject(obj[key])) {
  1854. handleFlatJson(obj[key]);
  1855. }
  1856. }
  1857. // handle for flat json, transform to normal json
  1858. else {
  1859. // go to the last object
  1860. const subKeys = key.split('.');
  1861. const lastIndex = subKeys.length - 1;
  1862. let currentObj = obj;
  1863. for (let i = 0; i < lastIndex; i++) {
  1864. if (!(subKeys[i] in currentObj)) {
  1865. currentObj[subKeys[i]] = {};
  1866. }
  1867. currentObj = currentObj[subKeys[i]];
  1868. }
  1869. // update last object value, delete old property
  1870. currentObj[subKeys[lastIndex]] = obj[key];
  1871. delete obj[key];
  1872. // recursive process value if value is also a object
  1873. if (isObject(currentObj[subKeys[lastIndex]])) {
  1874. handleFlatJson(currentObj[subKeys[lastIndex]]);
  1875. }
  1876. }
  1877. }
  1878. return obj;
  1879. }
  1880. function getLocaleMessages(locale, options) {
  1881. const { messages, __i18n, messageResolver, flatJson } = options;
  1882. // prettier-ignore
  1883. const ret = isPlainObject(messages)
  1884. ? messages
  1885. : isArray(__i18n)
  1886. ? {}
  1887. : { [locale]: {} };
  1888. // merge locale messages of i18n custom block
  1889. if (isArray(__i18n)) {
  1890. __i18n.forEach(custom => {
  1891. if ('locale' in custom && 'resource' in custom) {
  1892. const { locale, resource } = custom;
  1893. if (locale) {
  1894. ret[locale] = ret[locale] || {};
  1895. deepCopy(resource, ret[locale]);
  1896. }
  1897. else {
  1898. deepCopy(resource, ret);
  1899. }
  1900. }
  1901. else {
  1902. isString(custom) && deepCopy(JSON.parse(custom), ret);
  1903. }
  1904. });
  1905. }
  1906. // handle messages for flat json
  1907. if (messageResolver == null && flatJson) {
  1908. for (const key in ret) {
  1909. if (hasOwn(ret, key)) {
  1910. handleFlatJson(ret[key]);
  1911. }
  1912. }
  1913. }
  1914. return ret;
  1915. }
  1916. const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
  1917. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
  1918. function deepCopy(src, des) {
  1919. // src and des should both be objects, and non of then can be a array
  1920. if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
  1921. throw createI18nError(I18nErrorCodes.INVALID_VALUE);
  1922. }
  1923. for (const key in src) {
  1924. if (hasOwn(src, key)) {
  1925. if (isNotObjectOrIsArray(src[key]) || isNotObjectOrIsArray(des[key])) {
  1926. // replace with src[key] when:
  1927. // src[key] or des[key] is not a object, or
  1928. // src[key] or des[key] is a array
  1929. des[key] = src[key];
  1930. }
  1931. else {
  1932. // src[key] and des[key] are both object, merge them
  1933. deepCopy(src[key], des[key]);
  1934. }
  1935. }
  1936. }
  1937. }
  1938. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1939. function getComponentOptions(instance) {
  1940. return instance.type ;
  1941. }
  1942. function adjustI18nResources(global, options, componentOptions // eslint-disable-line @typescript-eslint/no-explicit-any
  1943. ) {
  1944. let messages = isObject(options.messages) ? options.messages : {};
  1945. if ('__i18nGlobal' in componentOptions) {
  1946. messages = getLocaleMessages(global.locale.value, {
  1947. messages,
  1948. __i18n: componentOptions.__i18nGlobal
  1949. });
  1950. }
  1951. // merge locale messages
  1952. const locales = Object.keys(messages);
  1953. if (locales.length) {
  1954. locales.forEach(locale => {
  1955. global.mergeLocaleMessage(locale, messages[locale]);
  1956. });
  1957. }
  1958. {
  1959. // merge datetime formats
  1960. if (isObject(options.datetimeFormats)) {
  1961. const locales = Object.keys(options.datetimeFormats);
  1962. if (locales.length) {
  1963. locales.forEach(locale => {
  1964. global.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
  1965. });
  1966. }
  1967. }
  1968. // merge number formats
  1969. if (isObject(options.numberFormats)) {
  1970. const locales = Object.keys(options.numberFormats);
  1971. if (locales.length) {
  1972. locales.forEach(locale => {
  1973. global.mergeNumberFormat(locale, options.numberFormats[locale]);
  1974. });
  1975. }
  1976. }
  1977. }
  1978. }
  1979. function createTextNode(key) {
  1980. return createVNode(Text, null, key, 0)
  1981. ;
  1982. }
  1983. /* eslint-enable @typescript-eslint/no-explicit-any */
  1984. /* eslint-disable @typescript-eslint/no-explicit-any */
  1985. // extend VNode interface
  1986. const DEVTOOLS_META = '__INTLIFY_META__';
  1987. let composerID = 0;
  1988. function defineCoreMissingHandler(missing) {
  1989. return ((ctx, locale, key, type) => {
  1990. return missing(locale, key, getCurrentInstance() || undefined, type);
  1991. });
  1992. }
  1993. // for Intlify DevTools
  1994. const getMetaInfo = () => {
  1995. const instance = getCurrentInstance();
  1996. let meta = null; // eslint-disable-line @typescript-eslint/no-explicit-any
  1997. return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META])
  1998. ? { [DEVTOOLS_META]: meta } // eslint-disable-line @typescript-eslint/no-explicit-any
  1999. : null;
  2000. };
  2001. /**
  2002. * Create composer interface factory
  2003. *
  2004. * @internal
  2005. */
  2006. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  2007. function createComposer(options = {}, VueI18nLegacy) {
  2008. const { __root } = options;
  2009. const _isGlobal = __root === undefined;
  2010. let _inheritLocale = isBoolean(options.inheritLocale)
  2011. ? options.inheritLocale
  2012. : true;
  2013. const _locale = ref(
  2014. // prettier-ignore
  2015. __root && _inheritLocale
  2016. ? __root.locale.value
  2017. : isString(options.locale)
  2018. ? options.locale
  2019. : DEFAULT_LOCALE);
  2020. const _fallbackLocale = ref(
  2021. // prettier-ignore
  2022. __root && _inheritLocale
  2023. ? __root.fallbackLocale.value
  2024. : isString(options.fallbackLocale) ||
  2025. isArray(options.fallbackLocale) ||
  2026. isPlainObject(options.fallbackLocale) ||
  2027. options.fallbackLocale === false
  2028. ? options.fallbackLocale
  2029. : _locale.value);
  2030. const _messages = ref(getLocaleMessages(_locale.value, options));
  2031. // prettier-ignore
  2032. const _datetimeFormats = ref(isPlainObject(options.datetimeFormats)
  2033. ? options.datetimeFormats
  2034. : { [_locale.value]: {} })
  2035. ;
  2036. // prettier-ignore
  2037. const _numberFormats = ref(isPlainObject(options.numberFormats)
  2038. ? options.numberFormats
  2039. : { [_locale.value]: {} })
  2040. ;
  2041. // warning suppress options
  2042. // prettier-ignore
  2043. let _missingWarn = __root
  2044. ? __root.missingWarn
  2045. : isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
  2046. ? options.missingWarn
  2047. : true;
  2048. // prettier-ignore
  2049. let _fallbackWarn = __root
  2050. ? __root.fallbackWarn
  2051. : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
  2052. ? options.fallbackWarn
  2053. : true;
  2054. // prettier-ignore
  2055. let _fallbackRoot = __root
  2056. ? __root.fallbackRoot
  2057. : isBoolean(options.fallbackRoot)
  2058. ? options.fallbackRoot
  2059. : true;
  2060. // configure fall back to root
  2061. let _fallbackFormat = !!options.fallbackFormat;
  2062. // runtime missing
  2063. let _missing = isFunction(options.missing) ? options.missing : null;
  2064. let _runtimeMissing = isFunction(options.missing)
  2065. ? defineCoreMissingHandler(options.missing)
  2066. : null;
  2067. // postTranslation handler
  2068. let _postTranslation = isFunction(options.postTranslation)
  2069. ? options.postTranslation
  2070. : null;
  2071. // prettier-ignore
  2072. let _warnHtmlMessage = __root
  2073. ? __root.warnHtmlMessage
  2074. : isBoolean(options.warnHtmlMessage)
  2075. ? options.warnHtmlMessage
  2076. : true;
  2077. let _escapeParameter = !!options.escapeParameter;
  2078. // custom linked modifiers
  2079. // prettier-ignore
  2080. const _modifiers = __root
  2081. ? __root.modifiers
  2082. : isPlainObject(options.modifiers)
  2083. ? options.modifiers
  2084. : {};
  2085. // pluralRules
  2086. let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
  2087. // runtime context
  2088. // eslint-disable-next-line prefer-const
  2089. let _context;
  2090. const getCoreContext = () => {
  2091. _isGlobal && setFallbackContext(null);
  2092. const ctxOptions = {
  2093. version: VERSION,
  2094. locale: _locale.value,
  2095. fallbackLocale: _fallbackLocale.value,
  2096. messages: _messages.value,
  2097. modifiers: _modifiers,
  2098. pluralRules: _pluralRules,
  2099. missing: _runtimeMissing === null ? undefined : _runtimeMissing,
  2100. missingWarn: _missingWarn,
  2101. fallbackWarn: _fallbackWarn,
  2102. fallbackFormat: _fallbackFormat,
  2103. unresolving: true,
  2104. postTranslation: _postTranslation === null ? undefined : _postTranslation,
  2105. warnHtmlMessage: _warnHtmlMessage,
  2106. escapeParameter: _escapeParameter,
  2107. messageResolver: options.messageResolver,
  2108. __meta: { framework: 'vue' }
  2109. };
  2110. {
  2111. ctxOptions.datetimeFormats = _datetimeFormats.value;
  2112. ctxOptions.numberFormats = _numberFormats.value;
  2113. ctxOptions.__datetimeFormatters = isPlainObject(_context)
  2114. ? _context.__datetimeFormatters
  2115. : undefined;
  2116. ctxOptions.__numberFormatters = isPlainObject(_context)
  2117. ? _context.__numberFormatters
  2118. : undefined;
  2119. }
  2120. {
  2121. ctxOptions.__v_emitter = isPlainObject(_context)
  2122. ? _context.__v_emitter
  2123. : undefined;
  2124. }
  2125. const ctx = createCoreContext(ctxOptions);
  2126. _isGlobal && setFallbackContext(ctx);
  2127. return ctx;
  2128. };
  2129. _context = getCoreContext();
  2130. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  2131. // track reactivity
  2132. function trackReactivityValues() {
  2133. return [
  2134. _locale.value,
  2135. _fallbackLocale.value,
  2136. _messages.value,
  2137. _datetimeFormats.value,
  2138. _numberFormats.value
  2139. ]
  2140. ;
  2141. }
  2142. // locale
  2143. const locale = computed({
  2144. get: () => _locale.value,
  2145. set: val => {
  2146. _locale.value = val;
  2147. _context.locale = _locale.value;
  2148. }
  2149. });
  2150. // fallbackLocale
  2151. const fallbackLocale = computed({
  2152. get: () => _fallbackLocale.value,
  2153. set: val => {
  2154. _fallbackLocale.value = val;
  2155. _context.fallbackLocale = _fallbackLocale.value;
  2156. updateFallbackLocale(_context, _locale.value, val);
  2157. }
  2158. });
  2159. // messages
  2160. const messages = computed(() => _messages.value);
  2161. // datetimeFormats
  2162. const datetimeFormats = /* #__PURE__*/ computed(() => _datetimeFormats.value);
  2163. // numberFormats
  2164. const numberFormats = /* #__PURE__*/ computed(() => _numberFormats.value);
  2165. // getPostTranslationHandler
  2166. function getPostTranslationHandler() {
  2167. return isFunction(_postTranslation) ? _postTranslation : null;
  2168. }
  2169. // setPostTranslationHandler
  2170. function setPostTranslationHandler(handler) {
  2171. _postTranslation = handler;
  2172. _context.postTranslation = handler;
  2173. }
  2174. // getMissingHandler
  2175. function getMissingHandler() {
  2176. return _missing;
  2177. }
  2178. // setMissingHandler
  2179. function setMissingHandler(handler) {
  2180. if (handler !== null) {
  2181. _runtimeMissing = defineCoreMissingHandler(handler);
  2182. }
  2183. _missing = handler;
  2184. _context.missing = _runtimeMissing;
  2185. }
  2186. function isResolvedTranslateMessage(type, arg // eslint-disable-line @typescript-eslint/no-explicit-any
  2187. ) {
  2188. return type !== 'translate' || !arg.resolvedMessage;
  2189. }
  2190. const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
  2191. trackReactivityValues(); // track reactive dependency
  2192. // NOTE: experimental !!
  2193. let ret;
  2194. {
  2195. try {
  2196. setAdditionalMeta(getMetaInfo());
  2197. if (!_isGlobal) {
  2198. _context.fallbackContext = __root
  2199. ? getFallbackContext()
  2200. : undefined;
  2201. }
  2202. ret = fn(_context);
  2203. }
  2204. finally {
  2205. setAdditionalMeta(null);
  2206. if (!_isGlobal) {
  2207. _context.fallbackContext = undefined;
  2208. }
  2209. }
  2210. }
  2211. if (isNumber(ret) && ret === NOT_REOSLVED) {
  2212. const [key, arg2] = argumentParser();
  2213. if (__root &&
  2214. isString(key) &&
  2215. isResolvedTranslateMessage(warnType, arg2)) {
  2216. if (_fallbackRoot &&
  2217. (isTranslateFallbackWarn(_fallbackWarn, key) ||
  2218. isTranslateMissingWarn(_missingWarn, key))) {
  2219. warn(getWarnMessage(I18nWarnCodes.FALLBACK_TO_ROOT, {
  2220. key,
  2221. type: warnType
  2222. }));
  2223. }
  2224. // for vue-devtools timeline event
  2225. {
  2226. const { __v_emitter: emitter } = _context;
  2227. if (emitter && _fallbackRoot) {
  2228. emitter.emit("fallback" /* FALBACK */, {
  2229. type: warnType,
  2230. key,
  2231. to: 'global',
  2232. groupId: `${warnType}:${key}`
  2233. });
  2234. }
  2235. }
  2236. }
  2237. return __root && _fallbackRoot
  2238. ? fallbackSuccess(__root)
  2239. : fallbackFail(key);
  2240. }
  2241. else if (successCondition(ret)) {
  2242. return ret;
  2243. }
  2244. else {
  2245. /* istanbul ignore next */
  2246. throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
  2247. }
  2248. };
  2249. // t
  2250. function t(...args) {
  2251. return wrapWithDeps(context => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), 'translate', root => Reflect.apply(root.t, root, [...args]), key => key, val => isString(val));
  2252. }
  2253. // rt
  2254. function rt(...args) {
  2255. const [arg1, arg2, arg3] = args;
  2256. if (arg3 && !isObject(arg3)) {
  2257. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  2258. }
  2259. return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
  2260. }
  2261. // d
  2262. function d(...args) {
  2263. return wrapWithDeps(context => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), 'datetime format', root => Reflect.apply(root.d, root, [...args]), () => MISSING_RESOLVE_VALUE, val => isString(val));
  2264. }
  2265. // n
  2266. function n(...args) {
  2267. return wrapWithDeps(context => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), 'number format', root => Reflect.apply(root.n, root, [...args]), () => MISSING_RESOLVE_VALUE, val => isString(val));
  2268. }
  2269. // for custom processor
  2270. function normalize(values) {
  2271. return values.map(val => isString(val) || isNumber(val) || isBoolean(val)
  2272. ? createTextNode(String(val))
  2273. : val);
  2274. }
  2275. const interpolate = (val) => val;
  2276. const processor = {
  2277. normalize,
  2278. interpolate,
  2279. type: 'vnode'
  2280. };
  2281. // transrateVNode, using for `i18n-t` component
  2282. function transrateVNode(...args) {
  2283. return wrapWithDeps(context => {
  2284. let ret;
  2285. const _context = context;
  2286. try {
  2287. _context.processor = processor;
  2288. ret = Reflect.apply(translate, null, [_context, ...args]);
  2289. }
  2290. finally {
  2291. _context.processor = null;
  2292. }
  2293. return ret;
  2294. }, () => parseTranslateArgs(...args), 'translate',
  2295. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2296. root => root[TransrateVNodeSymbol](...args), key => [createTextNode(key)], val => isArray(val));
  2297. }
  2298. // numberParts, using for `i18n-n` component
  2299. function numberParts(...args) {
  2300. return wrapWithDeps(context => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), 'number format',
  2301. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2302. root => root[NumberPartsSymbol](...args), () => [], val => isString(val) || isArray(val));
  2303. }
  2304. // datetimeParts, using for `i18n-d` component
  2305. function datetimeParts(...args) {
  2306. return wrapWithDeps(context => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), 'datetime format',
  2307. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2308. root => root[DatetimePartsSymbol](...args), () => [], val => isString(val) || isArray(val));
  2309. }
  2310. function setPluralRules(rules) {
  2311. _pluralRules = rules;
  2312. _context.pluralRules = _pluralRules;
  2313. }
  2314. // te
  2315. function te(key, locale) {
  2316. const targetLocale = isString(locale) ? locale : _locale.value;
  2317. const message = getLocaleMessage(targetLocale);
  2318. return _context.messageResolver(message, key) !== null;
  2319. }
  2320. function resolveMessages(key) {
  2321. let messages = null;
  2322. const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
  2323. for (let i = 0; i < locales.length; i++) {
  2324. const targetLocaleMessages = _messages.value[locales[i]] || {};
  2325. const messageValue = _context.messageResolver(targetLocaleMessages, key);
  2326. if (messageValue != null) {
  2327. messages = messageValue;
  2328. break;
  2329. }
  2330. }
  2331. return messages;
  2332. }
  2333. // tm
  2334. function tm(key) {
  2335. const messages = resolveMessages(key);
  2336. // prettier-ignore
  2337. return messages != null
  2338. ? messages
  2339. : __root
  2340. ? __root.tm(key) || {}
  2341. : {};
  2342. }
  2343. // getLocaleMessage
  2344. function getLocaleMessage(locale) {
  2345. return (_messages.value[locale] || {});
  2346. }
  2347. // setLocaleMessage
  2348. function setLocaleMessage(locale, message) {
  2349. _messages.value[locale] = message;
  2350. _context.messages = _messages.value;
  2351. }
  2352. // mergeLocaleMessage
  2353. function mergeLocaleMessage(locale, message) {
  2354. _messages.value[locale] = _messages.value[locale] || {};
  2355. deepCopy(message, _messages.value[locale]);
  2356. _context.messages = _messages.value;
  2357. }
  2358. // getDateTimeFormat
  2359. function getDateTimeFormat(locale) {
  2360. return _datetimeFormats.value[locale] || {};
  2361. }
  2362. // setDateTimeFormat
  2363. function setDateTimeFormat(locale, format) {
  2364. _datetimeFormats.value[locale] = format;
  2365. _context.datetimeFormats = _datetimeFormats.value;
  2366. clearDateTimeFormat(_context, locale, format);
  2367. }
  2368. // mergeDateTimeFormat
  2369. function mergeDateTimeFormat(locale, format) {
  2370. _datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format);
  2371. _context.datetimeFormats = _datetimeFormats.value;
  2372. clearDateTimeFormat(_context, locale, format);
  2373. }
  2374. // getNumberFormat
  2375. function getNumberFormat(locale) {
  2376. return _numberFormats.value[locale] || {};
  2377. }
  2378. // setNumberFormat
  2379. function setNumberFormat(locale, format) {
  2380. _numberFormats.value[locale] = format;
  2381. _context.numberFormats = _numberFormats.value;
  2382. clearNumberFormat(_context, locale, format);
  2383. }
  2384. // mergeNumberFormat
  2385. function mergeNumberFormat(locale, format) {
  2386. _numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format);
  2387. _context.numberFormats = _numberFormats.value;
  2388. clearNumberFormat(_context, locale, format);
  2389. }
  2390. // for debug
  2391. composerID++;
  2392. // watch root locale & fallbackLocale
  2393. if (__root && inBrowser) {
  2394. watch(__root.locale, (val) => {
  2395. if (_inheritLocale) {
  2396. _locale.value = val;
  2397. _context.locale = val;
  2398. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  2399. }
  2400. });
  2401. watch(__root.fallbackLocale, (val) => {
  2402. if (_inheritLocale) {
  2403. _fallbackLocale.value = val;
  2404. _context.fallbackLocale = val;
  2405. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  2406. }
  2407. });
  2408. }
  2409. // define basic composition API!
  2410. const composer = {
  2411. id: composerID,
  2412. locale,
  2413. fallbackLocale,
  2414. get inheritLocale() {
  2415. return _inheritLocale;
  2416. },
  2417. set inheritLocale(val) {
  2418. _inheritLocale = val;
  2419. if (val && __root) {
  2420. _locale.value = __root.locale.value;
  2421. _fallbackLocale.value = __root.fallbackLocale.value;
  2422. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  2423. }
  2424. },
  2425. get availableLocales() {
  2426. return Object.keys(_messages.value).sort();
  2427. },
  2428. messages,
  2429. get modifiers() {
  2430. return _modifiers;
  2431. },
  2432. get pluralRules() {
  2433. return _pluralRules || {};
  2434. },
  2435. get isGlobal() {
  2436. return _isGlobal;
  2437. },
  2438. get missingWarn() {
  2439. return _missingWarn;
  2440. },
  2441. set missingWarn(val) {
  2442. _missingWarn = val;
  2443. _context.missingWarn = _missingWarn;
  2444. },
  2445. get fallbackWarn() {
  2446. return _fallbackWarn;
  2447. },
  2448. set fallbackWarn(val) {
  2449. _fallbackWarn = val;
  2450. _context.fallbackWarn = _fallbackWarn;
  2451. },
  2452. get fallbackRoot() {
  2453. return _fallbackRoot;
  2454. },
  2455. set fallbackRoot(val) {
  2456. _fallbackRoot = val;
  2457. },
  2458. get fallbackFormat() {
  2459. return _fallbackFormat;
  2460. },
  2461. set fallbackFormat(val) {
  2462. _fallbackFormat = val;
  2463. _context.fallbackFormat = _fallbackFormat;
  2464. },
  2465. get warnHtmlMessage() {
  2466. return _warnHtmlMessage;
  2467. },
  2468. set warnHtmlMessage(val) {
  2469. _warnHtmlMessage = val;
  2470. _context.warnHtmlMessage = val;
  2471. },
  2472. get escapeParameter() {
  2473. return _escapeParameter;
  2474. },
  2475. set escapeParameter(val) {
  2476. _escapeParameter = val;
  2477. _context.escapeParameter = val;
  2478. },
  2479. t,
  2480. getLocaleMessage,
  2481. setLocaleMessage,
  2482. mergeLocaleMessage,
  2483. getPostTranslationHandler,
  2484. setPostTranslationHandler,
  2485. getMissingHandler,
  2486. setMissingHandler,
  2487. [SetPluralRulesSymbol]: setPluralRules
  2488. };
  2489. {
  2490. composer.datetimeFormats = datetimeFormats;
  2491. composer.numberFormats = numberFormats;
  2492. composer.rt = rt;
  2493. composer.te = te;
  2494. composer.tm = tm;
  2495. composer.d = d;
  2496. composer.n = n;
  2497. composer.getDateTimeFormat = getDateTimeFormat;
  2498. composer.setDateTimeFormat = setDateTimeFormat;
  2499. composer.mergeDateTimeFormat = mergeDateTimeFormat;
  2500. composer.getNumberFormat = getNumberFormat;
  2501. composer.setNumberFormat = setNumberFormat;
  2502. composer.mergeNumberFormat = mergeNumberFormat;
  2503. composer[InejctWithOption] = options.__injectWithOption;
  2504. composer[TransrateVNodeSymbol] = transrateVNode;
  2505. composer[DatetimePartsSymbol] = datetimeParts;
  2506. composer[NumberPartsSymbol] = numberParts;
  2507. }
  2508. // for vue-devtools timeline event
  2509. {
  2510. composer[EnableEmitter] = (emitter) => {
  2511. _context.__v_emitter = emitter;
  2512. };
  2513. composer[DisableEmitter] = () => {
  2514. _context.__v_emitter = undefined;
  2515. };
  2516. }
  2517. return composer;
  2518. }
  2519. /* eslint-enable @typescript-eslint/no-explicit-any */
  2520. /* eslint-disable @typescript-eslint/no-explicit-any */
  2521. /**
  2522. * Convert to I18n Composer Options from VueI18n Options
  2523. *
  2524. * @internal
  2525. */
  2526. function convertComposerOptions(options) {
  2527. const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
  2528. const fallbackLocale = isString(options.fallbackLocale) ||
  2529. isArray(options.fallbackLocale) ||
  2530. isPlainObject(options.fallbackLocale) ||
  2531. options.fallbackLocale === false
  2532. ? options.fallbackLocale
  2533. : locale;
  2534. const missing = isFunction(options.missing) ? options.missing : undefined;
  2535. const missingWarn = isBoolean(options.silentTranslationWarn) ||
  2536. isRegExp(options.silentTranslationWarn)
  2537. ? !options.silentTranslationWarn
  2538. : true;
  2539. const fallbackWarn = isBoolean(options.silentFallbackWarn) ||
  2540. isRegExp(options.silentFallbackWarn)
  2541. ? !options.silentFallbackWarn
  2542. : true;
  2543. const fallbackRoot = isBoolean(options.fallbackRoot)
  2544. ? options.fallbackRoot
  2545. : true;
  2546. const fallbackFormat = !!options.formatFallbackMessages;
  2547. const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {};
  2548. const pluralizationRules = options.pluralizationRules;
  2549. const postTranslation = isFunction(options.postTranslation)
  2550. ? options.postTranslation
  2551. : undefined;
  2552. const warnHtmlMessage = isString(options.warnHtmlInMessage)
  2553. ? options.warnHtmlInMessage !== 'off'
  2554. : true;
  2555. const escapeParameter = !!options.escapeParameterHtml;
  2556. const inheritLocale = isBoolean(options.sync) ? options.sync : true;
  2557. if (options.formatter) {
  2558. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER));
  2559. }
  2560. if (options.preserveDirectiveContent) {
  2561. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE));
  2562. }
  2563. let messages = options.messages;
  2564. if (isPlainObject(options.sharedMessages)) {
  2565. const sharedMessages = options.sharedMessages;
  2566. const locales = Object.keys(sharedMessages);
  2567. messages = locales.reduce((messages, locale) => {
  2568. const message = messages[locale] || (messages[locale] = {});
  2569. assign(message, sharedMessages[locale]);
  2570. return messages;
  2571. }, (messages || {}));
  2572. }
  2573. const { __i18n, __root, __injectWithOption } = options;
  2574. const datetimeFormats = options.datetimeFormats;
  2575. const numberFormats = options.numberFormats;
  2576. const flatJson = options.flatJson;
  2577. return {
  2578. locale,
  2579. fallbackLocale,
  2580. messages,
  2581. flatJson,
  2582. datetimeFormats,
  2583. numberFormats,
  2584. missing,
  2585. missingWarn,
  2586. fallbackWarn,
  2587. fallbackRoot,
  2588. fallbackFormat,
  2589. modifiers,
  2590. pluralRules: pluralizationRules,
  2591. postTranslation,
  2592. warnHtmlMessage,
  2593. escapeParameter,
  2594. messageResolver: options.messageResolver,
  2595. inheritLocale,
  2596. __i18n,
  2597. __root,
  2598. __injectWithOption
  2599. };
  2600. }
  2601. /**
  2602. * create VueI18n interface factory
  2603. *
  2604. * @internal
  2605. */
  2606. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  2607. function createVueI18n(options = {}, VueI18nLegacy) {
  2608. {
  2609. const composer = createComposer(convertComposerOptions(options));
  2610. // defines VueI18n
  2611. const vueI18n = {
  2612. // id
  2613. id: composer.id,
  2614. // locale
  2615. get locale() {
  2616. return composer.locale.value;
  2617. },
  2618. set locale(val) {
  2619. composer.locale.value = val;
  2620. },
  2621. // fallbackLocale
  2622. get fallbackLocale() {
  2623. return composer.fallbackLocale.value;
  2624. },
  2625. set fallbackLocale(val) {
  2626. composer.fallbackLocale.value = val;
  2627. },
  2628. // messages
  2629. get messages() {
  2630. return composer.messages.value;
  2631. },
  2632. // datetimeFormats
  2633. get datetimeFormats() {
  2634. return composer.datetimeFormats.value;
  2635. },
  2636. // numberFormats
  2637. get numberFormats() {
  2638. return composer.numberFormats.value;
  2639. },
  2640. // availableLocales
  2641. get availableLocales() {
  2642. return composer.availableLocales;
  2643. },
  2644. // formatter
  2645. get formatter() {
  2646. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER));
  2647. // dummy
  2648. return {
  2649. interpolate() {
  2650. return [];
  2651. }
  2652. };
  2653. },
  2654. set formatter(val) {
  2655. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER));
  2656. },
  2657. // missing
  2658. get missing() {
  2659. return composer.getMissingHandler();
  2660. },
  2661. set missing(handler) {
  2662. composer.setMissingHandler(handler);
  2663. },
  2664. // silentTranslationWarn
  2665. get silentTranslationWarn() {
  2666. return isBoolean(composer.missingWarn)
  2667. ? !composer.missingWarn
  2668. : composer.missingWarn;
  2669. },
  2670. set silentTranslationWarn(val) {
  2671. composer.missingWarn = isBoolean(val) ? !val : val;
  2672. },
  2673. // silentFallbackWarn
  2674. get silentFallbackWarn() {
  2675. return isBoolean(composer.fallbackWarn)
  2676. ? !composer.fallbackWarn
  2677. : composer.fallbackWarn;
  2678. },
  2679. set silentFallbackWarn(val) {
  2680. composer.fallbackWarn = isBoolean(val) ? !val : val;
  2681. },
  2682. // modifiers
  2683. get modifiers() {
  2684. return composer.modifiers;
  2685. },
  2686. // formatFallbackMessages
  2687. get formatFallbackMessages() {
  2688. return composer.fallbackFormat;
  2689. },
  2690. set formatFallbackMessages(val) {
  2691. composer.fallbackFormat = val;
  2692. },
  2693. // postTranslation
  2694. get postTranslation() {
  2695. return composer.getPostTranslationHandler();
  2696. },
  2697. set postTranslation(handler) {
  2698. composer.setPostTranslationHandler(handler);
  2699. },
  2700. // sync
  2701. get sync() {
  2702. return composer.inheritLocale;
  2703. },
  2704. set sync(val) {
  2705. composer.inheritLocale = val;
  2706. },
  2707. // warnInHtmlMessage
  2708. get warnHtmlInMessage() {
  2709. return composer.warnHtmlMessage ? 'warn' : 'off';
  2710. },
  2711. set warnHtmlInMessage(val) {
  2712. composer.warnHtmlMessage = val !== 'off';
  2713. },
  2714. // escapeParameterHtml
  2715. get escapeParameterHtml() {
  2716. return composer.escapeParameter;
  2717. },
  2718. set escapeParameterHtml(val) {
  2719. composer.escapeParameter = val;
  2720. },
  2721. // preserveDirectiveContent
  2722. get preserveDirectiveContent() {
  2723. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE));
  2724. return true;
  2725. },
  2726. set preserveDirectiveContent(val) {
  2727. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE));
  2728. },
  2729. // pluralizationRules
  2730. get pluralizationRules() {
  2731. return composer.pluralRules || {};
  2732. },
  2733. // for internal
  2734. __composer: composer,
  2735. // t
  2736. t(...args) {
  2737. const [arg1, arg2, arg3] = args;
  2738. const options = {};
  2739. let list = null;
  2740. let named = null;
  2741. if (!isString(arg1)) {
  2742. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  2743. }
  2744. const key = arg1;
  2745. if (isString(arg2)) {
  2746. options.locale = arg2;
  2747. }
  2748. else if (isArray(arg2)) {
  2749. list = arg2;
  2750. }
  2751. else if (isPlainObject(arg2)) {
  2752. named = arg2;
  2753. }
  2754. if (isArray(arg3)) {
  2755. list = arg3;
  2756. }
  2757. else if (isPlainObject(arg3)) {
  2758. named = arg3;
  2759. }
  2760. // return composer.t(key, (list || named || {}) as any, options)
  2761. return Reflect.apply(composer.t, composer, [
  2762. key,
  2763. (list || named || {}),
  2764. options
  2765. ]);
  2766. },
  2767. rt(...args) {
  2768. return Reflect.apply(composer.rt, composer, [...args]);
  2769. },
  2770. // tc
  2771. tc(...args) {
  2772. const [arg1, arg2, arg3] = args;
  2773. const options = { plural: 1 };
  2774. let list = null;
  2775. let named = null;
  2776. if (!isString(arg1)) {
  2777. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  2778. }
  2779. const key = arg1;
  2780. if (isString(arg2)) {
  2781. options.locale = arg2;
  2782. }
  2783. else if (isNumber(arg2)) {
  2784. options.plural = arg2;
  2785. }
  2786. else if (isArray(arg2)) {
  2787. list = arg2;
  2788. }
  2789. else if (isPlainObject(arg2)) {
  2790. named = arg2;
  2791. }
  2792. if (isString(arg3)) {
  2793. options.locale = arg3;
  2794. }
  2795. else if (isArray(arg3)) {
  2796. list = arg3;
  2797. }
  2798. else if (isPlainObject(arg3)) {
  2799. named = arg3;
  2800. }
  2801. // return composer.t(key, (list || named || {}) as any, options)
  2802. return Reflect.apply(composer.t, composer, [
  2803. key,
  2804. (list || named || {}),
  2805. options
  2806. ]);
  2807. },
  2808. // te
  2809. te(key, locale) {
  2810. return composer.te(key, locale);
  2811. },
  2812. // tm
  2813. tm(key) {
  2814. return composer.tm(key);
  2815. },
  2816. // getLocaleMessage
  2817. getLocaleMessage(locale) {
  2818. return composer.getLocaleMessage(locale);
  2819. },
  2820. // setLocaleMessage
  2821. setLocaleMessage(locale, message) {
  2822. composer.setLocaleMessage(locale, message);
  2823. },
  2824. // mergeLocaleMessage
  2825. mergeLocaleMessage(locale, message) {
  2826. composer.mergeLocaleMessage(locale, message);
  2827. },
  2828. // d
  2829. d(...args) {
  2830. return Reflect.apply(composer.d, composer, [...args]);
  2831. },
  2832. // getDateTimeFormat
  2833. getDateTimeFormat(locale) {
  2834. return composer.getDateTimeFormat(locale);
  2835. },
  2836. // setDateTimeFormat
  2837. setDateTimeFormat(locale, format) {
  2838. composer.setDateTimeFormat(locale, format);
  2839. },
  2840. // mergeDateTimeFormat
  2841. mergeDateTimeFormat(locale, format) {
  2842. composer.mergeDateTimeFormat(locale, format);
  2843. },
  2844. // n
  2845. n(...args) {
  2846. return Reflect.apply(composer.n, composer, [...args]);
  2847. },
  2848. // getNumberFormat
  2849. getNumberFormat(locale) {
  2850. return composer.getNumberFormat(locale);
  2851. },
  2852. // setNumberFormat
  2853. setNumberFormat(locale, format) {
  2854. composer.setNumberFormat(locale, format);
  2855. },
  2856. // mergeNumberFormat
  2857. mergeNumberFormat(locale, format) {
  2858. composer.mergeNumberFormat(locale, format);
  2859. },
  2860. // getChoiceIndex
  2861. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  2862. getChoiceIndex(choice, choicesLength) {
  2863. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX));
  2864. return -1;
  2865. },
  2866. // for internal
  2867. __onComponentInstanceCreated(target) {
  2868. const { componentInstanceCreatedListener } = options;
  2869. if (componentInstanceCreatedListener) {
  2870. componentInstanceCreatedListener(target, vueI18n);
  2871. }
  2872. }
  2873. };
  2874. // for vue-devtools timeline event
  2875. {
  2876. vueI18n.__enableEmitter = (emitter) => {
  2877. const __composer = composer;
  2878. __composer[EnableEmitter] && __composer[EnableEmitter](emitter);
  2879. };
  2880. vueI18n.__disableEmitter = () => {
  2881. const __composer = composer;
  2882. __composer[DisableEmitter] && __composer[DisableEmitter]();
  2883. };
  2884. }
  2885. return vueI18n;
  2886. }
  2887. }
  2888. /* eslint-enable @typescript-eslint/no-explicit-any */
  2889. const baseFormatProps = {
  2890. tag: {
  2891. type: [String, Object]
  2892. },
  2893. locale: {
  2894. type: String
  2895. },
  2896. scope: {
  2897. type: String,
  2898. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  2899. validator: (val /* ComponetI18nScope */) => val === 'parent' || val === 'global',
  2900. default: 'parent' /* ComponetI18nScope */
  2901. },
  2902. i18n: {
  2903. type: Object
  2904. }
  2905. };
  2906. function getInterpolateArg(
  2907. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2908. { slots }, // SetupContext,
  2909. keys) {
  2910. if (keys.length === 1 && keys[0] === 'default') {
  2911. // default slot with list
  2912. const ret = slots.default ? slots.default() : [];
  2913. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2914. return ret.reduce((slot, current) => {
  2915. return (slot = [
  2916. ...slot,
  2917. ...(isArray(current.children) ? current.children : [current])
  2918. ]);
  2919. }, []);
  2920. }
  2921. else {
  2922. // named slots
  2923. return keys.reduce((arg, key) => {
  2924. const slot = slots[key];
  2925. if (slot) {
  2926. arg[key] = slot();
  2927. }
  2928. return arg;
  2929. }, {});
  2930. }
  2931. }
  2932. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2933. function getFragmentableTag(tag) {
  2934. return Fragment ;
  2935. }
  2936. /**
  2937. * Translation Component
  2938. *
  2939. * @remarks
  2940. * See the following items for property about details
  2941. *
  2942. * @VueI18nSee [TranslationProps](component#translationprops)
  2943. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  2944. * @VueI18nSee [Component Interpolation](../guide/advanced/component)
  2945. *
  2946. * @example
  2947. * ```html
  2948. * <div id="app">
  2949. * <!-- ... -->
  2950. * <i18n path="term" tag="label" for="tos">
  2951. * <a :href="url" target="_blank">{{ $t('tos') }}</a>
  2952. * </i18n>
  2953. * <!-- ... -->
  2954. * </div>
  2955. * ```
  2956. * ```js
  2957. * import { createApp } from 'vue'
  2958. * import { createI18n } from 'vue-i18n'
  2959. *
  2960. * const messages = {
  2961. * en: {
  2962. * tos: 'Term of Service',
  2963. * term: 'I accept xxx {0}.'
  2964. * },
  2965. * ja: {
  2966. * tos: '利用規約',
  2967. * term: '私は xxx の{0}に同意します。'
  2968. * }
  2969. * }
  2970. *
  2971. * const i18n = createI18n({
  2972. * locale: 'en',
  2973. * messages
  2974. * })
  2975. *
  2976. * const app = createApp({
  2977. * data: {
  2978. * url: '/term'
  2979. * }
  2980. * }).use(i18n).mount('#app')
  2981. * ```
  2982. *
  2983. * @VueI18nComponent
  2984. */
  2985. const Translation = /* defineComponent */ {
  2986. /* eslint-disable */
  2987. name: 'i18n-t',
  2988. props: assign({
  2989. keypath: {
  2990. type: String,
  2991. required: true
  2992. },
  2993. plural: {
  2994. type: [Number, String],
  2995. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2996. validator: (val) => isNumber(val) || !isNaN(val)
  2997. }
  2998. }, baseFormatProps),
  2999. /* eslint-enable */
  3000. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3001. setup(props, context) {
  3002. const { slots, attrs } = context;
  3003. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  3004. const i18n = props.i18n ||
  3005. useI18n({
  3006. useScope: props.scope,
  3007. __useComponent: true
  3008. });
  3009. return () => {
  3010. const keys = Object.keys(slots).filter(key => key !== '_');
  3011. const options = {};
  3012. if (props.locale) {
  3013. options.locale = props.locale;
  3014. }
  3015. if (props.plural !== undefined) {
  3016. options.plural = isString(props.plural) ? +props.plural : props.plural;
  3017. }
  3018. const arg = getInterpolateArg(context, keys);
  3019. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3020. const children = i18n[TransrateVNodeSymbol](props.keypath, arg, options);
  3021. const assignedAttrs = assign({}, attrs);
  3022. const tag = isString(props.tag) || isObject(props.tag)
  3023. ? props.tag
  3024. : getFragmentableTag();
  3025. return h(tag, assignedAttrs, children);
  3026. };
  3027. }
  3028. };
  3029. function isVNode(target) {
  3030. return isArray(target) && !isString(target[0]);
  3031. }
  3032. function renderFormatter(props, context, slotKeys, partFormatter) {
  3033. const { slots, attrs } = context;
  3034. return () => {
  3035. const options = { part: true };
  3036. let overrides = {};
  3037. if (props.locale) {
  3038. options.locale = props.locale;
  3039. }
  3040. if (isString(props.format)) {
  3041. options.key = props.format;
  3042. }
  3043. else if (isObject(props.format)) {
  3044. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3045. if (isString(props.format.key)) {
  3046. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3047. options.key = props.format.key;
  3048. }
  3049. // Filter out number format options only
  3050. overrides = Object.keys(props.format).reduce((options, prop) => {
  3051. return slotKeys.includes(prop)
  3052. ? assign({}, options, { [prop]: props.format[prop] }) // eslint-disable-line @typescript-eslint/no-explicit-any
  3053. : options;
  3054. }, {});
  3055. }
  3056. const parts = partFormatter(...[props.value, options, overrides]);
  3057. let children = [options.key];
  3058. if (isArray(parts)) {
  3059. children = parts.map((part, index) => {
  3060. const slot = slots[part.type];
  3061. const node = slot
  3062. ? slot({ [part.type]: part.value, index, parts })
  3063. : [part.value];
  3064. if (isVNode(node)) {
  3065. node[0].key = `${part.type}-${index}`;
  3066. }
  3067. return node;
  3068. });
  3069. }
  3070. else if (isString(parts)) {
  3071. children = [parts];
  3072. }
  3073. const assignedAttrs = assign({}, attrs);
  3074. const tag = isString(props.tag) || isObject(props.tag)
  3075. ? props.tag
  3076. : getFragmentableTag();
  3077. return h(tag, assignedAttrs, children);
  3078. };
  3079. }
  3080. /**
  3081. * Number Format Component
  3082. *
  3083. * @remarks
  3084. * See the following items for property about details
  3085. *
  3086. * @VueI18nSee [FormattableProps](component#formattableprops)
  3087. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  3088. * @VueI18nSee [Custom Formatting](../guide/essentials/number#custom-formatting)
  3089. *
  3090. * @VueI18nDanger
  3091. * Not supported IE, due to no support `Intl.NumberFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
  3092. *
  3093. * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat)
  3094. *
  3095. * @VueI18nComponent
  3096. */
  3097. const NumberFormat = /* defineComponent */ {
  3098. /* eslint-disable */
  3099. name: 'i18n-n',
  3100. props: assign({
  3101. value: {
  3102. type: Number,
  3103. required: true
  3104. },
  3105. format: {
  3106. type: [String, Object]
  3107. }
  3108. }, baseFormatProps),
  3109. /* eslint-enable */
  3110. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3111. setup(props, context) {
  3112. const i18n = props.i18n ||
  3113. useI18n({ useScope: 'parent', __useComponent: true });
  3114. return renderFormatter(props, context, NUMBER_FORMAT_OPTIONS_KEYS, (...args) =>
  3115. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3116. i18n[NumberPartsSymbol](...args));
  3117. }
  3118. };
  3119. /**
  3120. * Datetime Format Component
  3121. *
  3122. * @remarks
  3123. * See the following items for property about details
  3124. *
  3125. * @VueI18nSee [FormattableProps](component#formattableprops)
  3126. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  3127. * @VueI18nSee [Custom Formatting](../guide/essentials/datetime#custom-formatting)
  3128. *
  3129. * @VueI18nDanger
  3130. * Not supported IE, due to no support `Intl.DateTimeFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
  3131. *
  3132. * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
  3133. *
  3134. * @VueI18nComponent
  3135. */
  3136. const DatetimeFormat = /*defineComponent */ {
  3137. /* eslint-disable */
  3138. name: 'i18n-d',
  3139. props: assign({
  3140. value: {
  3141. type: [Number, Date],
  3142. required: true
  3143. },
  3144. format: {
  3145. type: [String, Object]
  3146. }
  3147. }, baseFormatProps),
  3148. /* eslint-enable */
  3149. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3150. setup(props, context) {
  3151. const i18n = props.i18n ||
  3152. useI18n({ useScope: 'parent', __useComponent: true });
  3153. return renderFormatter(props, context, DATETIME_FORMAT_OPTIONS_KEYS, (...args) =>
  3154. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3155. i18n[DatetimePartsSymbol](...args));
  3156. }
  3157. };
  3158. function getComposer$2(i18n, instance) {
  3159. const i18nInternal = i18n;
  3160. if (i18n.mode === 'composition') {
  3161. return (i18nInternal.__getInstance(instance) || i18n.global);
  3162. }
  3163. else {
  3164. const vueI18n = i18nInternal.__getInstance(instance);
  3165. return vueI18n != null
  3166. ? vueI18n.__composer
  3167. : i18n.global.__composer;
  3168. }
  3169. }
  3170. function vTDirective(i18n) {
  3171. const _process = (binding) => {
  3172. const { instance, modifiers, value } = binding;
  3173. /* istanbul ignore if */
  3174. if (!instance || !instance.$) {
  3175. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  3176. }
  3177. const composer = getComposer$2(i18n, instance.$);
  3178. if (modifiers.preserve) {
  3179. warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE));
  3180. }
  3181. const parsedValue = parseValue(value);
  3182. return [
  3183. Reflect.apply(composer.t, composer, [...makeParams(parsedValue)]),
  3184. composer
  3185. ];
  3186. };
  3187. const register = (el, binding) => {
  3188. const [textContent, composer] = _process(binding);
  3189. if (inBrowser && i18n.global === composer) {
  3190. // global scope only
  3191. el.__i18nWatcher = watch(composer.locale, () => {
  3192. binding.instance && binding.instance.$forceUpdate();
  3193. });
  3194. }
  3195. el.__composer = composer;
  3196. el.textContent = textContent;
  3197. };
  3198. const unregister = (el) => {
  3199. if (inBrowser && el.__i18nWatcher) {
  3200. el.__i18nWatcher();
  3201. el.__i18nWatcher = undefined;
  3202. delete el.__i18nWatcher;
  3203. }
  3204. if (el.__composer) {
  3205. el.__composer = undefined;
  3206. delete el.__composer;
  3207. }
  3208. };
  3209. const update = (el, { value }) => {
  3210. if (el.__composer) {
  3211. const composer = el.__composer;
  3212. const parsedValue = parseValue(value);
  3213. el.textContent = Reflect.apply(composer.t, composer, [
  3214. ...makeParams(parsedValue)
  3215. ]);
  3216. }
  3217. };
  3218. const getSSRProps = (binding) => {
  3219. const [textContent] = _process(binding);
  3220. return { textContent };
  3221. };
  3222. return {
  3223. created: register,
  3224. unmounted: unregister,
  3225. beforeUpdate: update,
  3226. getSSRProps
  3227. };
  3228. }
  3229. function parseValue(value) {
  3230. if (isString(value)) {
  3231. return { path: value };
  3232. }
  3233. else if (isPlainObject(value)) {
  3234. if (!('path' in value)) {
  3235. throw createI18nError(I18nErrorCodes.REQUIRED_VALUE, 'path');
  3236. }
  3237. return value;
  3238. }
  3239. else {
  3240. throw createI18nError(I18nErrorCodes.INVALID_VALUE);
  3241. }
  3242. }
  3243. function makeParams(value) {
  3244. const { path, locale, args, choice, plural } = value;
  3245. const options = {};
  3246. const named = args || {};
  3247. if (isString(locale)) {
  3248. options.locale = locale;
  3249. }
  3250. if (isNumber(choice)) {
  3251. options.plural = choice;
  3252. }
  3253. if (isNumber(plural)) {
  3254. options.plural = plural;
  3255. }
  3256. return [path, named, options];
  3257. }
  3258. function apply(app, i18n, ...options) {
  3259. const pluginOptions = isPlainObject(options[0])
  3260. ? options[0]
  3261. : {};
  3262. const useI18nComponentName = !!pluginOptions.useI18nComponentName;
  3263. const globalInstall = isBoolean(pluginOptions.globalInstall)
  3264. ? pluginOptions.globalInstall
  3265. : true;
  3266. if (globalInstall && useI18nComponentName) {
  3267. warn(getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
  3268. name: Translation.name
  3269. }));
  3270. }
  3271. if (globalInstall) {
  3272. // install components
  3273. app.component(!useI18nComponentName ? Translation.name : 'i18n', Translation);
  3274. app.component(NumberFormat.name, NumberFormat);
  3275. app.component(DatetimeFormat.name, DatetimeFormat);
  3276. }
  3277. // install directive
  3278. {
  3279. app.directive('t', vTDirective(i18n));
  3280. }
  3281. }
  3282. var global$1 = (typeof global !== "undefined" ? global :
  3283. typeof self !== "undefined" ? self :
  3284. typeof window !== "undefined" ? window : {});
  3285. function getDevtoolsGlobalHook() {
  3286. return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
  3287. }
  3288. function getTarget() {
  3289. // @ts-ignore
  3290. return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
  3291. ? window
  3292. : typeof global$1 !== 'undefined'
  3293. ? global$1
  3294. : {};
  3295. }
  3296. const isProxyAvailable = typeof Proxy === 'function';
  3297. const HOOK_SETUP = 'devtools-plugin:setup';
  3298. const HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
  3299. let supported;
  3300. let perf;
  3301. function isPerformanceSupported() {
  3302. var _a;
  3303. if (supported !== undefined) {
  3304. return supported;
  3305. }
  3306. if (typeof window !== 'undefined' && window.performance) {
  3307. supported = true;
  3308. perf = window.performance;
  3309. }
  3310. else if (typeof global$1 !== 'undefined' && ((_a = global$1.perf_hooks) === null || _a === void 0 ? void 0 : _a.performance)) {
  3311. supported = true;
  3312. perf = global$1.perf_hooks.performance;
  3313. }
  3314. else {
  3315. supported = false;
  3316. }
  3317. return supported;
  3318. }
  3319. function now() {
  3320. return isPerformanceSupported() ? perf.now() : Date.now();
  3321. }
  3322. class ApiProxy {
  3323. constructor(plugin, hook) {
  3324. this.target = null;
  3325. this.targetQueue = [];
  3326. this.onQueue = [];
  3327. this.plugin = plugin;
  3328. this.hook = hook;
  3329. const defaultSettings = {};
  3330. if (plugin.settings) {
  3331. for (const id in plugin.settings) {
  3332. const item = plugin.settings[id];
  3333. defaultSettings[id] = item.defaultValue;
  3334. }
  3335. }
  3336. const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
  3337. let currentSettings = Object.assign({}, defaultSettings);
  3338. try {
  3339. const raw = localStorage.getItem(localSettingsSaveId);
  3340. const data = JSON.parse(raw);
  3341. Object.assign(currentSettings, data);
  3342. }
  3343. catch (e) {
  3344. // noop
  3345. }
  3346. this.fallbacks = {
  3347. getSettings() {
  3348. return currentSettings;
  3349. },
  3350. setSettings(value) {
  3351. try {
  3352. localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
  3353. }
  3354. catch (e) {
  3355. // noop
  3356. }
  3357. currentSettings = value;
  3358. },
  3359. now() {
  3360. return now();
  3361. },
  3362. };
  3363. if (hook) {
  3364. hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
  3365. if (pluginId === this.plugin.id) {
  3366. this.fallbacks.setSettings(value);
  3367. }
  3368. });
  3369. }
  3370. this.proxiedOn = new Proxy({}, {
  3371. get: (_target, prop) => {
  3372. if (this.target) {
  3373. return this.target.on[prop];
  3374. }
  3375. else {
  3376. return (...args) => {
  3377. this.onQueue.push({
  3378. method: prop,
  3379. args,
  3380. });
  3381. };
  3382. }
  3383. },
  3384. });
  3385. this.proxiedTarget = new Proxy({}, {
  3386. get: (_target, prop) => {
  3387. if (this.target) {
  3388. return this.target[prop];
  3389. }
  3390. else if (prop === 'on') {
  3391. return this.proxiedOn;
  3392. }
  3393. else if (Object.keys(this.fallbacks).includes(prop)) {
  3394. return (...args) => {
  3395. this.targetQueue.push({
  3396. method: prop,
  3397. args,
  3398. resolve: () => { },
  3399. });
  3400. return this.fallbacks[prop](...args);
  3401. };
  3402. }
  3403. else {
  3404. return (...args) => {
  3405. return new Promise(resolve => {
  3406. this.targetQueue.push({
  3407. method: prop,
  3408. args,
  3409. resolve,
  3410. });
  3411. });
  3412. };
  3413. }
  3414. },
  3415. });
  3416. }
  3417. async setRealTarget(target) {
  3418. this.target = target;
  3419. for (const item of this.onQueue) {
  3420. this.target.on[item.method](...item.args);
  3421. }
  3422. for (const item of this.targetQueue) {
  3423. item.resolve(await this.target[item.method](...item.args));
  3424. }
  3425. }
  3426. }
  3427. function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
  3428. const descriptor = pluginDescriptor;
  3429. const target = getTarget();
  3430. const hook = getDevtoolsGlobalHook();
  3431. const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy;
  3432. if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
  3433. hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
  3434. }
  3435. else {
  3436. const proxy = enableProxy ? new ApiProxy(descriptor, hook) : null;
  3437. const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
  3438. list.push({
  3439. pluginDescriptor: descriptor,
  3440. setupFn,
  3441. proxy,
  3442. });
  3443. if (proxy)
  3444. setupFn(proxy.proxiedTarget);
  3445. }
  3446. }
  3447. const VueDevToolsLabels = {
  3448. ["vue-devtools-plugin-vue-i18n" /* PLUGIN */]: 'Vue I18n devtools',
  3449. ["vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */]: 'I18n Resources',
  3450. ["vue-i18n-timeline" /* TIMELINE */]: 'Vue I18n'
  3451. };
  3452. const VueDevToolsPlaceholders = {
  3453. ["vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */]: 'Search for scopes ...'
  3454. };
  3455. const VueDevToolsTimelineColors = {
  3456. ["vue-i18n-timeline" /* TIMELINE */]: 0xffcd19
  3457. };
  3458. const VUE_I18N_COMPONENT_TYPES = 'vue-i18n: composer properties';
  3459. let devtoolsApi;
  3460. async function enableDevTools(app, i18n) {
  3461. return new Promise((resolve, reject) => {
  3462. try {
  3463. setupDevtoolsPlugin({
  3464. id: "vue-devtools-plugin-vue-i18n" /* PLUGIN */,
  3465. label: VueDevToolsLabels["vue-devtools-plugin-vue-i18n" /* PLUGIN */],
  3466. packageName: 'vue-i18n',
  3467. homepage: 'https://vue-i18n.intlify.dev',
  3468. logo: 'https://vue-i18n.intlify.dev/vue-i18n-devtools-logo.png',
  3469. componentStateTypes: [VUE_I18N_COMPONENT_TYPES],
  3470. app: app // eslint-disable-line @typescript-eslint/no-explicit-any
  3471. }, api => {
  3472. devtoolsApi = api;
  3473. api.on.visitComponentTree(({ componentInstance, treeNode }) => {
  3474. updateComponentTreeTags(componentInstance, treeNode, i18n);
  3475. });
  3476. api.on.inspectComponent(({ componentInstance, instanceData }) => {
  3477. if (componentInstance.vnode.el &&
  3478. componentInstance.vnode.el.__VUE_I18N__ &&
  3479. instanceData) {
  3480. if (i18n.mode === 'legacy') {
  3481. // ignore global scope on legacy mode
  3482. if (componentInstance.vnode.el.__VUE_I18N__ !==
  3483. i18n.global.__composer) {
  3484. inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
  3485. }
  3486. }
  3487. else {
  3488. inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
  3489. }
  3490. }
  3491. });
  3492. api.addInspector({
  3493. id: "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */,
  3494. label: VueDevToolsLabels["vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */],
  3495. icon: 'language',
  3496. treeFilterPlaceholder: VueDevToolsPlaceholders["vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */]
  3497. });
  3498. api.on.getInspectorTree(payload => {
  3499. if (payload.app === app &&
  3500. payload.inspectorId === "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */) {
  3501. registerScope(payload, i18n);
  3502. }
  3503. });
  3504. const roots = new Map();
  3505. api.on.getInspectorState(async (payload) => {
  3506. if (payload.app === app &&
  3507. payload.inspectorId === "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */) {
  3508. api.unhighlightElement();
  3509. inspectScope(payload, i18n);
  3510. if (payload.nodeId === 'global') {
  3511. if (!roots.has(payload.app)) {
  3512. const [root] = await api.getComponentInstances(payload.app);
  3513. roots.set(payload.app, root);
  3514. }
  3515. api.highlightElement(roots.get(payload.app));
  3516. }
  3517. else {
  3518. const instance = getComponentInstance(payload.nodeId, i18n);
  3519. instance && api.highlightElement(instance);
  3520. }
  3521. }
  3522. });
  3523. api.on.editInspectorState(payload => {
  3524. if (payload.app === app &&
  3525. payload.inspectorId === "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */) {
  3526. editScope(payload, i18n);
  3527. }
  3528. });
  3529. api.addTimelineLayer({
  3530. id: "vue-i18n-timeline" /* TIMELINE */,
  3531. label: VueDevToolsLabels["vue-i18n-timeline" /* TIMELINE */],
  3532. color: VueDevToolsTimelineColors["vue-i18n-timeline" /* TIMELINE */]
  3533. });
  3534. resolve(true);
  3535. });
  3536. }
  3537. catch (e) {
  3538. console.error(e);
  3539. reject(false);
  3540. }
  3541. });
  3542. }
  3543. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3544. function getI18nScopeLable(instance) {
  3545. return (instance.type.name ||
  3546. instance.type.displayName ||
  3547. instance.type.__file ||
  3548. 'Anonymous');
  3549. }
  3550. function updateComponentTreeTags(instance, // eslint-disable-line @typescript-eslint/no-explicit-any
  3551. treeNode, i18n) {
  3552. // prettier-ignore
  3553. const global = i18n.mode === 'composition'
  3554. ? i18n.global
  3555. : i18n.global.__composer;
  3556. if (instance && instance.vnode.el && instance.vnode.el.__VUE_I18N__) {
  3557. // add custom tags local scope only
  3558. if (instance.vnode.el.__VUE_I18N__ !== global) {
  3559. const tag = {
  3560. label: `i18n (${getI18nScopeLable(instance)} Scope)`,
  3561. textColor: 0x000000,
  3562. backgroundColor: 0xffcd19
  3563. };
  3564. treeNode.tags.push(tag);
  3565. }
  3566. }
  3567. }
  3568. function inspectComposer(instanceData, composer) {
  3569. const type = VUE_I18N_COMPONENT_TYPES;
  3570. instanceData.state.push({
  3571. type,
  3572. key: 'locale',
  3573. editable: true,
  3574. value: composer.locale.value
  3575. });
  3576. instanceData.state.push({
  3577. type,
  3578. key: 'availableLocales',
  3579. editable: false,
  3580. value: composer.availableLocales
  3581. });
  3582. instanceData.state.push({
  3583. type,
  3584. key: 'fallbackLocale',
  3585. editable: true,
  3586. value: composer.fallbackLocale.value
  3587. });
  3588. instanceData.state.push({
  3589. type,
  3590. key: 'inheritLocale',
  3591. editable: true,
  3592. value: composer.inheritLocale
  3593. });
  3594. instanceData.state.push({
  3595. type,
  3596. key: 'messages',
  3597. editable: false,
  3598. value: getLocaleMessageValue(composer.messages.value)
  3599. });
  3600. {
  3601. instanceData.state.push({
  3602. type,
  3603. key: 'datetimeFormats',
  3604. editable: false,
  3605. value: composer.datetimeFormats.value
  3606. });
  3607. instanceData.state.push({
  3608. type,
  3609. key: 'numberFormats',
  3610. editable: false,
  3611. value: composer.numberFormats.value
  3612. });
  3613. }
  3614. }
  3615. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3616. function getLocaleMessageValue(messages) {
  3617. const value = {};
  3618. Object.keys(messages).forEach((key) => {
  3619. const v = messages[key];
  3620. if (isFunction(v) && 'source' in v) {
  3621. value[key] = getMessageFunctionDetails(v);
  3622. }
  3623. else if (isObject(v)) {
  3624. value[key] = getLocaleMessageValue(v);
  3625. }
  3626. else {
  3627. value[key] = v;
  3628. }
  3629. });
  3630. return value;
  3631. }
  3632. const ESC = {
  3633. '<': '&lt;',
  3634. '>': '&gt;',
  3635. '"': '&quot;',
  3636. '&': '&amp;'
  3637. };
  3638. function escape(s) {
  3639. return s.replace(/[<>"&]/g, escapeChar);
  3640. }
  3641. function escapeChar(a) {
  3642. return ESC[a] || a;
  3643. }
  3644. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3645. function getMessageFunctionDetails(func) {
  3646. const argString = func.source ? `("${escape(func.source)}")` : `(?)`;
  3647. return {
  3648. _custom: {
  3649. type: 'function',
  3650. display: `<span>ƒ</span> ${argString}`
  3651. }
  3652. };
  3653. }
  3654. function registerScope(payload, i18n) {
  3655. payload.rootNodes.push({
  3656. id: 'global',
  3657. label: 'Global Scope'
  3658. });
  3659. // prettier-ignore
  3660. const global = i18n.mode === 'composition'
  3661. ? i18n.global
  3662. : i18n.global.__composer;
  3663. for (const [keyInstance, instance] of i18n.__instances) {
  3664. // prettier-ignore
  3665. const composer = i18n.mode === 'composition'
  3666. ? instance
  3667. : instance.__composer;
  3668. if (global === composer) {
  3669. continue;
  3670. }
  3671. payload.rootNodes.push({
  3672. id: composer.id.toString(),
  3673. label: `${getI18nScopeLable(keyInstance)} Scope`
  3674. });
  3675. }
  3676. }
  3677. function getComponentInstance(nodeId, i18n) {
  3678. let instance = null;
  3679. if (nodeId !== 'global') {
  3680. for (const [component, composer] of i18n.__instances.entries()) {
  3681. if (composer.id.toString() === nodeId) {
  3682. instance = component;
  3683. break;
  3684. }
  3685. }
  3686. }
  3687. return instance;
  3688. }
  3689. function getComposer$1(nodeId, i18n) {
  3690. if (nodeId === 'global') {
  3691. return i18n.mode === 'composition'
  3692. ? i18n.global
  3693. : i18n.global.__composer;
  3694. }
  3695. else {
  3696. const instance = Array.from(i18n.__instances.values()).find(item => item.id.toString() === nodeId);
  3697. if (instance) {
  3698. return i18n.mode === 'composition'
  3699. ? instance
  3700. : instance.__composer;
  3701. }
  3702. else {
  3703. return null;
  3704. }
  3705. }
  3706. }
  3707. function inspectScope(payload, i18n
  3708. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3709. ) {
  3710. const composer = getComposer$1(payload.nodeId, i18n);
  3711. if (composer) {
  3712. // TODO:
  3713. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3714. payload.state = makeScopeInspectState(composer);
  3715. }
  3716. return null;
  3717. }
  3718. function makeScopeInspectState(composer) {
  3719. const state = {};
  3720. const localeType = 'Locale related info';
  3721. const localeStates = [
  3722. {
  3723. type: localeType,
  3724. key: 'locale',
  3725. editable: true,
  3726. value: composer.locale.value
  3727. },
  3728. {
  3729. type: localeType,
  3730. key: 'fallbackLocale',
  3731. editable: true,
  3732. value: composer.fallbackLocale.value
  3733. },
  3734. {
  3735. type: localeType,
  3736. key: 'availableLocales',
  3737. editable: false,
  3738. value: composer.availableLocales
  3739. },
  3740. {
  3741. type: localeType,
  3742. key: 'inheritLocale',
  3743. editable: true,
  3744. value: composer.inheritLocale
  3745. }
  3746. ];
  3747. state[localeType] = localeStates;
  3748. const localeMessagesType = 'Locale messages info';
  3749. const localeMessagesStates = [
  3750. {
  3751. type: localeMessagesType,
  3752. key: 'messages',
  3753. editable: false,
  3754. value: getLocaleMessageValue(composer.messages.value)
  3755. }
  3756. ];
  3757. state[localeMessagesType] = localeMessagesStates;
  3758. {
  3759. const datetimeFormatsType = 'Datetime formats info';
  3760. const datetimeFormatsStates = [
  3761. {
  3762. type: datetimeFormatsType,
  3763. key: 'datetimeFormats',
  3764. editable: false,
  3765. value: composer.datetimeFormats.value
  3766. }
  3767. ];
  3768. state[datetimeFormatsType] = datetimeFormatsStates;
  3769. const numberFormatsType = 'Datetime formats info';
  3770. const numberFormatsStates = [
  3771. {
  3772. type: numberFormatsType,
  3773. key: 'numberFormats',
  3774. editable: false,
  3775. value: composer.numberFormats.value
  3776. }
  3777. ];
  3778. state[numberFormatsType] = numberFormatsStates;
  3779. }
  3780. return state;
  3781. }
  3782. function addTimelineEvent(event, payload) {
  3783. if (devtoolsApi) {
  3784. let groupId;
  3785. if (payload && 'groupId' in payload) {
  3786. groupId = payload.groupId;
  3787. delete payload.groupId;
  3788. }
  3789. devtoolsApi.addTimelineEvent({
  3790. layerId: "vue-i18n-timeline" /* TIMELINE */,
  3791. event: {
  3792. title: event,
  3793. groupId,
  3794. time: Date.now(),
  3795. meta: {},
  3796. data: payload || {},
  3797. logType: event === "compile-error" /* COMPILE_ERROR */
  3798. ? 'error'
  3799. : event === "fallback" /* FALBACK */ ||
  3800. event === "missing" /* MISSING */
  3801. ? 'warning'
  3802. : 'default'
  3803. }
  3804. });
  3805. }
  3806. }
  3807. function editScope(payload, i18n) {
  3808. const composer = getComposer$1(payload.nodeId, i18n);
  3809. if (composer) {
  3810. const [field] = payload.path;
  3811. if (field === 'locale' && isString(payload.state.value)) {
  3812. composer.locale.value = payload.state.value;
  3813. }
  3814. else if (field === 'fallbackLocale' &&
  3815. (isString(payload.state.value) ||
  3816. isArray(payload.state.value) ||
  3817. isObject(payload.state.value))) {
  3818. composer.fallbackLocale.value = payload.state.value;
  3819. }
  3820. else if (field === 'inheritLocale' && isBoolean(payload.state.value)) {
  3821. composer.inheritLocale = payload.state.value;
  3822. }
  3823. }
  3824. }
  3825. /**
  3826. * Supports compatibility for legacy vue-i18n APIs
  3827. * This mixin is used when we use vue-i18n@v9.x or later
  3828. */
  3829. function defineMixin(vuei18n, composer, i18n) {
  3830. return {
  3831. beforeCreate() {
  3832. const instance = getCurrentInstance();
  3833. /* istanbul ignore if */
  3834. if (!instance) {
  3835. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  3836. }
  3837. const options = this.$options;
  3838. if (options.i18n) {
  3839. const optionsI18n = options.i18n;
  3840. if (options.__i18n) {
  3841. optionsI18n.__i18n = options.__i18n;
  3842. }
  3843. optionsI18n.__root = composer;
  3844. if (this === this.$root) {
  3845. this.$i18n = mergeToRoot(vuei18n, optionsI18n);
  3846. }
  3847. else {
  3848. optionsI18n.__injectWithOption = true;
  3849. this.$i18n = createVueI18n(optionsI18n);
  3850. }
  3851. }
  3852. else if (options.__i18n) {
  3853. if (this === this.$root) {
  3854. this.$i18n = mergeToRoot(vuei18n, options);
  3855. }
  3856. else {
  3857. this.$i18n = createVueI18n({
  3858. __i18n: options.__i18n,
  3859. __injectWithOption: true,
  3860. __root: composer
  3861. });
  3862. }
  3863. }
  3864. else {
  3865. // set global
  3866. this.$i18n = vuei18n;
  3867. }
  3868. if (options.__i18nGlobal) {
  3869. adjustI18nResources(composer, options, options);
  3870. }
  3871. vuei18n.__onComponentInstanceCreated(this.$i18n);
  3872. i18n.__setInstance(instance, this.$i18n);
  3873. // defines vue-i18n legacy APIs
  3874. this.$t = (...args) => this.$i18n.t(...args);
  3875. this.$rt = (...args) => this.$i18n.rt(...args);
  3876. this.$tc = (...args) => this.$i18n.tc(...args);
  3877. this.$te = (key, locale) => this.$i18n.te(key, locale);
  3878. this.$d = (...args) => this.$i18n.d(...args);
  3879. this.$n = (...args) => this.$i18n.n(...args);
  3880. this.$tm = (key) => this.$i18n.tm(key);
  3881. },
  3882. mounted() {
  3883. /* istanbul ignore if */
  3884. if (this.$el &&
  3885. this.$i18n) {
  3886. this.$el.__VUE_I18N__ = this.$i18n.__composer;
  3887. const emitter = (this.__v_emitter =
  3888. createEmitter());
  3889. const _vueI18n = this.$i18n;
  3890. _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
  3891. emitter.on('*', addTimelineEvent);
  3892. }
  3893. },
  3894. unmounted() {
  3895. const instance = getCurrentInstance();
  3896. /* istanbul ignore if */
  3897. if (!instance) {
  3898. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  3899. }
  3900. /* istanbul ignore if */
  3901. if (this.$el &&
  3902. this.$el.__VUE_I18N__) {
  3903. if (this.__v_emitter) {
  3904. this.__v_emitter.off('*', addTimelineEvent);
  3905. delete this.__v_emitter;
  3906. }
  3907. if (this.$i18n) {
  3908. const _vueI18n = this.$i18n;
  3909. _vueI18n.__disableEmitter && _vueI18n.__disableEmitter();
  3910. delete this.$el.__VUE_I18N__;
  3911. }
  3912. }
  3913. delete this.$t;
  3914. delete this.$rt;
  3915. delete this.$tc;
  3916. delete this.$te;
  3917. delete this.$d;
  3918. delete this.$n;
  3919. delete this.$tm;
  3920. i18n.__deleteInstance(instance);
  3921. delete this.$i18n;
  3922. }
  3923. };
  3924. }
  3925. function mergeToRoot(root, options) {
  3926. root.locale = options.locale || root.locale;
  3927. root.fallbackLocale = options.fallbackLocale || root.fallbackLocale;
  3928. root.missing = options.missing || root.missing;
  3929. root.silentTranslationWarn =
  3930. options.silentTranslationWarn || root.silentFallbackWarn;
  3931. root.silentFallbackWarn =
  3932. options.silentFallbackWarn || root.silentFallbackWarn;
  3933. root.formatFallbackMessages =
  3934. options.formatFallbackMessages || root.formatFallbackMessages;
  3935. root.postTranslation = options.postTranslation || root.postTranslation;
  3936. root.warnHtmlInMessage = options.warnHtmlInMessage || root.warnHtmlInMessage;
  3937. root.escapeParameterHtml =
  3938. options.escapeParameterHtml || root.escapeParameterHtml;
  3939. root.sync = options.sync || root.sync;
  3940. root.__composer[SetPluralRulesSymbol](options.pluralizationRules || root.pluralizationRules);
  3941. const messages = getLocaleMessages(root.locale, {
  3942. messages: options.messages,
  3943. __i18n: options.__i18n
  3944. });
  3945. Object.keys(messages).forEach(locale => root.mergeLocaleMessage(locale, messages[locale]));
  3946. if (options.datetimeFormats) {
  3947. Object.keys(options.datetimeFormats).forEach(locale => root.mergeDateTimeFormat(locale, options.datetimeFormats[locale]));
  3948. }
  3949. if (options.numberFormats) {
  3950. Object.keys(options.numberFormats).forEach(locale => root.mergeNumberFormat(locale, options.numberFormats[locale]));
  3951. }
  3952. return root;
  3953. }
  3954. /**
  3955. * Injection key for {@link useI18n}
  3956. *
  3957. * @remarks
  3958. * The global injection key for I18n instances with `useI18n`. this injection key is used in Web Components.
  3959. * Specify the i18n instance created by {@link createI18n} together with `provide` function.
  3960. *
  3961. * @VueI18nGeneral
  3962. */
  3963. const I18nInjectionKey =
  3964. /* #__PURE__*/ makeSymbol('global-vue-i18n');
  3965. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
  3966. function createI18n(options = {}, VueI18nLegacy) {
  3967. // prettier-ignore
  3968. const __legacyMode = isBoolean(options.legacy)
  3969. ? options.legacy
  3970. : true;
  3971. // prettier-ignore
  3972. const __globalInjection = isBoolean(options.globalInjection)
  3973. ? options.globalInjection
  3974. : true;
  3975. // prettier-ignore
  3976. const __allowComposition = __legacyMode
  3977. ? !!options.allowComposition
  3978. : true;
  3979. const __instances = new Map();
  3980. const [globalScope, __global] = createGlobal(options, __legacyMode);
  3981. const symbol = makeSymbol('vue-i18n' );
  3982. function __getInstance(component) {
  3983. return __instances.get(component) || null;
  3984. }
  3985. function __setInstance(component, instance) {
  3986. __instances.set(component, instance);
  3987. }
  3988. function __deleteInstance(component) {
  3989. __instances.delete(component);
  3990. }
  3991. {
  3992. const i18n = {
  3993. // mode
  3994. get mode() {
  3995. return __legacyMode
  3996. ? 'legacy'
  3997. : 'composition';
  3998. },
  3999. // allowComposition
  4000. get allowComposition() {
  4001. return __allowComposition;
  4002. },
  4003. // install plugin
  4004. async install(app, ...options) {
  4005. {
  4006. app.__VUE_I18N__ = i18n;
  4007. }
  4008. // setup global provider
  4009. app.__VUE_I18N_SYMBOL__ = symbol;
  4010. app.provide(app.__VUE_I18N_SYMBOL__, i18n);
  4011. // global method and properties injection for Composition API
  4012. if (!__legacyMode && __globalInjection) {
  4013. injectGlobalFields(app, i18n.global);
  4014. }
  4015. // install built-in components and directive
  4016. {
  4017. apply(app, i18n, ...options);
  4018. }
  4019. // setup mixin for Legacy API
  4020. if (__legacyMode) {
  4021. app.mixin(defineMixin(__global, __global.__composer, i18n));
  4022. }
  4023. // release global scope
  4024. const unmountApp = app.unmount;
  4025. app.unmount = () => {
  4026. i18n.dispose();
  4027. unmountApp();
  4028. };
  4029. // setup vue-devtools plugin
  4030. {
  4031. const ret = await enableDevTools(app, i18n);
  4032. if (!ret) {
  4033. throw createI18nError(I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN);
  4034. }
  4035. const emitter = createEmitter();
  4036. if (__legacyMode) {
  4037. const _vueI18n = __global;
  4038. _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
  4039. }
  4040. else {
  4041. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4042. const _composer = __global;
  4043. _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
  4044. }
  4045. emitter.on('*', addTimelineEvent);
  4046. }
  4047. },
  4048. // global accessor
  4049. get global() {
  4050. return __global;
  4051. },
  4052. dispose() {
  4053. globalScope.stop();
  4054. },
  4055. // @internal
  4056. __instances,
  4057. // @internal
  4058. __getInstance,
  4059. // @internal
  4060. __setInstance,
  4061. // @internal
  4062. __deleteInstance
  4063. };
  4064. return i18n;
  4065. }
  4066. }
  4067. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  4068. function useI18n(options = {}) {
  4069. const instance = getCurrentInstance();
  4070. if (instance == null) {
  4071. throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
  4072. }
  4073. if (!instance.isCE &&
  4074. instance.appContext.app != null &&
  4075. !instance.appContext.app.__VUE_I18N_SYMBOL__) {
  4076. throw createI18nError(I18nErrorCodes.NOT_INSLALLED);
  4077. }
  4078. const i18n = getI18nInstance(instance);
  4079. const global = getGlobalComposer(i18n);
  4080. const componentOptions = getComponentOptions(instance);
  4081. const scope = getScope(options, componentOptions);
  4082. {
  4083. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4084. if (i18n.mode === 'legacy' && !options.__useComponent) {
  4085. if (!i18n.allowComposition) {
  4086. throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
  4087. }
  4088. return useI18nForLegacy(instance, scope, global, options);
  4089. }
  4090. }
  4091. if (scope === 'global') {
  4092. adjustI18nResources(global, options, componentOptions);
  4093. return global;
  4094. }
  4095. if (scope === 'parent') {
  4096. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4097. let composer = getComposer(i18n, instance, options.__useComponent);
  4098. if (composer == null) {
  4099. {
  4100. warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
  4101. }
  4102. composer = global;
  4103. }
  4104. return composer;
  4105. }
  4106. const i18nInternal = i18n;
  4107. let composer = i18nInternal.__getInstance(instance);
  4108. if (composer == null) {
  4109. const composerOptions = assign({}, options);
  4110. if ('__i18n' in componentOptions) {
  4111. composerOptions.__i18n = componentOptions.__i18n;
  4112. }
  4113. if (global) {
  4114. composerOptions.__root = global;
  4115. }
  4116. composer = createComposer(composerOptions);
  4117. setupLifeCycle(i18nInternal, instance, composer);
  4118. i18nInternal.__setInstance(instance, composer);
  4119. }
  4120. return composer;
  4121. }
  4122. /**
  4123. * Cast to VueI18n legacy compatible type
  4124. *
  4125. * @remarks
  4126. * This API is provided only with [vue-i18n-bridge](https://vue-i18n.intlify.dev/guide/migration/ways.html#what-is-vue-i18n-bridge).
  4127. *
  4128. * The purpose of this function is to convert an {@link I18n} instance created with {@link createI18n | createI18n(legacy: true)} into a `vue-i18n@v8.x` compatible instance of `new VueI18n` in a TypeScript environment.
  4129. *
  4130. * @param i18n - An instance of {@link I18n}
  4131. * @returns A i18n instance which is casted to {@link VueI18n} type
  4132. *
  4133. * @VueI18nTip
  4134. * :new: provided by **vue-i18n-bridge only**
  4135. *
  4136. * @VueI18nGeneral
  4137. */
  4138. const castToVueI18n = (i18n
  4139. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4140. ) => {
  4141. if (!(__VUE_I18N_BRIDGE__ in i18n)) {
  4142. throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N);
  4143. }
  4144. return i18n;
  4145. };
  4146. function createGlobal(options, legacyMode, VueI18nLegacy // eslint-disable-line @typescript-eslint/no-explicit-any
  4147. ) {
  4148. const scope = effectScope();
  4149. {
  4150. const obj = legacyMode
  4151. ? scope.run(() => createVueI18n(options))
  4152. : scope.run(() => createComposer(options));
  4153. if (obj == null) {
  4154. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  4155. }
  4156. return [scope, obj];
  4157. }
  4158. }
  4159. function getI18nInstance(instance) {
  4160. {
  4161. const i18n = inject(!instance.isCE
  4162. ? instance.appContext.app.__VUE_I18N_SYMBOL__
  4163. : I18nInjectionKey);
  4164. /* istanbul ignore if */
  4165. if (!i18n) {
  4166. throw createI18nError(!instance.isCE
  4167. ? I18nErrorCodes.UNEXPECTED_ERROR
  4168. : I18nErrorCodes.NOT_INSLALLED_WITH_PROVIDE);
  4169. }
  4170. return i18n;
  4171. }
  4172. }
  4173. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4174. function getScope(options, componentOptions) {
  4175. // prettier-ignore
  4176. return isEmptyObject(options)
  4177. ? ('__i18n' in componentOptions)
  4178. ? 'local'
  4179. : 'global'
  4180. : !options.useScope
  4181. ? 'local'
  4182. : options.useScope;
  4183. }
  4184. function getGlobalComposer(i18n) {
  4185. // prettier-ignore
  4186. return i18n.mode === 'composition'
  4187. ? i18n.global
  4188. : i18n.global.__composer
  4189. ;
  4190. }
  4191. function getComposer(i18n, target, useComponent = false) {
  4192. let composer = null;
  4193. const root = target.root;
  4194. let current = target.parent;
  4195. while (current != null) {
  4196. const i18nInternal = i18n;
  4197. if (i18n.mode === 'composition') {
  4198. composer = i18nInternal.__getInstance(current);
  4199. }
  4200. else {
  4201. {
  4202. const vueI18n = i18nInternal.__getInstance(current);
  4203. if (vueI18n != null) {
  4204. composer = vueI18n
  4205. .__composer;
  4206. if (useComponent &&
  4207. composer &&
  4208. !composer[InejctWithOption] // eslint-disable-line @typescript-eslint/no-explicit-any
  4209. ) {
  4210. composer = null;
  4211. }
  4212. }
  4213. }
  4214. }
  4215. if (composer != null) {
  4216. break;
  4217. }
  4218. if (root === current) {
  4219. break;
  4220. }
  4221. current = current.parent;
  4222. }
  4223. return composer;
  4224. }
  4225. function setupLifeCycle(i18n, target, composer) {
  4226. let emitter = null;
  4227. {
  4228. onMounted(() => {
  4229. // inject composer instance to DOM for intlify-devtools
  4230. if (target.vnode.el) {
  4231. target.vnode.el.__VUE_I18N__ = composer;
  4232. emitter = createEmitter();
  4233. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4234. const _composer = composer;
  4235. _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
  4236. emitter.on('*', addTimelineEvent);
  4237. }
  4238. }, target);
  4239. onUnmounted(() => {
  4240. // remove composer instance from DOM for intlify-devtools
  4241. if (target.vnode.el &&
  4242. target.vnode.el.__VUE_I18N__) {
  4243. emitter && emitter.off('*', addTimelineEvent);
  4244. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4245. const _composer = composer;
  4246. _composer[DisableEmitter] && _composer[DisableEmitter]();
  4247. delete target.vnode.el.__VUE_I18N__;
  4248. }
  4249. i18n.__deleteInstance(target);
  4250. }, target);
  4251. }
  4252. }
  4253. function useI18nForLegacy(instance, scope, root, options = {} // eslint-disable-line @typescript-eslint/no-explicit-any
  4254. ) {
  4255. const isLocale = scope === 'local';
  4256. const _composer = shallowRef(null);
  4257. if (isLocale &&
  4258. instance.proxy &&
  4259. !(instance.proxy.$options.i18n || instance.proxy.$options.__i18n)) {
  4260. throw createI18nError(I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION);
  4261. }
  4262. const _inheritLocale = isBoolean(options.inheritLocale)
  4263. ? options.inheritLocale
  4264. : true;
  4265. const _locale = ref(
  4266. // prettier-ignore
  4267. isLocale && _inheritLocale
  4268. ? root.locale.value
  4269. : isString(options.locale)
  4270. ? options.locale
  4271. : DEFAULT_LOCALE);
  4272. const _fallbackLocale = ref(
  4273. // prettier-ignore
  4274. isLocale && _inheritLocale
  4275. ? root.fallbackLocale.value
  4276. : isString(options.fallbackLocale) ||
  4277. isArray(options.fallbackLocale) ||
  4278. isPlainObject(options.fallbackLocale) ||
  4279. options.fallbackLocale === false
  4280. ? options.fallbackLocale
  4281. : _locale.value);
  4282. const _messages = ref(getLocaleMessages(_locale.value, options));
  4283. // prettier-ignore
  4284. const _datetimeFormats = ref(isPlainObject(options.datetimeFormats)
  4285. ? options.datetimeFormats
  4286. : { [_locale.value]: {} });
  4287. // prettier-ignore
  4288. const _numberFormats = ref(isPlainObject(options.numberFormats)
  4289. ? options.numberFormats
  4290. : { [_locale.value]: {} });
  4291. // prettier-ignore
  4292. const _missingWarn = isLocale
  4293. ? root.missingWarn
  4294. : isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
  4295. ? options.missingWarn
  4296. : true;
  4297. // prettier-ignore
  4298. const _fallbackWarn = isLocale
  4299. ? root.fallbackWarn
  4300. : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
  4301. ? options.fallbackWarn
  4302. : true;
  4303. // prettier-ignore
  4304. const _fallbackRoot = isLocale
  4305. ? root.fallbackRoot
  4306. : isBoolean(options.fallbackRoot)
  4307. ? options.fallbackRoot
  4308. : true;
  4309. // configure fall back to root
  4310. const _fallbackFormat = !!options.fallbackFormat;
  4311. // runtime missing
  4312. const _missing = isFunction(options.missing) ? options.missing : null;
  4313. // postTranslation handler
  4314. const _postTranslation = isFunction(options.postTranslation)
  4315. ? options.postTranslation
  4316. : null;
  4317. // prettier-ignore
  4318. const _warnHtmlMessage = isLocale
  4319. ? root.warnHtmlMessage
  4320. : isBoolean(options.warnHtmlMessage)
  4321. ? options.warnHtmlMessage
  4322. : true;
  4323. const _escapeParameter = !!options.escapeParameter;
  4324. // prettier-ignore
  4325. const _modifiers = isLocale
  4326. ? root.modifiers
  4327. : isPlainObject(options.modifiers)
  4328. ? options.modifiers
  4329. : {};
  4330. // pluralRules
  4331. const _pluralRules = options.pluralRules || (isLocale && root.pluralRules);
  4332. // track reactivity
  4333. function trackReactivityValues() {
  4334. return [
  4335. _locale.value,
  4336. _fallbackLocale.value,
  4337. _messages.value,
  4338. _datetimeFormats.value,
  4339. _numberFormats.value
  4340. ];
  4341. }
  4342. // locale
  4343. const locale = computed({
  4344. get: () => {
  4345. return _composer.value ? _composer.value.locale.value : _locale.value;
  4346. },
  4347. set: val => {
  4348. if (_composer.value) {
  4349. _composer.value.locale.value = val;
  4350. }
  4351. _locale.value = val;
  4352. }
  4353. });
  4354. // fallbackLocale
  4355. const fallbackLocale = computed({
  4356. get: () => {
  4357. return _composer.value
  4358. ? _composer.value.fallbackLocale.value
  4359. : _fallbackLocale.value;
  4360. },
  4361. set: val => {
  4362. if (_composer.value) {
  4363. _composer.value.fallbackLocale.value = val;
  4364. }
  4365. _fallbackLocale.value = val;
  4366. }
  4367. });
  4368. // messages
  4369. const messages = computed(() => {
  4370. if (_composer.value) {
  4371. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4372. return _composer.value.messages.value;
  4373. }
  4374. else {
  4375. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4376. return _messages.value;
  4377. }
  4378. });
  4379. const datetimeFormats = computed(() => _datetimeFormats.value);
  4380. const numberFormats = computed(() => _numberFormats.value);
  4381. function getPostTranslationHandler() {
  4382. return _composer.value
  4383. ? _composer.value.getPostTranslationHandler()
  4384. : _postTranslation;
  4385. }
  4386. function setPostTranslationHandler(handler) {
  4387. if (_composer.value) {
  4388. _composer.value.setPostTranslationHandler(handler);
  4389. }
  4390. }
  4391. function getMissingHandler() {
  4392. return _composer.value ? _composer.value.getMissingHandler() : _missing;
  4393. }
  4394. function setMissingHandler(handler) {
  4395. if (_composer.value) {
  4396. _composer.value.setMissingHandler(handler);
  4397. }
  4398. }
  4399. function warpWithDeps(fn) {
  4400. trackReactivityValues();
  4401. return fn();
  4402. }
  4403. function t(...args) {
  4404. return _composer.value
  4405. ? warpWithDeps(() => Reflect.apply(_composer.value.t, null, [...args]))
  4406. : warpWithDeps(() => '');
  4407. }
  4408. function rt(...args) {
  4409. return _composer.value
  4410. ? Reflect.apply(_composer.value.rt, null, [...args])
  4411. : '';
  4412. }
  4413. function d(...args) {
  4414. return _composer.value
  4415. ? warpWithDeps(() => Reflect.apply(_composer.value.d, null, [...args]))
  4416. : warpWithDeps(() => '');
  4417. }
  4418. function n(...args) {
  4419. return _composer.value
  4420. ? warpWithDeps(() => Reflect.apply(_composer.value.n, null, [...args]))
  4421. : warpWithDeps(() => '');
  4422. }
  4423. function tm(key) {
  4424. return _composer.value ? _composer.value.tm(key) : {};
  4425. }
  4426. function te(key, locale) {
  4427. return _composer.value ? _composer.value.te(key, locale) : false;
  4428. }
  4429. function getLocaleMessage(locale) {
  4430. return _composer.value ? _composer.value.getLocaleMessage(locale) : {};
  4431. }
  4432. function setLocaleMessage(locale, message) {
  4433. if (_composer.value) {
  4434. _composer.value.setLocaleMessage(locale, message);
  4435. _messages.value[locale] = message;
  4436. }
  4437. }
  4438. function mergeLocaleMessage(locale, message) {
  4439. if (_composer.value) {
  4440. _composer.value.mergeLocaleMessage(locale, message);
  4441. }
  4442. }
  4443. function getDateTimeFormat(locale) {
  4444. return _composer.value ? _composer.value.getDateTimeFormat(locale) : {};
  4445. }
  4446. function setDateTimeFormat(locale, format) {
  4447. if (_composer.value) {
  4448. _composer.value.setDateTimeFormat(locale, format);
  4449. _datetimeFormats.value[locale] = format;
  4450. }
  4451. }
  4452. function mergeDateTimeFormat(locale, format) {
  4453. if (_composer.value) {
  4454. _composer.value.mergeDateTimeFormat(locale, format);
  4455. }
  4456. }
  4457. function getNumberFormat(locale) {
  4458. return _composer.value ? _composer.value.getNumberFormat(locale) : {};
  4459. }
  4460. function setNumberFormat(locale, format) {
  4461. if (_composer.value) {
  4462. _composer.value.setNumberFormat(locale, format);
  4463. _numberFormats.value[locale] = format;
  4464. }
  4465. }
  4466. function mergeNumberFormat(locale, format) {
  4467. if (_composer.value) {
  4468. _composer.value.mergeNumberFormat(locale, format);
  4469. }
  4470. }
  4471. const wrapper = {
  4472. get id() {
  4473. return _composer.value ? _composer.value.id : -1;
  4474. },
  4475. locale,
  4476. fallbackLocale,
  4477. messages,
  4478. datetimeFormats,
  4479. numberFormats,
  4480. get inheritLocale() {
  4481. return _composer.value ? _composer.value.inheritLocale : _inheritLocale;
  4482. },
  4483. set inheritLocale(val) {
  4484. if (_composer.value) {
  4485. _composer.value.inheritLocale = val;
  4486. }
  4487. },
  4488. get availableLocales() {
  4489. return _composer.value
  4490. ? _composer.value.availableLocales
  4491. : Object.keys(_messages.value);
  4492. },
  4493. get modifiers() {
  4494. return (_composer.value ? _composer.value.modifiers : _modifiers);
  4495. },
  4496. get pluralRules() {
  4497. return (_composer.value ? _composer.value.pluralRules : _pluralRules);
  4498. },
  4499. get isGlobal() {
  4500. return _composer.value ? _composer.value.isGlobal : false;
  4501. },
  4502. get missingWarn() {
  4503. return _composer.value ? _composer.value.missingWarn : _missingWarn;
  4504. },
  4505. set missingWarn(val) {
  4506. if (_composer.value) {
  4507. _composer.value.missingWarn = val;
  4508. }
  4509. },
  4510. get fallbackWarn() {
  4511. return _composer.value ? _composer.value.fallbackWarn : _fallbackWarn;
  4512. },
  4513. set fallbackWarn(val) {
  4514. if (_composer.value) {
  4515. _composer.value.missingWarn = val;
  4516. }
  4517. },
  4518. get fallbackRoot() {
  4519. return _composer.value ? _composer.value.fallbackRoot : _fallbackRoot;
  4520. },
  4521. set fallbackRoot(val) {
  4522. if (_composer.value) {
  4523. _composer.value.fallbackRoot = val;
  4524. }
  4525. },
  4526. get fallbackFormat() {
  4527. return _composer.value ? _composer.value.fallbackFormat : _fallbackFormat;
  4528. },
  4529. set fallbackFormat(val) {
  4530. if (_composer.value) {
  4531. _composer.value.fallbackFormat = val;
  4532. }
  4533. },
  4534. get warnHtmlMessage() {
  4535. return _composer.value
  4536. ? _composer.value.warnHtmlMessage
  4537. : _warnHtmlMessage;
  4538. },
  4539. set warnHtmlMessage(val) {
  4540. if (_composer.value) {
  4541. _composer.value.warnHtmlMessage = val;
  4542. }
  4543. },
  4544. get escapeParameter() {
  4545. return _composer.value
  4546. ? _composer.value.escapeParameter
  4547. : _escapeParameter;
  4548. },
  4549. set escapeParameter(val) {
  4550. if (_composer.value) {
  4551. _composer.value.escapeParameter = val;
  4552. }
  4553. },
  4554. t,
  4555. getPostTranslationHandler,
  4556. setPostTranslationHandler,
  4557. getMissingHandler,
  4558. setMissingHandler,
  4559. rt,
  4560. d,
  4561. n,
  4562. tm,
  4563. te,
  4564. getLocaleMessage,
  4565. setLocaleMessage,
  4566. mergeLocaleMessage,
  4567. getDateTimeFormat,
  4568. setDateTimeFormat,
  4569. mergeDateTimeFormat,
  4570. getNumberFormat,
  4571. setNumberFormat,
  4572. mergeNumberFormat
  4573. };
  4574. function sync(composer) {
  4575. composer.locale.value = _locale.value;
  4576. composer.fallbackLocale.value = _fallbackLocale.value;
  4577. Object.keys(_messages.value).forEach(locale => {
  4578. composer.mergeLocaleMessage(locale, _messages.value[locale]);
  4579. });
  4580. Object.keys(_datetimeFormats.value).forEach(locale => {
  4581. composer.mergeDateTimeFormat(locale, _datetimeFormats.value[locale]);
  4582. });
  4583. Object.keys(_numberFormats.value).forEach(locale => {
  4584. composer.mergeNumberFormat(locale, _numberFormats.value[locale]);
  4585. });
  4586. composer.escapeParameter = _escapeParameter;
  4587. composer.fallbackFormat = _fallbackFormat;
  4588. composer.fallbackRoot = _fallbackRoot;
  4589. composer.fallbackWarn = _fallbackWarn;
  4590. composer.missingWarn = _missingWarn;
  4591. composer.warnHtmlMessage = _warnHtmlMessage;
  4592. }
  4593. onBeforeMount(() => {
  4594. if (instance.proxy == null || instance.proxy.$i18n == null) {
  4595. throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY);
  4596. }
  4597. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4598. const composer = (_composer.value = instance.proxy.$i18n
  4599. .__composer);
  4600. if (scope === 'global') {
  4601. _locale.value = composer.locale.value;
  4602. _fallbackLocale.value = composer.fallbackLocale.value;
  4603. _messages.value = composer.messages.value;
  4604. _datetimeFormats.value = composer.datetimeFormats.value;
  4605. _numberFormats.value = composer.numberFormats.value;
  4606. }
  4607. else if (isLocale) {
  4608. sync(composer);
  4609. }
  4610. });
  4611. return wrapper;
  4612. }
  4613. const globalExportProps = [
  4614. 'locale',
  4615. 'fallbackLocale',
  4616. 'availableLocales'
  4617. ];
  4618. const globalExportMethods = ['t', 'rt', 'd', 'n', 'tm'] ;
  4619. function injectGlobalFields(app, composer) {
  4620. const i18n = Object.create(null);
  4621. globalExportProps.forEach(prop => {
  4622. const desc = Object.getOwnPropertyDescriptor(composer, prop);
  4623. if (!desc) {
  4624. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  4625. }
  4626. const wrap = isRef(desc.value) // check computed props
  4627. ? {
  4628. get() {
  4629. return desc.value.value;
  4630. },
  4631. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4632. set(val) {
  4633. desc.value.value = val;
  4634. }
  4635. }
  4636. : {
  4637. get() {
  4638. return desc.get && desc.get();
  4639. }
  4640. };
  4641. Object.defineProperty(i18n, prop, wrap);
  4642. });
  4643. app.config.globalProperties.$i18n = i18n;
  4644. globalExportMethods.forEach(method => {
  4645. const desc = Object.getOwnPropertyDescriptor(composer, method);
  4646. if (!desc || !desc.value) {
  4647. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  4648. }
  4649. Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
  4650. });
  4651. }
  4652. // register message resolver at vue-i18n
  4653. registerMessageResolver(resolveValue);
  4654. // register fallback locale at vue-i18n
  4655. registerLocaleFallbacker(fallbackWithLocaleChain);
  4656. // NOTE: experimental !!
  4657. {
  4658. const target = getGlobalThis();
  4659. target.__INTLIFY__ = true;
  4660. setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
  4661. }
  4662. {
  4663. initDev();
  4664. }
  4665. export { DatetimeFormat, I18nInjectionKey, NumberFormat, Translation, VERSION, castToVueI18n, createI18n, useI18n, vTDirective };