vue-i18n.runtime.global.js 169 KB

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