vue-i18n.runtime.mjs 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411
  1. /*!
  2. * vue-i18n v11.1.3
  3. * (c) 2025 kazuya kawaguchi
  4. * Released under the MIT License.
  5. */
  6. import { CORE_ERROR_CODES_EXTEND_POINT, createCompileError, CORE_WARN_CODES_EXTEND_POINT, isMessageAST, AST_NODE_PROPS_KEYS, DEFAULT_LOCALE, updateFallbackLocale, setFallbackContext, createCoreContext, clearDateTimeFormat, clearNumberFormat, setAdditionalMeta, getFallbackContext, NOT_REOSLVED, isTranslateFallbackWarn, isTranslateMissingWarn, parseTranslateArgs, translate, MISSING_RESOLVE_VALUE, parseDateTimeArgs, datetime, parseNumberArgs, number, isMessageFunction, fallbackWithLocaleChain, NUMBER_FORMAT_OPTIONS_KEYS, DATETIME_FORMAT_OPTIONS_KEYS, registerMessageCompiler, compile, registerMessageResolver, resolveValue, registerLocaleFallbacker, setDevToolsHook } from '@intlify/core-base';
  7. import { getGlobalThis, makeSymbol, format, isObject, create, isPlainObject, isArray, deepCopy, isString, hasOwn, warn, isBoolean, isRegExp, isFunction, inBrowser, assign, isNumber, createEmitter, warnOnce, isEmptyObject } from '@intlify/shared';
  8. import { createVNode, Text, computed, watch, getCurrentInstance, ref, shallowRef, Fragment, defineComponent, h, effectScope, inject, onMounted, onUnmounted, isRef } from 'vue';
  9. import { setupDevtoolsPlugin } from '@vue/devtools-api';
  10. /**
  11. * Vue I18n Version
  12. *
  13. * @remarks
  14. * Semver format. Same format as the package.json `version` field.
  15. *
  16. * @VueI18nGeneral
  17. */
  18. const VERSION = '11.1.3';
  19. /**
  20. * This is only called in esm-bundler builds.
  21. * istanbul-ignore-next
  22. */
  23. function initFeatureFlags() {
  24. if (typeof __VUE_I18N_FULL_INSTALL__ !== 'boolean') {
  25. getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true;
  26. }
  27. if (typeof __VUE_I18N_LEGACY_API__ !== 'boolean') {
  28. getGlobalThis().__VUE_I18N_LEGACY_API__ = true;
  29. }
  30. if (typeof __INTLIFY_DROP_MESSAGE_COMPILER__ !== 'boolean') {
  31. getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false;
  32. }
  33. if (typeof __INTLIFY_PROD_DEVTOOLS__ !== 'boolean') {
  34. getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
  35. }
  36. }
  37. const I18nErrorCodes = {
  38. // composer module errors
  39. UNEXPECTED_RETURN_TYPE: CORE_ERROR_CODES_EXTEND_POINT, // 24
  40. // legacy module errors
  41. INVALID_ARGUMENT: 25,
  42. // i18n module errors
  43. MUST_BE_CALL_SETUP_TOP: 26,
  44. NOT_INSTALLED: 27,
  45. // directive module errors
  46. REQUIRED_VALUE: 28,
  47. INVALID_VALUE: 29,
  48. // vue-devtools errors
  49. CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: 30,
  50. NOT_INSTALLED_WITH_PROVIDE: 31,
  51. // unexpected error
  52. UNEXPECTED_ERROR: 32,
  53. // not compatible legacy vue-i18n constructor
  54. NOT_COMPATIBLE_LEGACY_VUE_I18N: 33,
  55. // Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
  56. NOT_AVAILABLE_COMPOSITION_IN_LEGACY: 34
  57. };
  58. function createI18nError(code, ...args) {
  59. return createCompileError(code, null, (process.env.NODE_ENV !== 'production') ? { messages: errorMessages, args } : undefined);
  60. }
  61. const errorMessages = {
  62. [I18nErrorCodes.UNEXPECTED_RETURN_TYPE]: 'Unexpected return type in composer',
  63. [I18nErrorCodes.INVALID_ARGUMENT]: 'Invalid argument',
  64. [I18nErrorCodes.MUST_BE_CALL_SETUP_TOP]: 'Must be called at the top of a `setup` function',
  65. [I18nErrorCodes.NOT_INSTALLED]: 'Need to install with `app.use` function',
  66. [I18nErrorCodes.UNEXPECTED_ERROR]: 'Unexpected error',
  67. [I18nErrorCodes.REQUIRED_VALUE]: `Required in value: {0}`,
  68. [I18nErrorCodes.INVALID_VALUE]: `Invalid value`,
  69. [I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
  70. [I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE]: 'Need to install with `provide` function',
  71. [I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: 'Not compatible legacy VueI18n.',
  72. [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'
  73. };
  74. const TranslateVNodeSymbol =
  75. /* #__PURE__*/ makeSymbol('__translateVNode');
  76. const DatetimePartsSymbol = /* #__PURE__*/ makeSymbol('__datetimeParts');
  77. const NumberPartsSymbol = /* #__PURE__*/ makeSymbol('__numberParts');
  78. const EnableEmitter = /* #__PURE__*/ makeSymbol('__enableEmitter');
  79. const DisableEmitter = /* #__PURE__*/ makeSymbol('__disableEmitter');
  80. const SetPluralRulesSymbol = makeSymbol('__setPluralRules');
  81. makeSymbol('__intlifyMeta');
  82. const InejctWithOptionSymbol =
  83. /* #__PURE__*/ makeSymbol('__injectWithOption');
  84. const DisposeSymbol = /* #__PURE__*/ makeSymbol('__dispose');
  85. const I18nWarnCodes = {
  86. FALLBACK_TO_ROOT: CORE_WARN_CODES_EXTEND_POINT, // 8
  87. NOT_FOUND_PARENT_SCOPE: 9,
  88. IGNORE_OBJ_FLATTEN: 10,
  89. /**
  90. * @deprecated will be removed at vue-i18n v12
  91. */
  92. DEPRECATE_LEGACY_MODE: 11,
  93. /**
  94. * @deprecated will be removed at vue-i18n v12
  95. */
  96. DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE: 12
  97. };
  98. const warnMessages = {
  99. [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
  100. [I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
  101. [I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`,
  102. /**
  103. * @deprecated will be removed at vue-i18n v12
  104. */
  105. [I18nWarnCodes.DEPRECATE_LEGACY_MODE]: `Legacy API mode has been deprecated in v11. Use Composition API mode instead.\nAbout how to use the Composition API mode, see https://vue-i18n.intlify.dev/guide/advanced/composition.html`,
  106. /**
  107. * @deprecated will be removed at vue-i18n v12
  108. */
  109. [I18nWarnCodes.DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE]: `'v-t' has been deprecated in v11. Use translate APIs ('t' or '$t') instead.`
  110. };
  111. function getWarnMessage(code, ...args) {
  112. return format(warnMessages[code], ...args);
  113. }
  114. /* eslint-disable @typescript-eslint/no-explicit-any */
  115. /**
  116. * Transform flat json in obj to normal json in obj
  117. */
  118. function handleFlatJson(obj) {
  119. // check obj
  120. if (!isObject(obj)) {
  121. return obj;
  122. }
  123. if (isMessageAST(obj)) {
  124. return obj;
  125. }
  126. for (const key in obj) {
  127. // check key
  128. if (!hasOwn(obj, key)) {
  129. continue;
  130. }
  131. // handle for normal json
  132. if (!key.includes('.')) {
  133. // recursive process value if value is also a object
  134. if (isObject(obj[key])) {
  135. handleFlatJson(obj[key]);
  136. }
  137. }
  138. // handle for flat json, transform to normal json
  139. else {
  140. // go to the last object
  141. const subKeys = key.split('.');
  142. const lastIndex = subKeys.length - 1;
  143. let currentObj = obj;
  144. let hasStringValue = false;
  145. for (let i = 0; i < lastIndex; i++) {
  146. if (subKeys[i] === '__proto__') {
  147. throw new Error(`unsafe key: ${subKeys[i]}`);
  148. }
  149. if (!(subKeys[i] in currentObj)) {
  150. currentObj[subKeys[i]] = create();
  151. }
  152. if (!isObject(currentObj[subKeys[i]])) {
  153. (process.env.NODE_ENV !== 'production') &&
  154. warn(getWarnMessage(I18nWarnCodes.IGNORE_OBJ_FLATTEN, {
  155. key: subKeys[i]
  156. }));
  157. hasStringValue = true;
  158. break;
  159. }
  160. currentObj = currentObj[subKeys[i]];
  161. }
  162. // update last object value, delete old property
  163. if (!hasStringValue) {
  164. if (!isMessageAST(currentObj)) {
  165. currentObj[subKeys[lastIndex]] = obj[key];
  166. delete obj[key];
  167. }
  168. else {
  169. /**
  170. * NOTE:
  171. * if the last object is a message AST and subKeys[lastIndex] has message AST prop key, ignore to copy and key deletion
  172. */
  173. if (!AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
  174. delete obj[key];
  175. }
  176. }
  177. }
  178. // recursive process value if value is also a object
  179. if (!isMessageAST(currentObj)) {
  180. const target = currentObj[subKeys[lastIndex]];
  181. if (isObject(target)) {
  182. handleFlatJson(target);
  183. }
  184. }
  185. }
  186. }
  187. return obj;
  188. }
  189. function getLocaleMessages(locale, options) {
  190. const { messages, __i18n, messageResolver, flatJson } = options;
  191. // prettier-ignore
  192. const ret = (isPlainObject(messages)
  193. ? messages
  194. : isArray(__i18n)
  195. ? create()
  196. : { [locale]: create() });
  197. // merge locale messages of i18n custom block
  198. if (isArray(__i18n)) {
  199. __i18n.forEach(custom => {
  200. if ('locale' in custom && 'resource' in custom) {
  201. const { locale, resource } = custom;
  202. if (locale) {
  203. ret[locale] = ret[locale] || create();
  204. deepCopy(resource, ret[locale]);
  205. }
  206. else {
  207. deepCopy(resource, ret);
  208. }
  209. }
  210. else {
  211. isString(custom) && deepCopy(JSON.parse(custom), ret);
  212. }
  213. });
  214. }
  215. // handle messages for flat json
  216. if (messageResolver == null && flatJson) {
  217. for (const key in ret) {
  218. if (hasOwn(ret, key)) {
  219. handleFlatJson(ret[key]);
  220. }
  221. }
  222. }
  223. return ret;
  224. }
  225. function getComponentOptions(instance) {
  226. return instance.type;
  227. }
  228. function adjustI18nResources(gl, options, componentOptions) {
  229. // prettier-ignore
  230. let messages = isObject(options.messages)
  231. ? options.messages
  232. : create();
  233. if ('__i18nGlobal' in componentOptions) {
  234. messages = getLocaleMessages(gl.locale.value, {
  235. messages,
  236. __i18n: componentOptions.__i18nGlobal
  237. });
  238. }
  239. // merge locale messages
  240. const locales = Object.keys(messages);
  241. if (locales.length) {
  242. locales.forEach(locale => {
  243. gl.mergeLocaleMessage(locale, messages[locale]);
  244. });
  245. }
  246. {
  247. // merge datetime formats
  248. if (isObject(options.datetimeFormats)) {
  249. const locales = Object.keys(options.datetimeFormats);
  250. if (locales.length) {
  251. locales.forEach(locale => {
  252. gl.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
  253. });
  254. }
  255. }
  256. // merge number formats
  257. if (isObject(options.numberFormats)) {
  258. const locales = Object.keys(options.numberFormats);
  259. if (locales.length) {
  260. locales.forEach(locale => {
  261. gl.mergeNumberFormat(locale, options.numberFormats[locale]);
  262. });
  263. }
  264. }
  265. }
  266. }
  267. function createTextNode(key) {
  268. return createVNode(Text, null, key, 0);
  269. }
  270. /* eslint-disable @typescript-eslint/no-explicit-any */
  271. // extend VNode interface
  272. const DEVTOOLS_META = '__INTLIFY_META__';
  273. const NOOP_RETURN_ARRAY = () => [];
  274. const NOOP_RETURN_FALSE = () => false;
  275. let composerID = 0;
  276. function defineCoreMissingHandler(missing) {
  277. return ((ctx, locale, key, type) => {
  278. return missing(locale, key, getCurrentInstance() || undefined, type);
  279. });
  280. }
  281. // for Intlify DevTools
  282. /* #__NO_SIDE_EFFECTS__ */
  283. const getMetaInfo = () => {
  284. const instance = getCurrentInstance();
  285. let meta = null;
  286. return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META])
  287. ? { [DEVTOOLS_META]: meta }
  288. : null;
  289. };
  290. /**
  291. * Create composer interface factory
  292. *
  293. * @internal
  294. */
  295. function createComposer(options = {}) {
  296. const { __root, __injectWithOption } = options;
  297. const _isGlobal = __root === undefined;
  298. const flatJson = options.flatJson;
  299. const _ref = inBrowser ? ref : shallowRef;
  300. let _inheritLocale = isBoolean(options.inheritLocale)
  301. ? options.inheritLocale
  302. : true;
  303. const _locale = _ref(
  304. // prettier-ignore
  305. __root && _inheritLocale
  306. ? __root.locale.value
  307. : isString(options.locale)
  308. ? options.locale
  309. : DEFAULT_LOCALE);
  310. const _fallbackLocale = _ref(
  311. // prettier-ignore
  312. __root && _inheritLocale
  313. ? __root.fallbackLocale.value
  314. : isString(options.fallbackLocale) ||
  315. isArray(options.fallbackLocale) ||
  316. isPlainObject(options.fallbackLocale) ||
  317. options.fallbackLocale === false
  318. ? options.fallbackLocale
  319. : _locale.value);
  320. const _messages = _ref(getLocaleMessages(_locale.value, options));
  321. // prettier-ignore
  322. const _datetimeFormats = _ref(isPlainObject(options.datetimeFormats)
  323. ? options.datetimeFormats
  324. : { [_locale.value]: {} })
  325. ;
  326. // prettier-ignore
  327. const _numberFormats = _ref(isPlainObject(options.numberFormats)
  328. ? options.numberFormats
  329. : { [_locale.value]: {} })
  330. ;
  331. // warning suppress options
  332. // prettier-ignore
  333. let _missingWarn = __root
  334. ? __root.missingWarn
  335. : isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
  336. ? options.missingWarn
  337. : true;
  338. // prettier-ignore
  339. let _fallbackWarn = __root
  340. ? __root.fallbackWarn
  341. : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
  342. ? options.fallbackWarn
  343. : true;
  344. // prettier-ignore
  345. let _fallbackRoot = __root
  346. ? __root.fallbackRoot
  347. : isBoolean(options.fallbackRoot)
  348. ? options.fallbackRoot
  349. : true;
  350. // configure fall back to root
  351. let _fallbackFormat = !!options.fallbackFormat;
  352. // runtime missing
  353. let _missing = isFunction(options.missing) ? options.missing : null;
  354. let _runtimeMissing = isFunction(options.missing)
  355. ? defineCoreMissingHandler(options.missing)
  356. : null;
  357. // postTranslation handler
  358. let _postTranslation = isFunction(options.postTranslation)
  359. ? options.postTranslation
  360. : null;
  361. // prettier-ignore
  362. let _warnHtmlMessage = __root
  363. ? __root.warnHtmlMessage
  364. : isBoolean(options.warnHtmlMessage)
  365. ? options.warnHtmlMessage
  366. : true;
  367. let _escapeParameter = !!options.escapeParameter;
  368. // custom linked modifiers
  369. // prettier-ignore
  370. const _modifiers = __root
  371. ? __root.modifiers
  372. : isPlainObject(options.modifiers)
  373. ? options.modifiers
  374. : {};
  375. // pluralRules
  376. let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
  377. // runtime context
  378. // eslint-disable-next-line prefer-const
  379. let _context;
  380. const getCoreContext = () => {
  381. _isGlobal && setFallbackContext(null);
  382. const ctxOptions = {
  383. version: VERSION,
  384. locale: _locale.value,
  385. fallbackLocale: _fallbackLocale.value,
  386. messages: _messages.value,
  387. modifiers: _modifiers,
  388. pluralRules: _pluralRules,
  389. missing: _runtimeMissing === null ? undefined : _runtimeMissing,
  390. missingWarn: _missingWarn,
  391. fallbackWarn: _fallbackWarn,
  392. fallbackFormat: _fallbackFormat,
  393. unresolving: true,
  394. postTranslation: _postTranslation === null ? undefined : _postTranslation,
  395. warnHtmlMessage: _warnHtmlMessage,
  396. escapeParameter: _escapeParameter,
  397. messageResolver: options.messageResolver,
  398. messageCompiler: options.messageCompiler,
  399. __meta: { framework: 'vue' }
  400. };
  401. {
  402. ctxOptions.datetimeFormats = _datetimeFormats.value;
  403. ctxOptions.numberFormats = _numberFormats.value;
  404. ctxOptions.__datetimeFormatters = isPlainObject(_context)
  405. ? _context.__datetimeFormatters
  406. : undefined;
  407. ctxOptions.__numberFormatters = isPlainObject(_context)
  408. ? _context.__numberFormatters
  409. : undefined;
  410. }
  411. if ((process.env.NODE_ENV !== 'production')) {
  412. ctxOptions.__v_emitter = isPlainObject(_context)
  413. ? _context.__v_emitter
  414. : undefined;
  415. }
  416. const ctx = createCoreContext(ctxOptions);
  417. _isGlobal && setFallbackContext(ctx);
  418. return ctx;
  419. };
  420. _context = getCoreContext();
  421. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  422. // track reactivity
  423. function trackReactivityValues() {
  424. return [
  425. _locale.value,
  426. _fallbackLocale.value,
  427. _messages.value,
  428. _datetimeFormats.value,
  429. _numberFormats.value
  430. ]
  431. ;
  432. }
  433. // locale
  434. const locale = computed({
  435. get: () => _locale.value,
  436. set: val => {
  437. _context.locale = val;
  438. _locale.value = val;
  439. }
  440. });
  441. // fallbackLocale
  442. const fallbackLocale = computed({
  443. get: () => _fallbackLocale.value,
  444. set: val => {
  445. _context.fallbackLocale = val;
  446. _fallbackLocale.value = val;
  447. updateFallbackLocale(_context, _locale.value, val);
  448. }
  449. });
  450. // messages
  451. const messages = computed(() => _messages.value);
  452. // datetimeFormats
  453. const datetimeFormats = /* #__PURE__*/ computed(() => _datetimeFormats.value);
  454. // numberFormats
  455. const numberFormats = /* #__PURE__*/ computed(() => _numberFormats.value);
  456. // getPostTranslationHandler
  457. function getPostTranslationHandler() {
  458. return isFunction(_postTranslation) ? _postTranslation : null;
  459. }
  460. // setPostTranslationHandler
  461. function setPostTranslationHandler(handler) {
  462. _postTranslation = handler;
  463. _context.postTranslation = handler;
  464. }
  465. // getMissingHandler
  466. function getMissingHandler() {
  467. return _missing;
  468. }
  469. // setMissingHandler
  470. function setMissingHandler(handler) {
  471. if (handler !== null) {
  472. _runtimeMissing = defineCoreMissingHandler(handler);
  473. }
  474. _missing = handler;
  475. _context.missing = _runtimeMissing;
  476. }
  477. function isResolvedTranslateMessage(type, arg) {
  478. return type !== 'translate' || !arg.resolvedMessage;
  479. }
  480. const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
  481. trackReactivityValues(); // track reactive dependency
  482. // NOTE: experimental !!
  483. let ret;
  484. try {
  485. if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
  486. setAdditionalMeta(getMetaInfo());
  487. }
  488. if (!_isGlobal) {
  489. _context.fallbackContext = __root
  490. ? getFallbackContext()
  491. : undefined;
  492. }
  493. ret = fn(_context);
  494. }
  495. finally {
  496. if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
  497. setAdditionalMeta(null);
  498. }
  499. if (!_isGlobal) {
  500. _context.fallbackContext = undefined;
  501. }
  502. }
  503. if ((warnType !== 'translate exists' && // for not `te` (e.g `t`)
  504. isNumber(ret) &&
  505. ret === NOT_REOSLVED) ||
  506. (warnType === 'translate exists' && !ret) // for `te`
  507. ) {
  508. const [key, arg2] = argumentParser();
  509. if ((process.env.NODE_ENV !== 'production') &&
  510. __root &&
  511. isString(key) &&
  512. isResolvedTranslateMessage(warnType, arg2)) {
  513. if (_fallbackRoot &&
  514. (isTranslateFallbackWarn(_fallbackWarn, key) ||
  515. isTranslateMissingWarn(_missingWarn, key))) {
  516. warn(getWarnMessage(I18nWarnCodes.FALLBACK_TO_ROOT, {
  517. key,
  518. type: warnType
  519. }));
  520. }
  521. // for vue-devtools timeline event
  522. if ((process.env.NODE_ENV !== 'production')) {
  523. const { __v_emitter: emitter } = _context;
  524. if (emitter && _fallbackRoot) {
  525. emitter.emit('fallback', {
  526. type: warnType,
  527. key,
  528. to: 'global',
  529. groupId: `${warnType}:${key}`
  530. });
  531. }
  532. }
  533. }
  534. return __root && _fallbackRoot
  535. ? fallbackSuccess(__root)
  536. : fallbackFail(key);
  537. }
  538. else if (successCondition(ret)) {
  539. return ret;
  540. }
  541. else {
  542. /* istanbul ignore next */
  543. throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
  544. }
  545. };
  546. // t
  547. function t(...args) {
  548. return wrapWithDeps(context => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), 'translate', root => Reflect.apply(root.t, root, [...args]), key => key, val => isString(val));
  549. }
  550. // rt
  551. function rt(...args) {
  552. const [arg1, arg2, arg3] = args;
  553. if (arg3 && !isObject(arg3)) {
  554. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  555. }
  556. return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
  557. }
  558. // d
  559. function d(...args) {
  560. 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));
  561. }
  562. // n
  563. function n(...args) {
  564. 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));
  565. }
  566. // for custom processor
  567. function normalize(values) {
  568. return values.map(val => isString(val) || isNumber(val) || isBoolean(val)
  569. ? createTextNode(String(val))
  570. : val);
  571. }
  572. const interpolate = (val) => val;
  573. const processor = {
  574. normalize,
  575. interpolate,
  576. type: 'vnode'
  577. };
  578. // translateVNode, using for `i18n-t` component
  579. function translateVNode(...args) {
  580. return wrapWithDeps(context => {
  581. let ret;
  582. const _context = context;
  583. try {
  584. _context.processor = processor;
  585. ret = Reflect.apply(translate, null, [_context, ...args]);
  586. }
  587. finally {
  588. _context.processor = null;
  589. }
  590. return ret;
  591. }, () => parseTranslateArgs(...args), 'translate', root => root[TranslateVNodeSymbol](...args), key => [createTextNode(key)], val => isArray(val));
  592. }
  593. // numberParts, using for `i18n-n` component
  594. function numberParts(...args) {
  595. return wrapWithDeps(context => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), 'number format', root => root[NumberPartsSymbol](...args), NOOP_RETURN_ARRAY, val => isString(val) || isArray(val));
  596. }
  597. // datetimeParts, using for `i18n-d` component
  598. function datetimeParts(...args) {
  599. return wrapWithDeps(context => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), 'datetime format', root => root[DatetimePartsSymbol](...args), NOOP_RETURN_ARRAY, val => isString(val) || isArray(val));
  600. }
  601. function setPluralRules(rules) {
  602. _pluralRules = rules;
  603. _context.pluralRules = _pluralRules;
  604. }
  605. // te
  606. function te(key, locale) {
  607. return wrapWithDeps(() => {
  608. if (!key) {
  609. return false;
  610. }
  611. const targetLocale = isString(locale) ? locale : _locale.value;
  612. const message = getLocaleMessage(targetLocale);
  613. const resolved = _context.messageResolver(message, key);
  614. return (isMessageAST(resolved) ||
  615. isMessageFunction(resolved) ||
  616. isString(resolved));
  617. }, () => [key], 'translate exists', root => {
  618. return Reflect.apply(root.te, root, [key, locale]);
  619. }, NOOP_RETURN_FALSE, val => isBoolean(val));
  620. }
  621. function resolveMessages(key) {
  622. let messages = null;
  623. const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
  624. for (let i = 0; i < locales.length; i++) {
  625. const targetLocaleMessages = _messages.value[locales[i]] || {};
  626. const messageValue = _context.messageResolver(targetLocaleMessages, key);
  627. if (messageValue != null) {
  628. messages = messageValue;
  629. break;
  630. }
  631. }
  632. return messages;
  633. }
  634. // tm
  635. function tm(key) {
  636. const messages = resolveMessages(key);
  637. // prettier-ignore
  638. return messages != null
  639. ? messages
  640. : __root
  641. ? __root.tm(key) || {}
  642. : {};
  643. }
  644. // getLocaleMessage
  645. function getLocaleMessage(locale) {
  646. return (_messages.value[locale] || {});
  647. }
  648. // setLocaleMessage
  649. function setLocaleMessage(locale, message) {
  650. if (flatJson) {
  651. const _message = { [locale]: message };
  652. for (const key in _message) {
  653. if (hasOwn(_message, key)) {
  654. handleFlatJson(_message[key]);
  655. }
  656. }
  657. message = _message[locale];
  658. }
  659. _messages.value[locale] = message;
  660. _context.messages = _messages.value;
  661. }
  662. // mergeLocaleMessage
  663. function mergeLocaleMessage(locale, message) {
  664. _messages.value[locale] = _messages.value[locale] || {};
  665. const _message = { [locale]: message };
  666. if (flatJson) {
  667. for (const key in _message) {
  668. if (hasOwn(_message, key)) {
  669. handleFlatJson(_message[key]);
  670. }
  671. }
  672. }
  673. message = _message[locale];
  674. deepCopy(message, _messages.value[locale]);
  675. _context.messages = _messages.value;
  676. }
  677. // getDateTimeFormat
  678. function getDateTimeFormat(locale) {
  679. return _datetimeFormats.value[locale] || {};
  680. }
  681. // setDateTimeFormat
  682. function setDateTimeFormat(locale, format) {
  683. _datetimeFormats.value[locale] = format;
  684. _context.datetimeFormats = _datetimeFormats.value;
  685. clearDateTimeFormat(_context, locale, format);
  686. }
  687. // mergeDateTimeFormat
  688. function mergeDateTimeFormat(locale, format) {
  689. _datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format);
  690. _context.datetimeFormats = _datetimeFormats.value;
  691. clearDateTimeFormat(_context, locale, format);
  692. }
  693. // getNumberFormat
  694. function getNumberFormat(locale) {
  695. return _numberFormats.value[locale] || {};
  696. }
  697. // setNumberFormat
  698. function setNumberFormat(locale, format) {
  699. _numberFormats.value[locale] = format;
  700. _context.numberFormats = _numberFormats.value;
  701. clearNumberFormat(_context, locale, format);
  702. }
  703. // mergeNumberFormat
  704. function mergeNumberFormat(locale, format) {
  705. _numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format);
  706. _context.numberFormats = _numberFormats.value;
  707. clearNumberFormat(_context, locale, format);
  708. }
  709. // for debug
  710. composerID++;
  711. // watch root locale & fallbackLocale
  712. if (__root && inBrowser) {
  713. watch(__root.locale, (val) => {
  714. if (_inheritLocale) {
  715. _locale.value = val;
  716. _context.locale = val;
  717. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  718. }
  719. });
  720. watch(__root.fallbackLocale, (val) => {
  721. if (_inheritLocale) {
  722. _fallbackLocale.value = val;
  723. _context.fallbackLocale = val;
  724. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  725. }
  726. });
  727. }
  728. // define basic composition API!
  729. const composer = {
  730. id: composerID,
  731. locale,
  732. fallbackLocale,
  733. get inheritLocale() {
  734. return _inheritLocale;
  735. },
  736. set inheritLocale(val) {
  737. _inheritLocale = val;
  738. if (val && __root) {
  739. _locale.value = __root.locale.value;
  740. _fallbackLocale.value = __root.fallbackLocale.value;
  741. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  742. }
  743. },
  744. get availableLocales() {
  745. return Object.keys(_messages.value).sort();
  746. },
  747. messages,
  748. get modifiers() {
  749. return _modifiers;
  750. },
  751. get pluralRules() {
  752. return _pluralRules || {};
  753. },
  754. get isGlobal() {
  755. return _isGlobal;
  756. },
  757. get missingWarn() {
  758. return _missingWarn;
  759. },
  760. set missingWarn(val) {
  761. _missingWarn = val;
  762. _context.missingWarn = _missingWarn;
  763. },
  764. get fallbackWarn() {
  765. return _fallbackWarn;
  766. },
  767. set fallbackWarn(val) {
  768. _fallbackWarn = val;
  769. _context.fallbackWarn = _fallbackWarn;
  770. },
  771. get fallbackRoot() {
  772. return _fallbackRoot;
  773. },
  774. set fallbackRoot(val) {
  775. _fallbackRoot = val;
  776. },
  777. get fallbackFormat() {
  778. return _fallbackFormat;
  779. },
  780. set fallbackFormat(val) {
  781. _fallbackFormat = val;
  782. _context.fallbackFormat = _fallbackFormat;
  783. },
  784. get warnHtmlMessage() {
  785. return _warnHtmlMessage;
  786. },
  787. set warnHtmlMessage(val) {
  788. _warnHtmlMessage = val;
  789. _context.warnHtmlMessage = val;
  790. },
  791. get escapeParameter() {
  792. return _escapeParameter;
  793. },
  794. set escapeParameter(val) {
  795. _escapeParameter = val;
  796. _context.escapeParameter = val;
  797. },
  798. t,
  799. getLocaleMessage,
  800. setLocaleMessage,
  801. mergeLocaleMessage,
  802. getPostTranslationHandler,
  803. setPostTranslationHandler,
  804. getMissingHandler,
  805. setMissingHandler,
  806. [SetPluralRulesSymbol]: setPluralRules
  807. };
  808. {
  809. composer.datetimeFormats = datetimeFormats;
  810. composer.numberFormats = numberFormats;
  811. composer.rt = rt;
  812. composer.te = te;
  813. composer.tm = tm;
  814. composer.d = d;
  815. composer.n = n;
  816. composer.getDateTimeFormat = getDateTimeFormat;
  817. composer.setDateTimeFormat = setDateTimeFormat;
  818. composer.mergeDateTimeFormat = mergeDateTimeFormat;
  819. composer.getNumberFormat = getNumberFormat;
  820. composer.setNumberFormat = setNumberFormat;
  821. composer.mergeNumberFormat = mergeNumberFormat;
  822. composer[InejctWithOptionSymbol] = __injectWithOption;
  823. composer[TranslateVNodeSymbol] = translateVNode;
  824. composer[DatetimePartsSymbol] = datetimeParts;
  825. composer[NumberPartsSymbol] = numberParts;
  826. }
  827. // for vue-devtools timeline event
  828. if ((process.env.NODE_ENV !== 'production')) {
  829. composer[EnableEmitter] = (emitter) => {
  830. _context.__v_emitter = emitter;
  831. };
  832. composer[DisableEmitter] = () => {
  833. _context.__v_emitter = undefined;
  834. };
  835. }
  836. return composer;
  837. }
  838. /* eslint-enable @typescript-eslint/no-explicit-any */
  839. const VUE_I18N_COMPONENT_TYPES = 'vue-i18n: composer properties';
  840. const VueDevToolsLabels = {
  841. 'vue-devtools-plugin-vue-i18n': 'Vue I18n DevTools',
  842. 'vue-i18n-resource-inspector': 'Vue I18n DevTools',
  843. 'vue-i18n-timeline': 'Vue I18n'
  844. };
  845. const VueDevToolsPlaceholders = {
  846. 'vue-i18n-resource-inspector': 'Search for scopes ...'
  847. };
  848. const VueDevToolsTimelineColors = {
  849. 'vue-i18n-timeline': 0xffcd19
  850. };
  851. let devtoolsApi;
  852. async function enableDevTools(app, i18n) {
  853. return new Promise((resolve, reject) => {
  854. try {
  855. setupDevtoolsPlugin({
  856. id: 'vue-devtools-plugin-vue-i18n',
  857. label: VueDevToolsLabels['vue-devtools-plugin-vue-i18n'],
  858. packageName: 'vue-i18n',
  859. homepage: 'https://vue-i18n.intlify.dev',
  860. logo: 'https://vue-i18n.intlify.dev/vue-i18n-devtools-logo.png',
  861. componentStateTypes: [VUE_I18N_COMPONENT_TYPES],
  862. app: app // eslint-disable-line @typescript-eslint/no-explicit-any
  863. }, api => {
  864. devtoolsApi = api;
  865. api.on.visitComponentTree(({ componentInstance, treeNode }) => {
  866. updateComponentTreeTags(componentInstance, treeNode, i18n);
  867. });
  868. api.on.inspectComponent(({ componentInstance, instanceData }) => {
  869. if (componentInstance.vnode.el &&
  870. componentInstance.vnode.el.__VUE_I18N__ &&
  871. instanceData) {
  872. if (i18n.mode === 'legacy') {
  873. // ignore global scope on legacy mode
  874. if (componentInstance.vnode.el.__VUE_I18N__ !==
  875. i18n.global.__composer) {
  876. inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
  877. }
  878. }
  879. else {
  880. inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
  881. }
  882. }
  883. });
  884. api.addInspector({
  885. id: 'vue-i18n-resource-inspector',
  886. label: VueDevToolsLabels['vue-i18n-resource-inspector'],
  887. icon: 'language',
  888. treeFilterPlaceholder: VueDevToolsPlaceholders['vue-i18n-resource-inspector']
  889. });
  890. api.on.getInspectorTree(payload => {
  891. if (payload.app === app &&
  892. payload.inspectorId === 'vue-i18n-resource-inspector') {
  893. registerScope(payload, i18n);
  894. }
  895. });
  896. const roots = new Map();
  897. api.on.getInspectorState(async (payload) => {
  898. if (payload.app === app &&
  899. payload.inspectorId === 'vue-i18n-resource-inspector') {
  900. api.unhighlightElement();
  901. inspectScope(payload, i18n);
  902. if (payload.nodeId === 'global') {
  903. if (!roots.has(payload.app)) {
  904. const [root] = await api.getComponentInstances(payload.app);
  905. roots.set(payload.app, root);
  906. }
  907. api.highlightElement(roots.get(payload.app));
  908. }
  909. else {
  910. const instance = getComponentInstance(payload.nodeId, i18n);
  911. instance && api.highlightElement(instance);
  912. }
  913. }
  914. });
  915. api.on.editInspectorState(payload => {
  916. if (payload.app === app &&
  917. payload.inspectorId === 'vue-i18n-resource-inspector') {
  918. editScope(payload, i18n);
  919. }
  920. });
  921. api.addTimelineLayer({
  922. id: 'vue-i18n-timeline',
  923. label: VueDevToolsLabels['vue-i18n-timeline'],
  924. color: VueDevToolsTimelineColors['vue-i18n-timeline']
  925. });
  926. resolve(true);
  927. });
  928. }
  929. catch (e) {
  930. console.error(e);
  931. // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
  932. reject(false);
  933. }
  934. });
  935. }
  936. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  937. function getI18nScopeLable(instance) {
  938. return (instance.type.name ||
  939. instance.type.displayName ||
  940. instance.type.__file ||
  941. 'Anonymous');
  942. }
  943. function updateComponentTreeTags(instance, // eslint-disable-line @typescript-eslint/no-explicit-any
  944. treeNode, i18n) {
  945. // prettier-ignore
  946. const global = i18n.mode === 'composition'
  947. ? i18n.global
  948. : i18n.global.__composer;
  949. if (instance && instance.vnode.el && instance.vnode.el.__VUE_I18N__) {
  950. // add custom tags local scope only
  951. if (instance.vnode.el.__VUE_I18N__ !== global) {
  952. const tag = {
  953. label: `i18n (${getI18nScopeLable(instance)} Scope)`,
  954. textColor: 0x000000,
  955. backgroundColor: 0xffcd19
  956. };
  957. treeNode.tags.push(tag);
  958. }
  959. }
  960. }
  961. function inspectComposer(instanceData, composer) {
  962. const type = VUE_I18N_COMPONENT_TYPES;
  963. instanceData.state.push({
  964. type,
  965. key: 'locale',
  966. editable: true,
  967. value: composer.locale.value
  968. });
  969. instanceData.state.push({
  970. type,
  971. key: 'availableLocales',
  972. editable: false,
  973. value: composer.availableLocales
  974. });
  975. instanceData.state.push({
  976. type,
  977. key: 'fallbackLocale',
  978. editable: true,
  979. value: composer.fallbackLocale.value
  980. });
  981. instanceData.state.push({
  982. type,
  983. key: 'inheritLocale',
  984. editable: true,
  985. value: composer.inheritLocale
  986. });
  987. instanceData.state.push({
  988. type,
  989. key: 'messages',
  990. editable: false,
  991. value: getLocaleMessageValue(composer.messages.value)
  992. });
  993. {
  994. instanceData.state.push({
  995. type,
  996. key: 'datetimeFormats',
  997. editable: false,
  998. value: composer.datetimeFormats.value
  999. });
  1000. instanceData.state.push({
  1001. type,
  1002. key: 'numberFormats',
  1003. editable: false,
  1004. value: composer.numberFormats.value
  1005. });
  1006. }
  1007. }
  1008. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1009. function getLocaleMessageValue(messages) {
  1010. const value = {};
  1011. Object.keys(messages).forEach((key) => {
  1012. const v = messages[key];
  1013. if (isFunction(v) && 'source' in v) {
  1014. value[key] = getMessageFunctionDetails(v);
  1015. }
  1016. else if (isMessageAST(v) && v.loc && v.loc.source) {
  1017. value[key] = v.loc.source;
  1018. }
  1019. else if (isObject(v)) {
  1020. value[key] = getLocaleMessageValue(v);
  1021. }
  1022. else {
  1023. value[key] = v;
  1024. }
  1025. });
  1026. return value;
  1027. }
  1028. const ESC = {
  1029. '<': '&lt;',
  1030. '>': '&gt;',
  1031. '"': '&quot;',
  1032. '&': '&amp;'
  1033. };
  1034. function escape(s) {
  1035. return s.replace(/[<>"&]/g, escapeChar);
  1036. }
  1037. function escapeChar(a) {
  1038. return ESC[a] || a;
  1039. }
  1040. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1041. function getMessageFunctionDetails(func) {
  1042. const argString = func.source ? `("${escape(func.source)}")` : `(?)`;
  1043. return {
  1044. _custom: {
  1045. type: 'function',
  1046. display: `<span>ƒ</span> ${argString}`
  1047. }
  1048. };
  1049. }
  1050. function registerScope(payload, i18n) {
  1051. payload.rootNodes.push({
  1052. id: 'global',
  1053. label: 'Global Scope'
  1054. });
  1055. // prettier-ignore
  1056. const global = i18n.mode === 'composition'
  1057. ? i18n.global
  1058. : i18n.global.__composer;
  1059. for (const [keyInstance, instance] of i18n.__instances) {
  1060. // prettier-ignore
  1061. const composer = i18n.mode === 'composition'
  1062. ? instance
  1063. : instance.__composer;
  1064. if (global === composer) {
  1065. continue;
  1066. }
  1067. payload.rootNodes.push({
  1068. id: composer.id.toString(),
  1069. label: `${getI18nScopeLable(keyInstance)} Scope`
  1070. });
  1071. }
  1072. }
  1073. function getComponentInstance(nodeId, i18n) {
  1074. let instance = null;
  1075. if (nodeId !== 'global') {
  1076. for (const [component, composer] of i18n.__instances.entries()) {
  1077. if (composer.id.toString() === nodeId) {
  1078. instance = component;
  1079. break;
  1080. }
  1081. }
  1082. }
  1083. return instance;
  1084. }
  1085. function getComposer$2(nodeId, i18n) {
  1086. if (nodeId === 'global') {
  1087. return i18n.mode === 'composition'
  1088. ? i18n.global
  1089. : i18n.global.__composer;
  1090. }
  1091. else {
  1092. const instance = Array.from(i18n.__instances.values()).find(item => item.id.toString() === nodeId);
  1093. if (instance) {
  1094. return i18n.mode === 'composition'
  1095. ? instance
  1096. : instance.__composer;
  1097. }
  1098. else {
  1099. return null;
  1100. }
  1101. }
  1102. }
  1103. function inspectScope(payload, i18n
  1104. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1105. ) {
  1106. const composer = getComposer$2(payload.nodeId, i18n);
  1107. if (composer) {
  1108. // TODO:
  1109. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1110. payload.state = makeScopeInspectState(composer);
  1111. }
  1112. return null;
  1113. }
  1114. function makeScopeInspectState(composer) {
  1115. const state = {};
  1116. const localeType = 'Locale related info';
  1117. const localeStates = [
  1118. {
  1119. type: localeType,
  1120. key: 'locale',
  1121. editable: true,
  1122. value: composer.locale.value
  1123. },
  1124. {
  1125. type: localeType,
  1126. key: 'fallbackLocale',
  1127. editable: true,
  1128. value: composer.fallbackLocale.value
  1129. },
  1130. {
  1131. type: localeType,
  1132. key: 'availableLocales',
  1133. editable: false,
  1134. value: composer.availableLocales
  1135. },
  1136. {
  1137. type: localeType,
  1138. key: 'inheritLocale',
  1139. editable: true,
  1140. value: composer.inheritLocale
  1141. }
  1142. ];
  1143. state[localeType] = localeStates;
  1144. const localeMessagesType = 'Locale messages info';
  1145. const localeMessagesStates = [
  1146. {
  1147. type: localeMessagesType,
  1148. key: 'messages',
  1149. editable: false,
  1150. value: getLocaleMessageValue(composer.messages.value)
  1151. }
  1152. ];
  1153. state[localeMessagesType] = localeMessagesStates;
  1154. {
  1155. const datetimeFormatsType = 'Datetime formats info';
  1156. const datetimeFormatsStates = [
  1157. {
  1158. type: datetimeFormatsType,
  1159. key: 'datetimeFormats',
  1160. editable: false,
  1161. value: composer.datetimeFormats.value
  1162. }
  1163. ];
  1164. state[datetimeFormatsType] = datetimeFormatsStates;
  1165. const numberFormatsType = 'Datetime formats info';
  1166. const numberFormatsStates = [
  1167. {
  1168. type: numberFormatsType,
  1169. key: 'numberFormats',
  1170. editable: false,
  1171. value: composer.numberFormats.value
  1172. }
  1173. ];
  1174. state[numberFormatsType] = numberFormatsStates;
  1175. }
  1176. return state;
  1177. }
  1178. function addTimelineEvent(event, payload) {
  1179. if (devtoolsApi) {
  1180. let groupId;
  1181. if (payload && 'groupId' in payload) {
  1182. groupId = payload.groupId;
  1183. delete payload.groupId;
  1184. }
  1185. devtoolsApi.addTimelineEvent({
  1186. layerId: 'vue-i18n-timeline',
  1187. event: {
  1188. title: event,
  1189. groupId,
  1190. time: Date.now(),
  1191. meta: {},
  1192. data: payload || {},
  1193. logType: event === 'compile-error'
  1194. ? 'error'
  1195. : event === 'fallback' || event === 'missing'
  1196. ? 'warning'
  1197. : 'default'
  1198. }
  1199. });
  1200. }
  1201. }
  1202. function editScope(payload, i18n) {
  1203. const composer = getComposer$2(payload.nodeId, i18n);
  1204. if (composer) {
  1205. const [field] = payload.path;
  1206. if (field === 'locale' && isString(payload.state.value)) {
  1207. composer.locale.value = payload.state.value;
  1208. }
  1209. else if (field === 'fallbackLocale' &&
  1210. (isString(payload.state.value) ||
  1211. isArray(payload.state.value) ||
  1212. isObject(payload.state.value))) {
  1213. composer.fallbackLocale.value = payload.state.value;
  1214. }
  1215. else if (field === 'inheritLocale' && isBoolean(payload.state.value)) {
  1216. composer.inheritLocale = payload.state.value;
  1217. }
  1218. }
  1219. }
  1220. /* eslint-disable @typescript-eslint/no-explicit-any */
  1221. /**
  1222. * Convert to I18n Composer Options from VueI18n Options
  1223. *
  1224. * @internal
  1225. */
  1226. function convertComposerOptions(options) {
  1227. const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
  1228. const fallbackLocale = isString(options.fallbackLocale) ||
  1229. isArray(options.fallbackLocale) ||
  1230. isPlainObject(options.fallbackLocale) ||
  1231. options.fallbackLocale === false
  1232. ? options.fallbackLocale
  1233. : locale;
  1234. const missing = isFunction(options.missing) ? options.missing : undefined;
  1235. const missingWarn = isBoolean(options.silentTranslationWarn) ||
  1236. isRegExp(options.silentTranslationWarn)
  1237. ? !options.silentTranslationWarn
  1238. : true;
  1239. const fallbackWarn = isBoolean(options.silentFallbackWarn) ||
  1240. isRegExp(options.silentFallbackWarn)
  1241. ? !options.silentFallbackWarn
  1242. : true;
  1243. const fallbackRoot = isBoolean(options.fallbackRoot)
  1244. ? options.fallbackRoot
  1245. : true;
  1246. const fallbackFormat = !!options.formatFallbackMessages;
  1247. const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {};
  1248. const pluralizationRules = options.pluralizationRules;
  1249. const postTranslation = isFunction(options.postTranslation)
  1250. ? options.postTranslation
  1251. : undefined;
  1252. const warnHtmlMessage = isString(options.warnHtmlInMessage)
  1253. ? options.warnHtmlInMessage !== 'off'
  1254. : true;
  1255. const escapeParameter = !!options.escapeParameterHtml;
  1256. const inheritLocale = isBoolean(options.sync) ? options.sync : true;
  1257. let messages = options.messages;
  1258. if (isPlainObject(options.sharedMessages)) {
  1259. const sharedMessages = options.sharedMessages;
  1260. const locales = Object.keys(sharedMessages);
  1261. messages = locales.reduce((messages, locale) => {
  1262. const message = messages[locale] || (messages[locale] = {});
  1263. assign(message, sharedMessages[locale]);
  1264. return messages;
  1265. }, (messages || {}));
  1266. }
  1267. const { __i18n, __root, __injectWithOption } = options;
  1268. const datetimeFormats = options.datetimeFormats;
  1269. const numberFormats = options.numberFormats;
  1270. const flatJson = options.flatJson;
  1271. return {
  1272. locale,
  1273. fallbackLocale,
  1274. messages,
  1275. flatJson,
  1276. datetimeFormats,
  1277. numberFormats,
  1278. missing,
  1279. missingWarn,
  1280. fallbackWarn,
  1281. fallbackRoot,
  1282. fallbackFormat,
  1283. modifiers,
  1284. pluralRules: pluralizationRules,
  1285. postTranslation,
  1286. warnHtmlMessage,
  1287. escapeParameter,
  1288. messageResolver: options.messageResolver,
  1289. inheritLocale,
  1290. __i18n,
  1291. __root,
  1292. __injectWithOption
  1293. };
  1294. }
  1295. /**
  1296. * create VueI18n interface factory
  1297. *
  1298. * @internal
  1299. *
  1300. * @deprecated will be removed at vue-i18n v12
  1301. */
  1302. function createVueI18n(options = {}) {
  1303. const composer = createComposer(convertComposerOptions(options));
  1304. const { __extender } = options;
  1305. // defines VueI18n
  1306. const vueI18n = {
  1307. // id
  1308. id: composer.id,
  1309. // locale
  1310. get locale() {
  1311. return composer.locale.value;
  1312. },
  1313. set locale(val) {
  1314. composer.locale.value = val;
  1315. },
  1316. // fallbackLocale
  1317. get fallbackLocale() {
  1318. return composer.fallbackLocale.value;
  1319. },
  1320. set fallbackLocale(val) {
  1321. composer.fallbackLocale.value = val;
  1322. },
  1323. // messages
  1324. get messages() {
  1325. return composer.messages.value;
  1326. },
  1327. // datetimeFormats
  1328. get datetimeFormats() {
  1329. return composer.datetimeFormats.value;
  1330. },
  1331. // numberFormats
  1332. get numberFormats() {
  1333. return composer.numberFormats.value;
  1334. },
  1335. // availableLocales
  1336. get availableLocales() {
  1337. return composer.availableLocales;
  1338. },
  1339. // missing
  1340. get missing() {
  1341. return composer.getMissingHandler();
  1342. },
  1343. set missing(handler) {
  1344. composer.setMissingHandler(handler);
  1345. },
  1346. // silentTranslationWarn
  1347. get silentTranslationWarn() {
  1348. return isBoolean(composer.missingWarn)
  1349. ? !composer.missingWarn
  1350. : composer.missingWarn;
  1351. },
  1352. set silentTranslationWarn(val) {
  1353. composer.missingWarn = isBoolean(val) ? !val : val;
  1354. },
  1355. // silentFallbackWarn
  1356. get silentFallbackWarn() {
  1357. return isBoolean(composer.fallbackWarn)
  1358. ? !composer.fallbackWarn
  1359. : composer.fallbackWarn;
  1360. },
  1361. set silentFallbackWarn(val) {
  1362. composer.fallbackWarn = isBoolean(val) ? !val : val;
  1363. },
  1364. // modifiers
  1365. get modifiers() {
  1366. return composer.modifiers;
  1367. },
  1368. // formatFallbackMessages
  1369. get formatFallbackMessages() {
  1370. return composer.fallbackFormat;
  1371. },
  1372. set formatFallbackMessages(val) {
  1373. composer.fallbackFormat = val;
  1374. },
  1375. // postTranslation
  1376. get postTranslation() {
  1377. return composer.getPostTranslationHandler();
  1378. },
  1379. set postTranslation(handler) {
  1380. composer.setPostTranslationHandler(handler);
  1381. },
  1382. // sync
  1383. get sync() {
  1384. return composer.inheritLocale;
  1385. },
  1386. set sync(val) {
  1387. composer.inheritLocale = val;
  1388. },
  1389. // warnInHtmlMessage
  1390. get warnHtmlInMessage() {
  1391. return composer.warnHtmlMessage ? 'warn' : 'off';
  1392. },
  1393. set warnHtmlInMessage(val) {
  1394. composer.warnHtmlMessage = val !== 'off';
  1395. },
  1396. // escapeParameterHtml
  1397. get escapeParameterHtml() {
  1398. return composer.escapeParameter;
  1399. },
  1400. set escapeParameterHtml(val) {
  1401. composer.escapeParameter = val;
  1402. },
  1403. // pluralizationRules
  1404. get pluralizationRules() {
  1405. return composer.pluralRules || {};
  1406. },
  1407. // for internal
  1408. __composer: composer,
  1409. // t
  1410. t(...args) {
  1411. return Reflect.apply(composer.t, composer, [...args]);
  1412. },
  1413. // rt
  1414. rt(...args) {
  1415. return Reflect.apply(composer.rt, composer, [...args]);
  1416. },
  1417. // te
  1418. te(key, locale) {
  1419. return composer.te(key, locale);
  1420. },
  1421. // tm
  1422. tm(key) {
  1423. return composer.tm(key);
  1424. },
  1425. // getLocaleMessage
  1426. getLocaleMessage(locale) {
  1427. return composer.getLocaleMessage(locale);
  1428. },
  1429. // setLocaleMessage
  1430. setLocaleMessage(locale, message) {
  1431. composer.setLocaleMessage(locale, message);
  1432. },
  1433. // mergeLocaleMessage
  1434. mergeLocaleMessage(locale, message) {
  1435. composer.mergeLocaleMessage(locale, message);
  1436. },
  1437. // d
  1438. d(...args) {
  1439. return Reflect.apply(composer.d, composer, [...args]);
  1440. },
  1441. // getDateTimeFormat
  1442. getDateTimeFormat(locale) {
  1443. return composer.getDateTimeFormat(locale);
  1444. },
  1445. // setDateTimeFormat
  1446. setDateTimeFormat(locale, format) {
  1447. composer.setDateTimeFormat(locale, format);
  1448. },
  1449. // mergeDateTimeFormat
  1450. mergeDateTimeFormat(locale, format) {
  1451. composer.mergeDateTimeFormat(locale, format);
  1452. },
  1453. // n
  1454. n(...args) {
  1455. return Reflect.apply(composer.n, composer, [...args]);
  1456. },
  1457. // getNumberFormat
  1458. getNumberFormat(locale) {
  1459. return composer.getNumberFormat(locale);
  1460. },
  1461. // setNumberFormat
  1462. setNumberFormat(locale, format) {
  1463. composer.setNumberFormat(locale, format);
  1464. },
  1465. // mergeNumberFormat
  1466. mergeNumberFormat(locale, format) {
  1467. composer.mergeNumberFormat(locale, format);
  1468. }
  1469. };
  1470. vueI18n.__extender = __extender;
  1471. // for vue-devtools timeline event
  1472. if ((process.env.NODE_ENV !== 'production')) {
  1473. vueI18n.__enableEmitter = (emitter) => {
  1474. const __composer = composer;
  1475. __composer[EnableEmitter] && __composer[EnableEmitter](emitter);
  1476. };
  1477. vueI18n.__disableEmitter = () => {
  1478. const __composer = composer;
  1479. __composer[DisableEmitter] && __composer[DisableEmitter]();
  1480. };
  1481. }
  1482. return vueI18n;
  1483. }
  1484. /* eslint-enable @typescript-eslint/no-explicit-any */
  1485. /**
  1486. * Supports compatibility for legacy vue-i18n APIs
  1487. * This mixin is used when we use vue-i18n@v9.x or later
  1488. */
  1489. function defineMixin(vuei18n, composer, i18n) {
  1490. return {
  1491. beforeCreate() {
  1492. const instance = getCurrentInstance();
  1493. /* istanbul ignore if */
  1494. if (!instance) {
  1495. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1496. }
  1497. const options = this.$options;
  1498. if (options.i18n) {
  1499. const optionsI18n = options.i18n;
  1500. if (options.__i18n) {
  1501. optionsI18n.__i18n = options.__i18n;
  1502. }
  1503. optionsI18n.__root = composer;
  1504. if (this === this.$root) {
  1505. // merge option and gttach global
  1506. this.$i18n = mergeToGlobal(vuei18n, optionsI18n);
  1507. }
  1508. else {
  1509. optionsI18n.__injectWithOption = true;
  1510. optionsI18n.__extender = i18n.__vueI18nExtend;
  1511. // atttach local VueI18n instance
  1512. this.$i18n = createVueI18n(optionsI18n);
  1513. // extend VueI18n instance
  1514. const _vueI18n = this.$i18n;
  1515. if (_vueI18n.__extender) {
  1516. _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
  1517. }
  1518. }
  1519. }
  1520. else if (options.__i18n) {
  1521. if (this === this.$root) {
  1522. // merge option and gttach global
  1523. this.$i18n = mergeToGlobal(vuei18n, options);
  1524. }
  1525. else {
  1526. // atttach local VueI18n instance
  1527. this.$i18n = createVueI18n({
  1528. __i18n: options.__i18n,
  1529. __injectWithOption: true,
  1530. __extender: i18n.__vueI18nExtend,
  1531. __root: composer
  1532. });
  1533. // extend VueI18n instance
  1534. const _vueI18n = this.$i18n;
  1535. if (_vueI18n.__extender) {
  1536. _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
  1537. }
  1538. }
  1539. }
  1540. else {
  1541. // attach global VueI18n instance
  1542. this.$i18n = vuei18n;
  1543. }
  1544. if (options.__i18nGlobal) {
  1545. adjustI18nResources(composer, options, options);
  1546. }
  1547. // defines vue-i18n legacy APIs
  1548. this.$t = (...args) => this.$i18n.t(...args);
  1549. this.$rt = (...args) => this.$i18n.rt(...args);
  1550. this.$te = (key, locale) => this.$i18n.te(key, locale);
  1551. this.$d = (...args) => this.$i18n.d(...args);
  1552. this.$n = (...args) => this.$i18n.n(...args);
  1553. this.$tm = (key) => this.$i18n.tm(key);
  1554. i18n.__setInstance(instance, this.$i18n);
  1555. },
  1556. mounted() {
  1557. /* istanbul ignore if */
  1558. if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) &&
  1559. !false &&
  1560. this.$el &&
  1561. this.$i18n) {
  1562. const _vueI18n = this.$i18n;
  1563. this.$el.__VUE_I18N__ = _vueI18n.__composer;
  1564. const emitter = (this.__v_emitter =
  1565. createEmitter());
  1566. _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
  1567. emitter.on('*', addTimelineEvent);
  1568. }
  1569. },
  1570. unmounted() {
  1571. const instance = getCurrentInstance();
  1572. /* istanbul ignore if */
  1573. if (!instance) {
  1574. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1575. }
  1576. const _vueI18n = this.$i18n;
  1577. /* istanbul ignore if */
  1578. if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) &&
  1579. !false &&
  1580. this.$el &&
  1581. this.$el.__VUE_I18N__) {
  1582. if (this.__v_emitter) {
  1583. this.__v_emitter.off('*', addTimelineEvent);
  1584. delete this.__v_emitter;
  1585. }
  1586. if (this.$i18n) {
  1587. _vueI18n.__disableEmitter && _vueI18n.__disableEmitter();
  1588. delete this.$el.__VUE_I18N__;
  1589. }
  1590. }
  1591. delete this.$t;
  1592. delete this.$rt;
  1593. delete this.$te;
  1594. delete this.$d;
  1595. delete this.$n;
  1596. delete this.$tm;
  1597. if (_vueI18n.__disposer) {
  1598. _vueI18n.__disposer();
  1599. delete _vueI18n.__disposer;
  1600. delete _vueI18n.__extender;
  1601. }
  1602. i18n.__deleteInstance(instance);
  1603. delete this.$i18n;
  1604. }
  1605. };
  1606. }
  1607. function mergeToGlobal(g, options) {
  1608. g.locale = options.locale || g.locale;
  1609. g.fallbackLocale = options.fallbackLocale || g.fallbackLocale;
  1610. g.missing = options.missing || g.missing;
  1611. g.silentTranslationWarn =
  1612. options.silentTranslationWarn || g.silentFallbackWarn;
  1613. g.silentFallbackWarn = options.silentFallbackWarn || g.silentFallbackWarn;
  1614. g.formatFallbackMessages =
  1615. options.formatFallbackMessages || g.formatFallbackMessages;
  1616. g.postTranslation = options.postTranslation || g.postTranslation;
  1617. g.warnHtmlInMessage = options.warnHtmlInMessage || g.warnHtmlInMessage;
  1618. g.escapeParameterHtml = options.escapeParameterHtml || g.escapeParameterHtml;
  1619. g.sync = options.sync || g.sync;
  1620. g.__composer[SetPluralRulesSymbol](options.pluralizationRules || g.pluralizationRules);
  1621. const messages = getLocaleMessages(g.locale, {
  1622. messages: options.messages,
  1623. __i18n: options.__i18n
  1624. });
  1625. Object.keys(messages).forEach(locale => g.mergeLocaleMessage(locale, messages[locale]));
  1626. if (options.datetimeFormats) {
  1627. Object.keys(options.datetimeFormats).forEach(locale => g.mergeDateTimeFormat(locale, options.datetimeFormats[locale]));
  1628. }
  1629. if (options.numberFormats) {
  1630. Object.keys(options.numberFormats).forEach(locale => g.mergeNumberFormat(locale, options.numberFormats[locale]));
  1631. }
  1632. return g;
  1633. }
  1634. const baseFormatProps = {
  1635. tag: {
  1636. type: [String, Object]
  1637. },
  1638. locale: {
  1639. type: String
  1640. },
  1641. scope: {
  1642. type: String,
  1643. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  1644. validator: (val /* ComponentI18nScope */) => val === 'parent' || val === 'global',
  1645. default: 'parent' /* ComponentI18nScope */
  1646. },
  1647. i18n: {
  1648. type: Object
  1649. }
  1650. };
  1651. function getInterpolateArg(
  1652. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1653. { slots }, // SetupContext,
  1654. keys) {
  1655. if (keys.length === 1 && keys[0] === 'default') {
  1656. // default slot with list
  1657. const ret = slots.default ? slots.default() : [];
  1658. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1659. return ret.reduce((slot, current) => {
  1660. return [
  1661. ...slot,
  1662. // prettier-ignore
  1663. ...(current.type === Fragment ? current.children : [current])
  1664. ];
  1665. }, []);
  1666. }
  1667. else {
  1668. // named slots
  1669. return keys.reduce((arg, key) => {
  1670. const slot = slots[key];
  1671. if (slot) {
  1672. arg[key] = slot();
  1673. }
  1674. return arg;
  1675. }, create());
  1676. }
  1677. }
  1678. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1679. function getFragmentableTag() {
  1680. return Fragment;
  1681. }
  1682. const TranslationImpl = /*#__PURE__*/ defineComponent({
  1683. /* eslint-disable */
  1684. name: 'i18n-t',
  1685. props: assign({
  1686. keypath: {
  1687. type: String,
  1688. required: true
  1689. },
  1690. plural: {
  1691. type: [Number, String],
  1692. validator: (val) => isNumber(val) || !isNaN(val)
  1693. }
  1694. }, baseFormatProps),
  1695. /* eslint-enable */
  1696. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1697. setup(props, context) {
  1698. const { slots, attrs } = context;
  1699. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  1700. const i18n = props.i18n ||
  1701. useI18n({
  1702. useScope: props.scope,
  1703. __useComponent: true
  1704. });
  1705. return () => {
  1706. const keys = Object.keys(slots).filter(key => key !== '_');
  1707. const options = create();
  1708. if (props.locale) {
  1709. options.locale = props.locale;
  1710. }
  1711. if (props.plural !== undefined) {
  1712. options.plural = isString(props.plural) ? +props.plural : props.plural;
  1713. }
  1714. const arg = getInterpolateArg(context, keys);
  1715. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1716. const children = i18n[TranslateVNodeSymbol](props.keypath, arg, options);
  1717. const assignedAttrs = assign(create(), attrs);
  1718. const tag = isString(props.tag) || isObject(props.tag)
  1719. ? props.tag
  1720. : getFragmentableTag();
  1721. return h(tag, assignedAttrs, children);
  1722. };
  1723. }
  1724. });
  1725. /**
  1726. * export the public type for h/tsx inference
  1727. * also to avoid inline import() in generated d.ts files
  1728. */
  1729. /**
  1730. * Translation Component
  1731. *
  1732. * @remarks
  1733. * See the following items for property about details
  1734. *
  1735. * @VueI18nSee [TranslationProps](component#translationprops)
  1736. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  1737. * @VueI18nSee [Component Interpolation](../guide/advanced/component)
  1738. *
  1739. * @example
  1740. * ```html
  1741. * <div id="app">
  1742. * <!-- ... -->
  1743. * <i18n keypath="term" tag="label" for="tos">
  1744. * <a :href="url" target="_blank">{{ $t('tos') }}</a>
  1745. * </i18n>
  1746. * <!-- ... -->
  1747. * </div>
  1748. * ```
  1749. * ```js
  1750. * import { createApp } from 'vue'
  1751. * import { createI18n } from 'vue-i18n'
  1752. *
  1753. * const messages = {
  1754. * en: {
  1755. * tos: 'Term of Service',
  1756. * term: 'I accept xxx {0}.'
  1757. * },
  1758. * ja: {
  1759. * tos: '利用規約',
  1760. * term: '私は xxx の{0}に同意します。'
  1761. * }
  1762. * }
  1763. *
  1764. * const i18n = createI18n({
  1765. * locale: 'en',
  1766. * messages
  1767. * })
  1768. *
  1769. * const app = createApp({
  1770. * data: {
  1771. * url: '/term'
  1772. * }
  1773. * }).use(i18n).mount('#app')
  1774. * ```
  1775. *
  1776. * @VueI18nComponent
  1777. */
  1778. const Translation = TranslationImpl;
  1779. const I18nT = Translation;
  1780. function isVNode(target) {
  1781. return isArray(target) && !isString(target[0]);
  1782. }
  1783. function renderFormatter(props, context, slotKeys, partFormatter) {
  1784. const { slots, attrs } = context;
  1785. return () => {
  1786. const options = { part: true };
  1787. let overrides = create();
  1788. if (props.locale) {
  1789. options.locale = props.locale;
  1790. }
  1791. if (isString(props.format)) {
  1792. options.key = props.format;
  1793. }
  1794. else if (isObject(props.format)) {
  1795. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1796. if (isString(props.format.key)) {
  1797. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1798. options.key = props.format.key;
  1799. }
  1800. // Filter out number format options only
  1801. overrides = Object.keys(props.format).reduce((options, prop) => {
  1802. return slotKeys.includes(prop)
  1803. ? assign(create(), options, { [prop]: props.format[prop] }) // eslint-disable-line @typescript-eslint/no-explicit-any
  1804. : options;
  1805. }, create());
  1806. }
  1807. const parts = partFormatter(...[props.value, options, overrides]);
  1808. let children = [options.key];
  1809. if (isArray(parts)) {
  1810. children = parts.map((part, index) => {
  1811. const slot = slots[part.type];
  1812. const node = slot
  1813. ? slot({ [part.type]: part.value, index, parts })
  1814. : [part.value];
  1815. if (isVNode(node)) {
  1816. node[0].key = `${part.type}-${index}`;
  1817. }
  1818. return node;
  1819. });
  1820. }
  1821. else if (isString(parts)) {
  1822. children = [parts];
  1823. }
  1824. const assignedAttrs = assign(create(), attrs);
  1825. const tag = isString(props.tag) || isObject(props.tag)
  1826. ? props.tag
  1827. : getFragmentableTag();
  1828. return h(tag, assignedAttrs, children);
  1829. };
  1830. }
  1831. const NumberFormatImpl = /*#__PURE__*/ defineComponent({
  1832. /* eslint-disable */
  1833. name: 'i18n-n',
  1834. props: assign({
  1835. value: {
  1836. type: Number,
  1837. required: true
  1838. },
  1839. format: {
  1840. type: [String, Object]
  1841. }
  1842. }, baseFormatProps),
  1843. /* eslint-enable */
  1844. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1845. setup(props, context) {
  1846. const i18n = props.i18n ||
  1847. useI18n({
  1848. useScope: props.scope,
  1849. __useComponent: true
  1850. });
  1851. return renderFormatter(props, context, NUMBER_FORMAT_OPTIONS_KEYS, (...args) =>
  1852. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1853. i18n[NumberPartsSymbol](...args));
  1854. }
  1855. });
  1856. /**
  1857. * export the public type for h/tsx inference
  1858. * also to avoid inline import() in generated d.ts files
  1859. */
  1860. /**
  1861. * Number Format Component
  1862. *
  1863. * @remarks
  1864. * See the following items for property about details
  1865. *
  1866. * @VueI18nSee [FormattableProps](component#formattableprops)
  1867. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  1868. * @VueI18nSee [Custom Formatting](../guide/essentials/number#custom-formatting)
  1869. *
  1870. * @VueI18nDanger
  1871. * 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)
  1872. *
  1873. * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat)
  1874. *
  1875. * @VueI18nComponent
  1876. */
  1877. const NumberFormat = NumberFormatImpl;
  1878. const I18nN = NumberFormat;
  1879. function getComposer$1(i18n, instance) {
  1880. const i18nInternal = i18n;
  1881. if (i18n.mode === 'composition') {
  1882. return (i18nInternal.__getInstance(instance) || i18n.global);
  1883. }
  1884. else {
  1885. const vueI18n = i18nInternal.__getInstance(instance);
  1886. return vueI18n != null
  1887. ? vueI18n.__composer
  1888. : i18n.global.__composer;
  1889. }
  1890. }
  1891. /**
  1892. * @deprecated will be removed at vue-i18n v12
  1893. */
  1894. function vTDirective(i18n) {
  1895. const _process = (binding) => {
  1896. if ((process.env.NODE_ENV !== 'production')) {
  1897. warnOnce(getWarnMessage(I18nWarnCodes.DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE));
  1898. }
  1899. const { instance, value } = binding;
  1900. /* istanbul ignore if */
  1901. if (!instance || !instance.$) {
  1902. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1903. }
  1904. const composer = getComposer$1(i18n, instance.$);
  1905. const parsedValue = parseValue(value);
  1906. return [
  1907. Reflect.apply(composer.t, composer, [...makeParams(parsedValue)]),
  1908. composer
  1909. ];
  1910. };
  1911. const register = (el, binding) => {
  1912. const [textContent, composer] = _process(binding);
  1913. if (inBrowser && i18n.global === composer) {
  1914. // global scope only
  1915. el.__i18nWatcher = watch(composer.locale, () => {
  1916. binding.instance && binding.instance.$forceUpdate();
  1917. });
  1918. }
  1919. el.__composer = composer;
  1920. el.textContent = textContent;
  1921. };
  1922. const unregister = (el) => {
  1923. if (inBrowser && el.__i18nWatcher) {
  1924. el.__i18nWatcher();
  1925. el.__i18nWatcher = undefined;
  1926. delete el.__i18nWatcher;
  1927. }
  1928. if (el.__composer) {
  1929. el.__composer = undefined;
  1930. delete el.__composer;
  1931. }
  1932. };
  1933. const update = (el, { value }) => {
  1934. if (el.__composer) {
  1935. const composer = el.__composer;
  1936. const parsedValue = parseValue(value);
  1937. el.textContent = Reflect.apply(composer.t, composer, [
  1938. ...makeParams(parsedValue)
  1939. ]);
  1940. }
  1941. };
  1942. const getSSRProps = (binding) => {
  1943. const [textContent] = _process(binding);
  1944. return { textContent };
  1945. };
  1946. return {
  1947. created: register,
  1948. unmounted: unregister,
  1949. beforeUpdate: update,
  1950. getSSRProps
  1951. };
  1952. }
  1953. function parseValue(value) {
  1954. if (isString(value)) {
  1955. return { path: value };
  1956. }
  1957. else if (isPlainObject(value)) {
  1958. if (!('path' in value)) {
  1959. throw createI18nError(I18nErrorCodes.REQUIRED_VALUE, 'path');
  1960. }
  1961. return value;
  1962. }
  1963. else {
  1964. throw createI18nError(I18nErrorCodes.INVALID_VALUE);
  1965. }
  1966. }
  1967. function makeParams(value) {
  1968. const { path, locale, args, choice, plural } = value;
  1969. const options = {};
  1970. const named = args || {};
  1971. if (isString(locale)) {
  1972. options.locale = locale;
  1973. }
  1974. if (isNumber(choice)) {
  1975. options.plural = choice;
  1976. }
  1977. if (isNumber(plural)) {
  1978. options.plural = plural;
  1979. }
  1980. return [path, named, options];
  1981. }
  1982. function apply(app, i18n, ...options) {
  1983. const pluginOptions = isPlainObject(options[0])
  1984. ? options[0]
  1985. : {};
  1986. const globalInstall = isBoolean(pluginOptions.globalInstall)
  1987. ? pluginOptions.globalInstall
  1988. : true;
  1989. if (globalInstall) {
  1990. [Translation.name, 'I18nT'].forEach(name => app.component(name, Translation));
  1991. [NumberFormat.name, 'I18nN'].forEach(name => app.component(name, NumberFormat));
  1992. [DatetimeFormat.name, 'I18nD'].forEach(name => app.component(name, DatetimeFormat));
  1993. }
  1994. // install directive
  1995. {
  1996. app.directive('t', vTDirective(i18n));
  1997. }
  1998. }
  1999. /**
  2000. * Injection key for {@link useI18n}
  2001. *
  2002. * @remarks
  2003. * The global injection key for I18n instances with `useI18n`. this injection key is used in Web Components.
  2004. * Specify the i18n instance created by {@link createI18n} together with `provide` function.
  2005. *
  2006. * @VueI18nGeneral
  2007. */
  2008. const I18nInjectionKey =
  2009. /* #__PURE__*/ makeSymbol('global-vue-i18n');
  2010. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2011. function createI18n(options = {}) {
  2012. // prettier-ignore
  2013. const __legacyMode = __VUE_I18N_LEGACY_API__ && isBoolean(options.legacy)
  2014. ? options.legacy
  2015. : __VUE_I18N_LEGACY_API__;
  2016. if ((process.env.NODE_ENV !== 'production') && __legacyMode) {
  2017. warnOnce(getWarnMessage(I18nWarnCodes.DEPRECATE_LEGACY_MODE));
  2018. }
  2019. // prettier-ignore
  2020. const __globalInjection = isBoolean(options.globalInjection)
  2021. ? options.globalInjection
  2022. : true;
  2023. const __instances = new Map();
  2024. const [globalScope, __global] = createGlobal(options, __legacyMode);
  2025. const symbol = /* #__PURE__*/ makeSymbol((process.env.NODE_ENV !== 'production') ? 'vue-i18n' : '');
  2026. function __getInstance(component) {
  2027. return __instances.get(component) || null;
  2028. }
  2029. function __setInstance(component, instance) {
  2030. __instances.set(component, instance);
  2031. }
  2032. function __deleteInstance(component) {
  2033. __instances.delete(component);
  2034. }
  2035. const i18n = {
  2036. // mode
  2037. get mode() {
  2038. return __VUE_I18N_LEGACY_API__ && __legacyMode
  2039. ? 'legacy'
  2040. : 'composition';
  2041. },
  2042. // install plugin
  2043. async install(app, ...options) {
  2044. if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && !false) {
  2045. app.__VUE_I18N__ = i18n;
  2046. }
  2047. // setup global provider
  2048. app.__VUE_I18N_SYMBOL__ = symbol;
  2049. app.provide(app.__VUE_I18N_SYMBOL__, i18n);
  2050. // set composer & vuei18n extend hook options from plugin options
  2051. if (isPlainObject(options[0])) {
  2052. const opts = options[0];
  2053. i18n.__composerExtend =
  2054. opts.__composerExtend;
  2055. i18n.__vueI18nExtend =
  2056. opts.__vueI18nExtend;
  2057. }
  2058. // global method and properties injection for Composition API
  2059. let globalReleaseHandler = null;
  2060. if (!__legacyMode && __globalInjection) {
  2061. globalReleaseHandler = injectGlobalFields(app, i18n.global);
  2062. }
  2063. // install built-in components and directive
  2064. if (__VUE_I18N_FULL_INSTALL__) {
  2065. apply(app, i18n, ...options);
  2066. }
  2067. // setup mixin for Legacy API
  2068. if (__VUE_I18N_LEGACY_API__ && __legacyMode) {
  2069. app.mixin(defineMixin(__global, __global.__composer, i18n));
  2070. }
  2071. // release global scope
  2072. const unmountApp = app.unmount;
  2073. app.unmount = () => {
  2074. globalReleaseHandler && globalReleaseHandler();
  2075. i18n.dispose();
  2076. unmountApp();
  2077. };
  2078. // setup vue-devtools plugin
  2079. if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && !false) {
  2080. const ret = await enableDevTools(app, i18n);
  2081. if (!ret) {
  2082. throw createI18nError(I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN);
  2083. }
  2084. const emitter = createEmitter();
  2085. if (__legacyMode) {
  2086. const _vueI18n = __global;
  2087. _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
  2088. }
  2089. else {
  2090. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2091. const _composer = __global;
  2092. _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
  2093. }
  2094. emitter.on('*', addTimelineEvent);
  2095. }
  2096. },
  2097. // global accessor
  2098. get global() {
  2099. return __global;
  2100. },
  2101. dispose() {
  2102. globalScope.stop();
  2103. },
  2104. // @internal
  2105. __instances,
  2106. // @internal
  2107. __getInstance,
  2108. // @internal
  2109. __setInstance,
  2110. // @internal
  2111. __deleteInstance
  2112. };
  2113. return i18n;
  2114. }
  2115. function useI18n(options = {}) {
  2116. const instance = getCurrentInstance();
  2117. if (instance == null) {
  2118. throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
  2119. }
  2120. if (!instance.isCE &&
  2121. instance.appContext.app != null &&
  2122. !instance.appContext.app.__VUE_I18N_SYMBOL__) {
  2123. throw createI18nError(I18nErrorCodes.NOT_INSTALLED);
  2124. }
  2125. const i18n = getI18nInstance(instance);
  2126. const gl = getGlobalComposer(i18n);
  2127. const componentOptions = getComponentOptions(instance);
  2128. const scope = getScope(options, componentOptions);
  2129. if (scope === 'global') {
  2130. adjustI18nResources(gl, options, componentOptions);
  2131. return gl;
  2132. }
  2133. if (scope === 'parent') {
  2134. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2135. let composer = getComposer(i18n, instance, options.__useComponent);
  2136. if (composer == null) {
  2137. if ((process.env.NODE_ENV !== 'production')) {
  2138. warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
  2139. }
  2140. composer = gl;
  2141. }
  2142. return composer;
  2143. }
  2144. const i18nInternal = i18n;
  2145. let composer = i18nInternal.__getInstance(instance);
  2146. if (composer == null) {
  2147. const composerOptions = assign({}, options);
  2148. if ('__i18n' in componentOptions) {
  2149. composerOptions.__i18n = componentOptions.__i18n;
  2150. }
  2151. if (gl) {
  2152. composerOptions.__root = gl;
  2153. }
  2154. composer = createComposer(composerOptions);
  2155. if (i18nInternal.__composerExtend) {
  2156. composer[DisposeSymbol] =
  2157. i18nInternal.__composerExtend(composer);
  2158. }
  2159. setupLifeCycle(i18nInternal, instance, composer);
  2160. i18nInternal.__setInstance(instance, composer);
  2161. }
  2162. return composer;
  2163. }
  2164. function createGlobal(options, legacyMode) {
  2165. const scope = effectScope();
  2166. const obj = __VUE_I18N_LEGACY_API__ && legacyMode
  2167. ? scope.run(() => createVueI18n(options))
  2168. : scope.run(() => createComposer(options));
  2169. if (obj == null) {
  2170. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  2171. }
  2172. return [scope, obj];
  2173. }
  2174. function getI18nInstance(instance) {
  2175. const i18n = inject(!instance.isCE
  2176. ? instance.appContext.app.__VUE_I18N_SYMBOL__
  2177. : I18nInjectionKey);
  2178. /* istanbul ignore if */
  2179. if (!i18n) {
  2180. throw createI18nError(!instance.isCE
  2181. ? I18nErrorCodes.UNEXPECTED_ERROR
  2182. : I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE);
  2183. }
  2184. return i18n;
  2185. }
  2186. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2187. function getScope(options, componentOptions) {
  2188. // prettier-ignore
  2189. return isEmptyObject(options)
  2190. ? ('__i18n' in componentOptions)
  2191. ? 'local'
  2192. : 'global'
  2193. : !options.useScope
  2194. ? 'local'
  2195. : options.useScope;
  2196. }
  2197. function getGlobalComposer(i18n) {
  2198. // prettier-ignore
  2199. return i18n.mode === 'composition'
  2200. ? i18n.global
  2201. : i18n.global.__composer;
  2202. }
  2203. function getComposer(i18n, target, useComponent = false) {
  2204. let composer = null;
  2205. const root = target.root;
  2206. let current = getParentComponentInstance(target, useComponent);
  2207. while (current != null) {
  2208. const i18nInternal = i18n;
  2209. if (i18n.mode === 'composition') {
  2210. composer = i18nInternal.__getInstance(current);
  2211. }
  2212. else {
  2213. if (__VUE_I18N_LEGACY_API__) {
  2214. const vueI18n = i18nInternal.__getInstance(current);
  2215. if (vueI18n != null) {
  2216. composer = vueI18n
  2217. .__composer;
  2218. if (useComponent &&
  2219. composer &&
  2220. !composer[InejctWithOptionSymbol] // eslint-disable-line @typescript-eslint/no-explicit-any
  2221. ) {
  2222. composer = null;
  2223. }
  2224. }
  2225. }
  2226. }
  2227. if (composer != null) {
  2228. break;
  2229. }
  2230. if (root === current) {
  2231. break;
  2232. }
  2233. current = current.parent;
  2234. }
  2235. return composer;
  2236. }
  2237. function getParentComponentInstance(target, useComponent = false) {
  2238. if (target == null) {
  2239. return null;
  2240. }
  2241. // if `useComponent: true` will be specified, we get lexical scope owner instance for use-case slots
  2242. return !useComponent
  2243. ? target.parent
  2244. : target.vnode.ctx || target.parent; // eslint-disable-line @typescript-eslint/no-explicit-any
  2245. }
  2246. function setupLifeCycle(i18n, target, composer) {
  2247. let emitter = null;
  2248. onMounted(() => {
  2249. // inject composer instance to DOM for intlify-devtools
  2250. if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) &&
  2251. !false &&
  2252. target.vnode.el) {
  2253. target.vnode.el.__VUE_I18N__ = composer;
  2254. emitter = createEmitter();
  2255. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2256. const _composer = composer;
  2257. _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
  2258. emitter.on('*', addTimelineEvent);
  2259. }
  2260. }, target);
  2261. onUnmounted(() => {
  2262. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2263. const _composer = composer;
  2264. // remove composer instance from DOM for intlify-devtools
  2265. if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) &&
  2266. !false &&
  2267. target.vnode.el &&
  2268. target.vnode.el.__VUE_I18N__) {
  2269. emitter && emitter.off('*', addTimelineEvent);
  2270. _composer[DisableEmitter] && _composer[DisableEmitter]();
  2271. delete target.vnode.el.__VUE_I18N__;
  2272. }
  2273. i18n.__deleteInstance(target);
  2274. // dispose extended resources
  2275. const dispose = _composer[DisposeSymbol];
  2276. if (dispose) {
  2277. dispose();
  2278. delete _composer[DisposeSymbol];
  2279. }
  2280. }, target);
  2281. }
  2282. const globalExportProps = [
  2283. 'locale',
  2284. 'fallbackLocale',
  2285. 'availableLocales'
  2286. ];
  2287. const globalExportMethods = ['t', 'rt', 'd', 'n', 'tm', 'te']
  2288. ;
  2289. function injectGlobalFields(app, composer) {
  2290. const i18n = Object.create(null);
  2291. globalExportProps.forEach(prop => {
  2292. const desc = Object.getOwnPropertyDescriptor(composer, prop);
  2293. if (!desc) {
  2294. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  2295. }
  2296. const wrap = isRef(desc.value) // check computed props
  2297. ? {
  2298. get() {
  2299. return desc.value.value;
  2300. },
  2301. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2302. set(val) {
  2303. desc.value.value = val;
  2304. }
  2305. }
  2306. : {
  2307. get() {
  2308. return desc.get && desc.get();
  2309. }
  2310. };
  2311. Object.defineProperty(i18n, prop, wrap);
  2312. });
  2313. app.config.globalProperties.$i18n = i18n;
  2314. globalExportMethods.forEach(method => {
  2315. const desc = Object.getOwnPropertyDescriptor(composer, method);
  2316. if (!desc || !desc.value) {
  2317. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  2318. }
  2319. Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
  2320. });
  2321. const dispose = () => {
  2322. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2323. delete app.config.globalProperties.$i18n;
  2324. globalExportMethods.forEach(method => {
  2325. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2326. delete app.config.globalProperties[`$${method}`];
  2327. });
  2328. };
  2329. return dispose;
  2330. }
  2331. const DatetimeFormatImpl = /* #__PURE__*/ defineComponent({
  2332. /* eslint-disable */
  2333. name: 'i18n-d',
  2334. props: assign({
  2335. value: {
  2336. type: [Number, Date],
  2337. required: true
  2338. },
  2339. format: {
  2340. type: [String, Object]
  2341. }
  2342. }, baseFormatProps),
  2343. /* eslint-enable */
  2344. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2345. setup(props, context) {
  2346. const i18n = props.i18n ||
  2347. useI18n({
  2348. useScope: props.scope,
  2349. __useComponent: true
  2350. });
  2351. return renderFormatter(props, context, DATETIME_FORMAT_OPTIONS_KEYS, (...args) =>
  2352. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2353. i18n[DatetimePartsSymbol](...args));
  2354. }
  2355. });
  2356. /**
  2357. * Datetime Format Component
  2358. *
  2359. * @remarks
  2360. * See the following items for property about details
  2361. *
  2362. * @VueI18nSee [FormattableProps](component#formattableprops)
  2363. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  2364. * @VueI18nSee [Custom Formatting](../guide/essentials/datetime#custom-formatting)
  2365. *
  2366. * @VueI18nDanger
  2367. * 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)
  2368. *
  2369. * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
  2370. *
  2371. * @VueI18nComponent
  2372. */
  2373. const DatetimeFormat = DatetimeFormatImpl;
  2374. const I18nD = DatetimeFormat;
  2375. {
  2376. initFeatureFlags();
  2377. }
  2378. // register message compiler for jit compilation
  2379. registerMessageCompiler(compile);
  2380. // register message resolver at vue-i18n
  2381. registerMessageResolver(resolveValue);
  2382. // register fallback locale at vue-i18n
  2383. registerLocaleFallbacker(fallbackWithLocaleChain);
  2384. // NOTE: experimental !!
  2385. if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
  2386. const target = getGlobalThis();
  2387. target.__INTLIFY__ = true;
  2388. setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
  2389. }
  2390. if ((process.env.NODE_ENV !== 'production')) ;
  2391. export { DatetimeFormat, I18nD, I18nInjectionKey, I18nN, I18nT, NumberFormat, Translation, VERSION, createI18n, useI18n, vTDirective };