vue-i18n.runtime.node.mjs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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, isMessageAST, AST_NODE_PROPS_KEYS, DEFAULT_LOCALE, updateFallbackLocale, setFallbackContext, createCoreContext, clearDateTimeFormat, clearNumberFormat, setAdditionalMeta, getFallbackContext, NOT_REOSLVED, 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, isObject, create, isPlainObject, isArray, deepCopy, isString, hasOwn, isBoolean, isRegExp, isFunction, inBrowser, assign, isNumber, isEmptyObject } from '@intlify/shared';
  8. import { createVNode, Text, computed, watch, getCurrentInstance, ref, shallowRef, Fragment, defineComponent, h, effectScope, inject, onMounted, onUnmounted, isRef } from 'vue';
  9. /**
  10. * Vue I18n Version
  11. *
  12. * @remarks
  13. * Semver format. Same format as the package.json `version` field.
  14. *
  15. * @VueI18nGeneral
  16. */
  17. const VERSION = '11.1.3';
  18. /**
  19. * This is only called in esm-bundler builds.
  20. * istanbul-ignore-next
  21. */
  22. function initFeatureFlags() {
  23. if (typeof __VUE_I18N_FULL_INSTALL__ !== 'boolean') {
  24. getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true;
  25. }
  26. if (typeof __VUE_I18N_LEGACY_API__ !== 'boolean') {
  27. getGlobalThis().__VUE_I18N_LEGACY_API__ = true;
  28. }
  29. if (typeof __INTLIFY_DROP_MESSAGE_COMPILER__ !== 'boolean') {
  30. getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false;
  31. }
  32. if (typeof __INTLIFY_PROD_DEVTOOLS__ !== 'boolean') {
  33. getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
  34. }
  35. }
  36. const I18nErrorCodes = {
  37. // composer module errors
  38. UNEXPECTED_RETURN_TYPE: CORE_ERROR_CODES_EXTEND_POINT, // 24
  39. // legacy module errors
  40. INVALID_ARGUMENT: 25,
  41. // i18n module errors
  42. MUST_BE_CALL_SETUP_TOP: 26,
  43. NOT_INSTALLED: 27,
  44. // directive module errors
  45. REQUIRED_VALUE: 28,
  46. INVALID_VALUE: 29,
  47. // vue-devtools errors
  48. CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: 30,
  49. NOT_INSTALLED_WITH_PROVIDE: 31,
  50. // unexpected error
  51. UNEXPECTED_ERROR: 32,
  52. // not compatible legacy vue-i18n constructor
  53. NOT_COMPATIBLE_LEGACY_VUE_I18N: 33,
  54. // Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
  55. NOT_AVAILABLE_COMPOSITION_IN_LEGACY: 34
  56. };
  57. function createI18nError(code, ...args) {
  58. return createCompileError(code, null, undefined);
  59. }
  60. const TranslateVNodeSymbol =
  61. /* #__PURE__*/ makeSymbol('__translateVNode');
  62. const DatetimePartsSymbol = /* #__PURE__*/ makeSymbol('__datetimeParts');
  63. const NumberPartsSymbol = /* #__PURE__*/ makeSymbol('__numberParts');
  64. const SetPluralRulesSymbol = makeSymbol('__setPluralRules');
  65. makeSymbol('__intlifyMeta');
  66. const InejctWithOptionSymbol =
  67. /* #__PURE__*/ makeSymbol('__injectWithOption');
  68. const DisposeSymbol = /* #__PURE__*/ makeSymbol('__dispose');
  69. /* eslint-disable @typescript-eslint/no-explicit-any */
  70. /**
  71. * Transform flat json in obj to normal json in obj
  72. */
  73. function handleFlatJson(obj) {
  74. // check obj
  75. if (!isObject(obj)) {
  76. return obj;
  77. }
  78. if (isMessageAST(obj)) {
  79. return obj;
  80. }
  81. for (const key in obj) {
  82. // check key
  83. if (!hasOwn(obj, key)) {
  84. continue;
  85. }
  86. // handle for normal json
  87. if (!key.includes('.')) {
  88. // recursive process value if value is also a object
  89. if (isObject(obj[key])) {
  90. handleFlatJson(obj[key]);
  91. }
  92. }
  93. // handle for flat json, transform to normal json
  94. else {
  95. // go to the last object
  96. const subKeys = key.split('.');
  97. const lastIndex = subKeys.length - 1;
  98. let currentObj = obj;
  99. let hasStringValue = false;
  100. for (let i = 0; i < lastIndex; i++) {
  101. if (subKeys[i] === '__proto__') {
  102. throw new Error(`unsafe key: ${subKeys[i]}`);
  103. }
  104. if (!(subKeys[i] in currentObj)) {
  105. currentObj[subKeys[i]] = create();
  106. }
  107. if (!isObject(currentObj[subKeys[i]])) {
  108. hasStringValue = true;
  109. break;
  110. }
  111. currentObj = currentObj[subKeys[i]];
  112. }
  113. // update last object value, delete old property
  114. if (!hasStringValue) {
  115. if (!isMessageAST(currentObj)) {
  116. currentObj[subKeys[lastIndex]] = obj[key];
  117. delete obj[key];
  118. }
  119. else {
  120. /**
  121. * NOTE:
  122. * if the last object is a message AST and subKeys[lastIndex] has message AST prop key, ignore to copy and key deletion
  123. */
  124. if (!AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
  125. delete obj[key];
  126. }
  127. }
  128. }
  129. // recursive process value if value is also a object
  130. if (!isMessageAST(currentObj)) {
  131. const target = currentObj[subKeys[lastIndex]];
  132. if (isObject(target)) {
  133. handleFlatJson(target);
  134. }
  135. }
  136. }
  137. }
  138. return obj;
  139. }
  140. function getLocaleMessages(locale, options) {
  141. const { messages, __i18n, messageResolver, flatJson } = options;
  142. // prettier-ignore
  143. const ret = (isPlainObject(messages)
  144. ? messages
  145. : isArray(__i18n)
  146. ? create()
  147. : { [locale]: create() });
  148. // merge locale messages of i18n custom block
  149. if (isArray(__i18n)) {
  150. __i18n.forEach(custom => {
  151. if ('locale' in custom && 'resource' in custom) {
  152. const { locale, resource } = custom;
  153. if (locale) {
  154. ret[locale] = ret[locale] || create();
  155. deepCopy(resource, ret[locale]);
  156. }
  157. else {
  158. deepCopy(resource, ret);
  159. }
  160. }
  161. else {
  162. isString(custom) && deepCopy(JSON.parse(custom), ret);
  163. }
  164. });
  165. }
  166. // handle messages for flat json
  167. if (messageResolver == null && flatJson) {
  168. for (const key in ret) {
  169. if (hasOwn(ret, key)) {
  170. handleFlatJson(ret[key]);
  171. }
  172. }
  173. }
  174. return ret;
  175. }
  176. function getComponentOptions(instance) {
  177. return instance.type;
  178. }
  179. function adjustI18nResources(gl, options, componentOptions) {
  180. // prettier-ignore
  181. let messages = isObject(options.messages)
  182. ? options.messages
  183. : create();
  184. if ('__i18nGlobal' in componentOptions) {
  185. messages = getLocaleMessages(gl.locale.value, {
  186. messages,
  187. __i18n: componentOptions.__i18nGlobal
  188. });
  189. }
  190. // merge locale messages
  191. const locales = Object.keys(messages);
  192. if (locales.length) {
  193. locales.forEach(locale => {
  194. gl.mergeLocaleMessage(locale, messages[locale]);
  195. });
  196. }
  197. {
  198. // merge datetime formats
  199. if (isObject(options.datetimeFormats)) {
  200. const locales = Object.keys(options.datetimeFormats);
  201. if (locales.length) {
  202. locales.forEach(locale => {
  203. gl.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
  204. });
  205. }
  206. }
  207. // merge number formats
  208. if (isObject(options.numberFormats)) {
  209. const locales = Object.keys(options.numberFormats);
  210. if (locales.length) {
  211. locales.forEach(locale => {
  212. gl.mergeNumberFormat(locale, options.numberFormats[locale]);
  213. });
  214. }
  215. }
  216. }
  217. }
  218. function createTextNode(key) {
  219. return createVNode(Text, null, key, 0);
  220. }
  221. /* eslint-disable @typescript-eslint/no-explicit-any */
  222. // extend VNode interface
  223. const DEVTOOLS_META = '__INTLIFY_META__';
  224. const NOOP_RETURN_ARRAY = () => [];
  225. const NOOP_RETURN_FALSE = () => false;
  226. let composerID = 0;
  227. function defineCoreMissingHandler(missing) {
  228. return ((ctx, locale, key, type) => {
  229. return missing(locale, key, getCurrentInstance() || undefined, type);
  230. });
  231. }
  232. // for Intlify DevTools
  233. /* #__NO_SIDE_EFFECTS__ */
  234. const getMetaInfo = () => {
  235. const instance = getCurrentInstance();
  236. let meta = null;
  237. return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META])
  238. ? { [DEVTOOLS_META]: meta }
  239. : null;
  240. };
  241. /**
  242. * Create composer interface factory
  243. *
  244. * @internal
  245. */
  246. function createComposer(options = {}) {
  247. const { __root, __injectWithOption } = options;
  248. const _isGlobal = __root === undefined;
  249. const flatJson = options.flatJson;
  250. const _ref = inBrowser ? ref : shallowRef;
  251. let _inheritLocale = isBoolean(options.inheritLocale)
  252. ? options.inheritLocale
  253. : true;
  254. const _locale = _ref(
  255. // prettier-ignore
  256. __root && _inheritLocale
  257. ? __root.locale.value
  258. : isString(options.locale)
  259. ? options.locale
  260. : DEFAULT_LOCALE);
  261. const _fallbackLocale = _ref(
  262. // prettier-ignore
  263. __root && _inheritLocale
  264. ? __root.fallbackLocale.value
  265. : isString(options.fallbackLocale) ||
  266. isArray(options.fallbackLocale) ||
  267. isPlainObject(options.fallbackLocale) ||
  268. options.fallbackLocale === false
  269. ? options.fallbackLocale
  270. : _locale.value);
  271. const _messages = _ref(getLocaleMessages(_locale.value, options));
  272. // prettier-ignore
  273. const _datetimeFormats = _ref(isPlainObject(options.datetimeFormats)
  274. ? options.datetimeFormats
  275. : { [_locale.value]: {} })
  276. ;
  277. // prettier-ignore
  278. const _numberFormats = _ref(isPlainObject(options.numberFormats)
  279. ? options.numberFormats
  280. : { [_locale.value]: {} })
  281. ;
  282. // warning suppress options
  283. // prettier-ignore
  284. let _missingWarn = __root
  285. ? __root.missingWarn
  286. : isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
  287. ? options.missingWarn
  288. : true;
  289. // prettier-ignore
  290. let _fallbackWarn = __root
  291. ? __root.fallbackWarn
  292. : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
  293. ? options.fallbackWarn
  294. : true;
  295. // prettier-ignore
  296. let _fallbackRoot = __root
  297. ? __root.fallbackRoot
  298. : isBoolean(options.fallbackRoot)
  299. ? options.fallbackRoot
  300. : true;
  301. // configure fall back to root
  302. let _fallbackFormat = !!options.fallbackFormat;
  303. // runtime missing
  304. let _missing = isFunction(options.missing) ? options.missing : null;
  305. let _runtimeMissing = isFunction(options.missing)
  306. ? defineCoreMissingHandler(options.missing)
  307. : null;
  308. // postTranslation handler
  309. let _postTranslation = isFunction(options.postTranslation)
  310. ? options.postTranslation
  311. : null;
  312. // prettier-ignore
  313. let _warnHtmlMessage = __root
  314. ? __root.warnHtmlMessage
  315. : isBoolean(options.warnHtmlMessage)
  316. ? options.warnHtmlMessage
  317. : true;
  318. let _escapeParameter = !!options.escapeParameter;
  319. // custom linked modifiers
  320. // prettier-ignore
  321. const _modifiers = __root
  322. ? __root.modifiers
  323. : isPlainObject(options.modifiers)
  324. ? options.modifiers
  325. : {};
  326. // pluralRules
  327. let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
  328. // runtime context
  329. // eslint-disable-next-line prefer-const
  330. let _context;
  331. const getCoreContext = () => {
  332. _isGlobal && setFallbackContext(null);
  333. const ctxOptions = {
  334. version: VERSION,
  335. locale: _locale.value,
  336. fallbackLocale: _fallbackLocale.value,
  337. messages: _messages.value,
  338. modifiers: _modifiers,
  339. pluralRules: _pluralRules,
  340. missing: _runtimeMissing === null ? undefined : _runtimeMissing,
  341. missingWarn: _missingWarn,
  342. fallbackWarn: _fallbackWarn,
  343. fallbackFormat: _fallbackFormat,
  344. unresolving: true,
  345. postTranslation: _postTranslation === null ? undefined : _postTranslation,
  346. warnHtmlMessage: _warnHtmlMessage,
  347. escapeParameter: _escapeParameter,
  348. messageResolver: options.messageResolver,
  349. messageCompiler: options.messageCompiler,
  350. __meta: { framework: 'vue' }
  351. };
  352. {
  353. ctxOptions.datetimeFormats = _datetimeFormats.value;
  354. ctxOptions.numberFormats = _numberFormats.value;
  355. ctxOptions.__datetimeFormatters = isPlainObject(_context)
  356. ? _context.__datetimeFormatters
  357. : undefined;
  358. ctxOptions.__numberFormatters = isPlainObject(_context)
  359. ? _context.__numberFormatters
  360. : undefined;
  361. }
  362. const ctx = createCoreContext(ctxOptions);
  363. _isGlobal && setFallbackContext(ctx);
  364. return ctx;
  365. };
  366. _context = getCoreContext();
  367. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  368. // track reactivity
  369. function trackReactivityValues() {
  370. return [
  371. _locale.value,
  372. _fallbackLocale.value,
  373. _messages.value,
  374. _datetimeFormats.value,
  375. _numberFormats.value
  376. ]
  377. ;
  378. }
  379. // locale
  380. const locale = computed({
  381. get: () => _locale.value,
  382. set: val => {
  383. _context.locale = val;
  384. _locale.value = val;
  385. }
  386. });
  387. // fallbackLocale
  388. const fallbackLocale = computed({
  389. get: () => _fallbackLocale.value,
  390. set: val => {
  391. _context.fallbackLocale = val;
  392. _fallbackLocale.value = val;
  393. updateFallbackLocale(_context, _locale.value, val);
  394. }
  395. });
  396. // messages
  397. const messages = computed(() => _messages.value);
  398. // datetimeFormats
  399. const datetimeFormats = /* #__PURE__*/ computed(() => _datetimeFormats.value);
  400. // numberFormats
  401. const numberFormats = /* #__PURE__*/ computed(() => _numberFormats.value);
  402. // getPostTranslationHandler
  403. function getPostTranslationHandler() {
  404. return isFunction(_postTranslation) ? _postTranslation : null;
  405. }
  406. // setPostTranslationHandler
  407. function setPostTranslationHandler(handler) {
  408. _postTranslation = handler;
  409. _context.postTranslation = handler;
  410. }
  411. // getMissingHandler
  412. function getMissingHandler() {
  413. return _missing;
  414. }
  415. // setMissingHandler
  416. function setMissingHandler(handler) {
  417. if (handler !== null) {
  418. _runtimeMissing = defineCoreMissingHandler(handler);
  419. }
  420. _missing = handler;
  421. _context.missing = _runtimeMissing;
  422. }
  423. const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
  424. trackReactivityValues(); // track reactive dependency
  425. // NOTE: experimental !!
  426. let ret;
  427. try {
  428. if (false || __INTLIFY_PROD_DEVTOOLS__) {
  429. setAdditionalMeta(getMetaInfo());
  430. }
  431. if (!_isGlobal) {
  432. _context.fallbackContext = __root
  433. ? getFallbackContext()
  434. : undefined;
  435. }
  436. ret = fn(_context);
  437. }
  438. finally {
  439. if (__INTLIFY_PROD_DEVTOOLS__) {
  440. setAdditionalMeta(null);
  441. }
  442. if (!_isGlobal) {
  443. _context.fallbackContext = undefined;
  444. }
  445. }
  446. if ((warnType !== 'translate exists' && // for not `te` (e.g `t`)
  447. isNumber(ret) &&
  448. ret === NOT_REOSLVED) ||
  449. (warnType === 'translate exists' && !ret) // for `te`
  450. ) {
  451. const [key, arg2] = argumentParser();
  452. return __root && _fallbackRoot
  453. ? fallbackSuccess(__root)
  454. : fallbackFail(key);
  455. }
  456. else if (successCondition(ret)) {
  457. return ret;
  458. }
  459. else {
  460. /* istanbul ignore next */
  461. throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
  462. }
  463. };
  464. // t
  465. function t(...args) {
  466. return wrapWithDeps(context => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), 'translate', root => Reflect.apply(root.t, root, [...args]), key => key, val => isString(val));
  467. }
  468. // rt
  469. function rt(...args) {
  470. const [arg1, arg2, arg3] = args;
  471. if (arg3 && !isObject(arg3)) {
  472. throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
  473. }
  474. return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
  475. }
  476. // d
  477. function d(...args) {
  478. 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));
  479. }
  480. // n
  481. function n(...args) {
  482. 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));
  483. }
  484. // for custom processor
  485. function normalize(values) {
  486. return values.map(val => isString(val) || isNumber(val) || isBoolean(val)
  487. ? createTextNode(String(val))
  488. : val);
  489. }
  490. const interpolate = (val) => val;
  491. const processor = {
  492. normalize,
  493. interpolate,
  494. type: 'vnode'
  495. };
  496. // translateVNode, using for `i18n-t` component
  497. function translateVNode(...args) {
  498. return wrapWithDeps(context => {
  499. let ret;
  500. const _context = context;
  501. try {
  502. _context.processor = processor;
  503. ret = Reflect.apply(translate, null, [_context, ...args]);
  504. }
  505. finally {
  506. _context.processor = null;
  507. }
  508. return ret;
  509. }, () => parseTranslateArgs(...args), 'translate', root => root[TranslateVNodeSymbol](...args), key => [createTextNode(key)], val => isArray(val));
  510. }
  511. // numberParts, using for `i18n-n` component
  512. function numberParts(...args) {
  513. 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));
  514. }
  515. // datetimeParts, using for `i18n-d` component
  516. function datetimeParts(...args) {
  517. 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));
  518. }
  519. function setPluralRules(rules) {
  520. _pluralRules = rules;
  521. _context.pluralRules = _pluralRules;
  522. }
  523. // te
  524. function te(key, locale) {
  525. return wrapWithDeps(() => {
  526. if (!key) {
  527. return false;
  528. }
  529. const targetLocale = isString(locale) ? locale : _locale.value;
  530. const message = getLocaleMessage(targetLocale);
  531. const resolved = _context.messageResolver(message, key);
  532. return (isMessageAST(resolved) ||
  533. isMessageFunction(resolved) ||
  534. isString(resolved));
  535. }, () => [key], 'translate exists', root => {
  536. return Reflect.apply(root.te, root, [key, locale]);
  537. }, NOOP_RETURN_FALSE, val => isBoolean(val));
  538. }
  539. function resolveMessages(key) {
  540. let messages = null;
  541. const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
  542. for (let i = 0; i < locales.length; i++) {
  543. const targetLocaleMessages = _messages.value[locales[i]] || {};
  544. const messageValue = _context.messageResolver(targetLocaleMessages, key);
  545. if (messageValue != null) {
  546. messages = messageValue;
  547. break;
  548. }
  549. }
  550. return messages;
  551. }
  552. // tm
  553. function tm(key) {
  554. const messages = resolveMessages(key);
  555. // prettier-ignore
  556. return messages != null
  557. ? messages
  558. : __root
  559. ? __root.tm(key) || {}
  560. : {};
  561. }
  562. // getLocaleMessage
  563. function getLocaleMessage(locale) {
  564. return (_messages.value[locale] || {});
  565. }
  566. // setLocaleMessage
  567. function setLocaleMessage(locale, message) {
  568. if (flatJson) {
  569. const _message = { [locale]: message };
  570. for (const key in _message) {
  571. if (hasOwn(_message, key)) {
  572. handleFlatJson(_message[key]);
  573. }
  574. }
  575. message = _message[locale];
  576. }
  577. _messages.value[locale] = message;
  578. _context.messages = _messages.value;
  579. }
  580. // mergeLocaleMessage
  581. function mergeLocaleMessage(locale, message) {
  582. _messages.value[locale] = _messages.value[locale] || {};
  583. const _message = { [locale]: message };
  584. if (flatJson) {
  585. for (const key in _message) {
  586. if (hasOwn(_message, key)) {
  587. handleFlatJson(_message[key]);
  588. }
  589. }
  590. }
  591. message = _message[locale];
  592. deepCopy(message, _messages.value[locale]);
  593. _context.messages = _messages.value;
  594. }
  595. // getDateTimeFormat
  596. function getDateTimeFormat(locale) {
  597. return _datetimeFormats.value[locale] || {};
  598. }
  599. // setDateTimeFormat
  600. function setDateTimeFormat(locale, format) {
  601. _datetimeFormats.value[locale] = format;
  602. _context.datetimeFormats = _datetimeFormats.value;
  603. clearDateTimeFormat(_context, locale, format);
  604. }
  605. // mergeDateTimeFormat
  606. function mergeDateTimeFormat(locale, format) {
  607. _datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format);
  608. _context.datetimeFormats = _datetimeFormats.value;
  609. clearDateTimeFormat(_context, locale, format);
  610. }
  611. // getNumberFormat
  612. function getNumberFormat(locale) {
  613. return _numberFormats.value[locale] || {};
  614. }
  615. // setNumberFormat
  616. function setNumberFormat(locale, format) {
  617. _numberFormats.value[locale] = format;
  618. _context.numberFormats = _numberFormats.value;
  619. clearNumberFormat(_context, locale, format);
  620. }
  621. // mergeNumberFormat
  622. function mergeNumberFormat(locale, format) {
  623. _numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format);
  624. _context.numberFormats = _numberFormats.value;
  625. clearNumberFormat(_context, locale, format);
  626. }
  627. // for debug
  628. composerID++;
  629. // watch root locale & fallbackLocale
  630. if (__root && inBrowser) {
  631. watch(__root.locale, (val) => {
  632. if (_inheritLocale) {
  633. _locale.value = val;
  634. _context.locale = val;
  635. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  636. }
  637. });
  638. watch(__root.fallbackLocale, (val) => {
  639. if (_inheritLocale) {
  640. _fallbackLocale.value = val;
  641. _context.fallbackLocale = val;
  642. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  643. }
  644. });
  645. }
  646. // define basic composition API!
  647. const composer = {
  648. id: composerID,
  649. locale,
  650. fallbackLocale,
  651. get inheritLocale() {
  652. return _inheritLocale;
  653. },
  654. set inheritLocale(val) {
  655. _inheritLocale = val;
  656. if (val && __root) {
  657. _locale.value = __root.locale.value;
  658. _fallbackLocale.value = __root.fallbackLocale.value;
  659. updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
  660. }
  661. },
  662. get availableLocales() {
  663. return Object.keys(_messages.value).sort();
  664. },
  665. messages,
  666. get modifiers() {
  667. return _modifiers;
  668. },
  669. get pluralRules() {
  670. return _pluralRules || {};
  671. },
  672. get isGlobal() {
  673. return _isGlobal;
  674. },
  675. get missingWarn() {
  676. return _missingWarn;
  677. },
  678. set missingWarn(val) {
  679. _missingWarn = val;
  680. _context.missingWarn = _missingWarn;
  681. },
  682. get fallbackWarn() {
  683. return _fallbackWarn;
  684. },
  685. set fallbackWarn(val) {
  686. _fallbackWarn = val;
  687. _context.fallbackWarn = _fallbackWarn;
  688. },
  689. get fallbackRoot() {
  690. return _fallbackRoot;
  691. },
  692. set fallbackRoot(val) {
  693. _fallbackRoot = val;
  694. },
  695. get fallbackFormat() {
  696. return _fallbackFormat;
  697. },
  698. set fallbackFormat(val) {
  699. _fallbackFormat = val;
  700. _context.fallbackFormat = _fallbackFormat;
  701. },
  702. get warnHtmlMessage() {
  703. return _warnHtmlMessage;
  704. },
  705. set warnHtmlMessage(val) {
  706. _warnHtmlMessage = val;
  707. _context.warnHtmlMessage = val;
  708. },
  709. get escapeParameter() {
  710. return _escapeParameter;
  711. },
  712. set escapeParameter(val) {
  713. _escapeParameter = val;
  714. _context.escapeParameter = val;
  715. },
  716. t,
  717. getLocaleMessage,
  718. setLocaleMessage,
  719. mergeLocaleMessage,
  720. getPostTranslationHandler,
  721. setPostTranslationHandler,
  722. getMissingHandler,
  723. setMissingHandler,
  724. [SetPluralRulesSymbol]: setPluralRules
  725. };
  726. {
  727. composer.datetimeFormats = datetimeFormats;
  728. composer.numberFormats = numberFormats;
  729. composer.rt = rt;
  730. composer.te = te;
  731. composer.tm = tm;
  732. composer.d = d;
  733. composer.n = n;
  734. composer.getDateTimeFormat = getDateTimeFormat;
  735. composer.setDateTimeFormat = setDateTimeFormat;
  736. composer.mergeDateTimeFormat = mergeDateTimeFormat;
  737. composer.getNumberFormat = getNumberFormat;
  738. composer.setNumberFormat = setNumberFormat;
  739. composer.mergeNumberFormat = mergeNumberFormat;
  740. composer[InejctWithOptionSymbol] = __injectWithOption;
  741. composer[TranslateVNodeSymbol] = translateVNode;
  742. composer[DatetimePartsSymbol] = datetimeParts;
  743. composer[NumberPartsSymbol] = numberParts;
  744. }
  745. return composer;
  746. }
  747. /* eslint-enable @typescript-eslint/no-explicit-any */
  748. /* eslint-disable @typescript-eslint/no-explicit-any */
  749. /**
  750. * Convert to I18n Composer Options from VueI18n Options
  751. *
  752. * @internal
  753. */
  754. function convertComposerOptions(options) {
  755. const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
  756. const fallbackLocale = isString(options.fallbackLocale) ||
  757. isArray(options.fallbackLocale) ||
  758. isPlainObject(options.fallbackLocale) ||
  759. options.fallbackLocale === false
  760. ? options.fallbackLocale
  761. : locale;
  762. const missing = isFunction(options.missing) ? options.missing : undefined;
  763. const missingWarn = isBoolean(options.silentTranslationWarn) ||
  764. isRegExp(options.silentTranslationWarn)
  765. ? !options.silentTranslationWarn
  766. : true;
  767. const fallbackWarn = isBoolean(options.silentFallbackWarn) ||
  768. isRegExp(options.silentFallbackWarn)
  769. ? !options.silentFallbackWarn
  770. : true;
  771. const fallbackRoot = isBoolean(options.fallbackRoot)
  772. ? options.fallbackRoot
  773. : true;
  774. const fallbackFormat = !!options.formatFallbackMessages;
  775. const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {};
  776. const pluralizationRules = options.pluralizationRules;
  777. const postTranslation = isFunction(options.postTranslation)
  778. ? options.postTranslation
  779. : undefined;
  780. const warnHtmlMessage = isString(options.warnHtmlInMessage)
  781. ? options.warnHtmlInMessage !== 'off'
  782. : true;
  783. const escapeParameter = !!options.escapeParameterHtml;
  784. const inheritLocale = isBoolean(options.sync) ? options.sync : true;
  785. let messages = options.messages;
  786. if (isPlainObject(options.sharedMessages)) {
  787. const sharedMessages = options.sharedMessages;
  788. const locales = Object.keys(sharedMessages);
  789. messages = locales.reduce((messages, locale) => {
  790. const message = messages[locale] || (messages[locale] = {});
  791. assign(message, sharedMessages[locale]);
  792. return messages;
  793. }, (messages || {}));
  794. }
  795. const { __i18n, __root, __injectWithOption } = options;
  796. const datetimeFormats = options.datetimeFormats;
  797. const numberFormats = options.numberFormats;
  798. const flatJson = options.flatJson;
  799. return {
  800. locale,
  801. fallbackLocale,
  802. messages,
  803. flatJson,
  804. datetimeFormats,
  805. numberFormats,
  806. missing,
  807. missingWarn,
  808. fallbackWarn,
  809. fallbackRoot,
  810. fallbackFormat,
  811. modifiers,
  812. pluralRules: pluralizationRules,
  813. postTranslation,
  814. warnHtmlMessage,
  815. escapeParameter,
  816. messageResolver: options.messageResolver,
  817. inheritLocale,
  818. __i18n,
  819. __root,
  820. __injectWithOption
  821. };
  822. }
  823. /**
  824. * create VueI18n interface factory
  825. *
  826. * @internal
  827. *
  828. * @deprecated will be removed at vue-i18n v12
  829. */
  830. function createVueI18n(options = {}) {
  831. const composer = createComposer(convertComposerOptions(options));
  832. const { __extender } = options;
  833. // defines VueI18n
  834. const vueI18n = {
  835. // id
  836. id: composer.id,
  837. // locale
  838. get locale() {
  839. return composer.locale.value;
  840. },
  841. set locale(val) {
  842. composer.locale.value = val;
  843. },
  844. // fallbackLocale
  845. get fallbackLocale() {
  846. return composer.fallbackLocale.value;
  847. },
  848. set fallbackLocale(val) {
  849. composer.fallbackLocale.value = val;
  850. },
  851. // messages
  852. get messages() {
  853. return composer.messages.value;
  854. },
  855. // datetimeFormats
  856. get datetimeFormats() {
  857. return composer.datetimeFormats.value;
  858. },
  859. // numberFormats
  860. get numberFormats() {
  861. return composer.numberFormats.value;
  862. },
  863. // availableLocales
  864. get availableLocales() {
  865. return composer.availableLocales;
  866. },
  867. // missing
  868. get missing() {
  869. return composer.getMissingHandler();
  870. },
  871. set missing(handler) {
  872. composer.setMissingHandler(handler);
  873. },
  874. // silentTranslationWarn
  875. get silentTranslationWarn() {
  876. return isBoolean(composer.missingWarn)
  877. ? !composer.missingWarn
  878. : composer.missingWarn;
  879. },
  880. set silentTranslationWarn(val) {
  881. composer.missingWarn = isBoolean(val) ? !val : val;
  882. },
  883. // silentFallbackWarn
  884. get silentFallbackWarn() {
  885. return isBoolean(composer.fallbackWarn)
  886. ? !composer.fallbackWarn
  887. : composer.fallbackWarn;
  888. },
  889. set silentFallbackWarn(val) {
  890. composer.fallbackWarn = isBoolean(val) ? !val : val;
  891. },
  892. // modifiers
  893. get modifiers() {
  894. return composer.modifiers;
  895. },
  896. // formatFallbackMessages
  897. get formatFallbackMessages() {
  898. return composer.fallbackFormat;
  899. },
  900. set formatFallbackMessages(val) {
  901. composer.fallbackFormat = val;
  902. },
  903. // postTranslation
  904. get postTranslation() {
  905. return composer.getPostTranslationHandler();
  906. },
  907. set postTranslation(handler) {
  908. composer.setPostTranslationHandler(handler);
  909. },
  910. // sync
  911. get sync() {
  912. return composer.inheritLocale;
  913. },
  914. set sync(val) {
  915. composer.inheritLocale = val;
  916. },
  917. // warnInHtmlMessage
  918. get warnHtmlInMessage() {
  919. return composer.warnHtmlMessage ? 'warn' : 'off';
  920. },
  921. set warnHtmlInMessage(val) {
  922. composer.warnHtmlMessage = val !== 'off';
  923. },
  924. // escapeParameterHtml
  925. get escapeParameterHtml() {
  926. return composer.escapeParameter;
  927. },
  928. set escapeParameterHtml(val) {
  929. composer.escapeParameter = val;
  930. },
  931. // pluralizationRules
  932. get pluralizationRules() {
  933. return composer.pluralRules || {};
  934. },
  935. // for internal
  936. __composer: composer,
  937. // t
  938. t(...args) {
  939. return Reflect.apply(composer.t, composer, [...args]);
  940. },
  941. // rt
  942. rt(...args) {
  943. return Reflect.apply(composer.rt, composer, [...args]);
  944. },
  945. // te
  946. te(key, locale) {
  947. return composer.te(key, locale);
  948. },
  949. // tm
  950. tm(key) {
  951. return composer.tm(key);
  952. },
  953. // getLocaleMessage
  954. getLocaleMessage(locale) {
  955. return composer.getLocaleMessage(locale);
  956. },
  957. // setLocaleMessage
  958. setLocaleMessage(locale, message) {
  959. composer.setLocaleMessage(locale, message);
  960. },
  961. // mergeLocaleMessage
  962. mergeLocaleMessage(locale, message) {
  963. composer.mergeLocaleMessage(locale, message);
  964. },
  965. // d
  966. d(...args) {
  967. return Reflect.apply(composer.d, composer, [...args]);
  968. },
  969. // getDateTimeFormat
  970. getDateTimeFormat(locale) {
  971. return composer.getDateTimeFormat(locale);
  972. },
  973. // setDateTimeFormat
  974. setDateTimeFormat(locale, format) {
  975. composer.setDateTimeFormat(locale, format);
  976. },
  977. // mergeDateTimeFormat
  978. mergeDateTimeFormat(locale, format) {
  979. composer.mergeDateTimeFormat(locale, format);
  980. },
  981. // n
  982. n(...args) {
  983. return Reflect.apply(composer.n, composer, [...args]);
  984. },
  985. // getNumberFormat
  986. getNumberFormat(locale) {
  987. return composer.getNumberFormat(locale);
  988. },
  989. // setNumberFormat
  990. setNumberFormat(locale, format) {
  991. composer.setNumberFormat(locale, format);
  992. },
  993. // mergeNumberFormat
  994. mergeNumberFormat(locale, format) {
  995. composer.mergeNumberFormat(locale, format);
  996. }
  997. };
  998. vueI18n.__extender = __extender;
  999. return vueI18n;
  1000. }
  1001. /* eslint-enable @typescript-eslint/no-explicit-any */
  1002. /**
  1003. * Supports compatibility for legacy vue-i18n APIs
  1004. * This mixin is used when we use vue-i18n@v9.x or later
  1005. */
  1006. function defineMixin(vuei18n, composer, i18n) {
  1007. return {
  1008. beforeCreate() {
  1009. const instance = getCurrentInstance();
  1010. /* istanbul ignore if */
  1011. if (!instance) {
  1012. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1013. }
  1014. const options = this.$options;
  1015. if (options.i18n) {
  1016. const optionsI18n = options.i18n;
  1017. if (options.__i18n) {
  1018. optionsI18n.__i18n = options.__i18n;
  1019. }
  1020. optionsI18n.__root = composer;
  1021. if (this === this.$root) {
  1022. // merge option and gttach global
  1023. this.$i18n = mergeToGlobal(vuei18n, optionsI18n);
  1024. }
  1025. else {
  1026. optionsI18n.__injectWithOption = true;
  1027. optionsI18n.__extender = i18n.__vueI18nExtend;
  1028. // atttach local VueI18n instance
  1029. this.$i18n = createVueI18n(optionsI18n);
  1030. // extend VueI18n instance
  1031. const _vueI18n = this.$i18n;
  1032. if (_vueI18n.__extender) {
  1033. _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
  1034. }
  1035. }
  1036. }
  1037. else if (options.__i18n) {
  1038. if (this === this.$root) {
  1039. // merge option and gttach global
  1040. this.$i18n = mergeToGlobal(vuei18n, options);
  1041. }
  1042. else {
  1043. // atttach local VueI18n instance
  1044. this.$i18n = createVueI18n({
  1045. __i18n: options.__i18n,
  1046. __injectWithOption: true,
  1047. __extender: i18n.__vueI18nExtend,
  1048. __root: composer
  1049. });
  1050. // extend VueI18n instance
  1051. const _vueI18n = this.$i18n;
  1052. if (_vueI18n.__extender) {
  1053. _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
  1054. }
  1055. }
  1056. }
  1057. else {
  1058. // attach global VueI18n instance
  1059. this.$i18n = vuei18n;
  1060. }
  1061. if (options.__i18nGlobal) {
  1062. adjustI18nResources(composer, options, options);
  1063. }
  1064. // defines vue-i18n legacy APIs
  1065. this.$t = (...args) => this.$i18n.t(...args);
  1066. this.$rt = (...args) => this.$i18n.rt(...args);
  1067. this.$te = (key, locale) => this.$i18n.te(key, locale);
  1068. this.$d = (...args) => this.$i18n.d(...args);
  1069. this.$n = (...args) => this.$i18n.n(...args);
  1070. this.$tm = (key) => this.$i18n.tm(key);
  1071. i18n.__setInstance(instance, this.$i18n);
  1072. },
  1073. mounted() {
  1074. },
  1075. unmounted() {
  1076. const instance = getCurrentInstance();
  1077. /* istanbul ignore if */
  1078. if (!instance) {
  1079. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1080. }
  1081. const _vueI18n = this.$i18n;
  1082. delete this.$t;
  1083. delete this.$rt;
  1084. delete this.$te;
  1085. delete this.$d;
  1086. delete this.$n;
  1087. delete this.$tm;
  1088. if (_vueI18n.__disposer) {
  1089. _vueI18n.__disposer();
  1090. delete _vueI18n.__disposer;
  1091. delete _vueI18n.__extender;
  1092. }
  1093. i18n.__deleteInstance(instance);
  1094. delete this.$i18n;
  1095. }
  1096. };
  1097. }
  1098. function mergeToGlobal(g, options) {
  1099. g.locale = options.locale || g.locale;
  1100. g.fallbackLocale = options.fallbackLocale || g.fallbackLocale;
  1101. g.missing = options.missing || g.missing;
  1102. g.silentTranslationWarn =
  1103. options.silentTranslationWarn || g.silentFallbackWarn;
  1104. g.silentFallbackWarn = options.silentFallbackWarn || g.silentFallbackWarn;
  1105. g.formatFallbackMessages =
  1106. options.formatFallbackMessages || g.formatFallbackMessages;
  1107. g.postTranslation = options.postTranslation || g.postTranslation;
  1108. g.warnHtmlInMessage = options.warnHtmlInMessage || g.warnHtmlInMessage;
  1109. g.escapeParameterHtml = options.escapeParameterHtml || g.escapeParameterHtml;
  1110. g.sync = options.sync || g.sync;
  1111. g.__composer[SetPluralRulesSymbol](options.pluralizationRules || g.pluralizationRules);
  1112. const messages = getLocaleMessages(g.locale, {
  1113. messages: options.messages,
  1114. __i18n: options.__i18n
  1115. });
  1116. Object.keys(messages).forEach(locale => g.mergeLocaleMessage(locale, messages[locale]));
  1117. if (options.datetimeFormats) {
  1118. Object.keys(options.datetimeFormats).forEach(locale => g.mergeDateTimeFormat(locale, options.datetimeFormats[locale]));
  1119. }
  1120. if (options.numberFormats) {
  1121. Object.keys(options.numberFormats).forEach(locale => g.mergeNumberFormat(locale, options.numberFormats[locale]));
  1122. }
  1123. return g;
  1124. }
  1125. const baseFormatProps = {
  1126. tag: {
  1127. type: [String, Object]
  1128. },
  1129. locale: {
  1130. type: String
  1131. },
  1132. scope: {
  1133. type: String,
  1134. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  1135. validator: (val /* ComponentI18nScope */) => val === 'parent' || val === 'global',
  1136. default: 'parent' /* ComponentI18nScope */
  1137. },
  1138. i18n: {
  1139. type: Object
  1140. }
  1141. };
  1142. function getInterpolateArg(
  1143. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1144. { slots }, // SetupContext,
  1145. keys) {
  1146. if (keys.length === 1 && keys[0] === 'default') {
  1147. // default slot with list
  1148. const ret = slots.default ? slots.default() : [];
  1149. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1150. return ret.reduce((slot, current) => {
  1151. return [
  1152. ...slot,
  1153. // prettier-ignore
  1154. ...(current.type === Fragment ? current.children : [current])
  1155. ];
  1156. }, []);
  1157. }
  1158. else {
  1159. // named slots
  1160. return keys.reduce((arg, key) => {
  1161. const slot = slots[key];
  1162. if (slot) {
  1163. arg[key] = slot();
  1164. }
  1165. return arg;
  1166. }, create());
  1167. }
  1168. }
  1169. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1170. function getFragmentableTag() {
  1171. return Fragment;
  1172. }
  1173. const TranslationImpl = /*#__PURE__*/ defineComponent({
  1174. /* eslint-disable */
  1175. name: 'i18n-t',
  1176. props: assign({
  1177. keypath: {
  1178. type: String,
  1179. required: true
  1180. },
  1181. plural: {
  1182. type: [Number, String],
  1183. validator: (val) => isNumber(val) || !isNaN(val)
  1184. }
  1185. }, baseFormatProps),
  1186. /* eslint-enable */
  1187. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1188. setup(props, context) {
  1189. const { slots, attrs } = context;
  1190. // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
  1191. const i18n = props.i18n ||
  1192. useI18n({
  1193. useScope: props.scope,
  1194. __useComponent: true
  1195. });
  1196. return () => {
  1197. const keys = Object.keys(slots).filter(key => key !== '_');
  1198. const options = create();
  1199. if (props.locale) {
  1200. options.locale = props.locale;
  1201. }
  1202. if (props.plural !== undefined) {
  1203. options.plural = isString(props.plural) ? +props.plural : props.plural;
  1204. }
  1205. const arg = getInterpolateArg(context, keys);
  1206. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1207. const children = i18n[TranslateVNodeSymbol](props.keypath, arg, options);
  1208. const assignedAttrs = assign(create(), attrs);
  1209. const tag = isString(props.tag) || isObject(props.tag)
  1210. ? props.tag
  1211. : getFragmentableTag();
  1212. return h(tag, assignedAttrs, children);
  1213. };
  1214. }
  1215. });
  1216. /**
  1217. * export the public type for h/tsx inference
  1218. * also to avoid inline import() in generated d.ts files
  1219. */
  1220. /**
  1221. * Translation Component
  1222. *
  1223. * @remarks
  1224. * See the following items for property about details
  1225. *
  1226. * @VueI18nSee [TranslationProps](component#translationprops)
  1227. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  1228. * @VueI18nSee [Component Interpolation](../guide/advanced/component)
  1229. *
  1230. * @example
  1231. * ```html
  1232. * <div id="app">
  1233. * <!-- ... -->
  1234. * <i18n keypath="term" tag="label" for="tos">
  1235. * <a :href="url" target="_blank">{{ $t('tos') }}</a>
  1236. * </i18n>
  1237. * <!-- ... -->
  1238. * </div>
  1239. * ```
  1240. * ```js
  1241. * import { createApp } from 'vue'
  1242. * import { createI18n } from 'vue-i18n'
  1243. *
  1244. * const messages = {
  1245. * en: {
  1246. * tos: 'Term of Service',
  1247. * term: 'I accept xxx {0}.'
  1248. * },
  1249. * ja: {
  1250. * tos: '利用規約',
  1251. * term: '私は xxx の{0}に同意します。'
  1252. * }
  1253. * }
  1254. *
  1255. * const i18n = createI18n({
  1256. * locale: 'en',
  1257. * messages
  1258. * })
  1259. *
  1260. * const app = createApp({
  1261. * data: {
  1262. * url: '/term'
  1263. * }
  1264. * }).use(i18n).mount('#app')
  1265. * ```
  1266. *
  1267. * @VueI18nComponent
  1268. */
  1269. const Translation = TranslationImpl;
  1270. const I18nT = Translation;
  1271. function isVNode(target) {
  1272. return isArray(target) && !isString(target[0]);
  1273. }
  1274. function renderFormatter(props, context, slotKeys, partFormatter) {
  1275. const { slots, attrs } = context;
  1276. return () => {
  1277. const options = { part: true };
  1278. let overrides = create();
  1279. if (props.locale) {
  1280. options.locale = props.locale;
  1281. }
  1282. if (isString(props.format)) {
  1283. options.key = props.format;
  1284. }
  1285. else if (isObject(props.format)) {
  1286. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1287. if (isString(props.format.key)) {
  1288. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1289. options.key = props.format.key;
  1290. }
  1291. // Filter out number format options only
  1292. overrides = Object.keys(props.format).reduce((options, prop) => {
  1293. return slotKeys.includes(prop)
  1294. ? assign(create(), options, { [prop]: props.format[prop] }) // eslint-disable-line @typescript-eslint/no-explicit-any
  1295. : options;
  1296. }, create());
  1297. }
  1298. const parts = partFormatter(...[props.value, options, overrides]);
  1299. let children = [options.key];
  1300. if (isArray(parts)) {
  1301. children = parts.map((part, index) => {
  1302. const slot = slots[part.type];
  1303. const node = slot
  1304. ? slot({ [part.type]: part.value, index, parts })
  1305. : [part.value];
  1306. if (isVNode(node)) {
  1307. node[0].key = `${part.type}-${index}`;
  1308. }
  1309. return node;
  1310. });
  1311. }
  1312. else if (isString(parts)) {
  1313. children = [parts];
  1314. }
  1315. const assignedAttrs = assign(create(), attrs);
  1316. const tag = isString(props.tag) || isObject(props.tag)
  1317. ? props.tag
  1318. : getFragmentableTag();
  1319. return h(tag, assignedAttrs, children);
  1320. };
  1321. }
  1322. const NumberFormatImpl = /*#__PURE__*/ defineComponent({
  1323. /* eslint-disable */
  1324. name: 'i18n-n',
  1325. props: assign({
  1326. value: {
  1327. type: Number,
  1328. required: true
  1329. },
  1330. format: {
  1331. type: [String, Object]
  1332. }
  1333. }, baseFormatProps),
  1334. /* eslint-enable */
  1335. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1336. setup(props, context) {
  1337. const i18n = props.i18n ||
  1338. useI18n({
  1339. useScope: props.scope,
  1340. __useComponent: true
  1341. });
  1342. return renderFormatter(props, context, NUMBER_FORMAT_OPTIONS_KEYS, (...args) =>
  1343. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1344. i18n[NumberPartsSymbol](...args));
  1345. }
  1346. });
  1347. /**
  1348. * export the public type for h/tsx inference
  1349. * also to avoid inline import() in generated d.ts files
  1350. */
  1351. /**
  1352. * Number Format Component
  1353. *
  1354. * @remarks
  1355. * See the following items for property about details
  1356. *
  1357. * @VueI18nSee [FormattableProps](component#formattableprops)
  1358. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  1359. * @VueI18nSee [Custom Formatting](../guide/essentials/number#custom-formatting)
  1360. *
  1361. * @VueI18nDanger
  1362. * 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)
  1363. *
  1364. * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat)
  1365. *
  1366. * @VueI18nComponent
  1367. */
  1368. const NumberFormat = NumberFormatImpl;
  1369. const I18nN = NumberFormat;
  1370. function getComposer$1(i18n, instance) {
  1371. const i18nInternal = i18n;
  1372. if (i18n.mode === 'composition') {
  1373. return (i18nInternal.__getInstance(instance) || i18n.global);
  1374. }
  1375. else {
  1376. const vueI18n = i18nInternal.__getInstance(instance);
  1377. return vueI18n != null
  1378. ? vueI18n.__composer
  1379. : i18n.global.__composer;
  1380. }
  1381. }
  1382. /**
  1383. * @deprecated will be removed at vue-i18n v12
  1384. */
  1385. function vTDirective(i18n) {
  1386. const _process = (binding) => {
  1387. const { instance, value } = binding;
  1388. /* istanbul ignore if */
  1389. if (!instance || !instance.$) {
  1390. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1391. }
  1392. const composer = getComposer$1(i18n, instance.$);
  1393. const parsedValue = parseValue(value);
  1394. return [
  1395. Reflect.apply(composer.t, composer, [...makeParams(parsedValue)]),
  1396. composer
  1397. ];
  1398. };
  1399. const register = (el, binding) => {
  1400. const [textContent, composer] = _process(binding);
  1401. if (inBrowser && i18n.global === composer) {
  1402. // global scope only
  1403. el.__i18nWatcher = watch(composer.locale, () => {
  1404. binding.instance && binding.instance.$forceUpdate();
  1405. });
  1406. }
  1407. el.__composer = composer;
  1408. el.textContent = textContent;
  1409. };
  1410. const unregister = (el) => {
  1411. if (inBrowser && el.__i18nWatcher) {
  1412. el.__i18nWatcher();
  1413. el.__i18nWatcher = undefined;
  1414. delete el.__i18nWatcher;
  1415. }
  1416. if (el.__composer) {
  1417. el.__composer = undefined;
  1418. delete el.__composer;
  1419. }
  1420. };
  1421. const update = (el, { value }) => {
  1422. if (el.__composer) {
  1423. const composer = el.__composer;
  1424. const parsedValue = parseValue(value);
  1425. el.textContent = Reflect.apply(composer.t, composer, [
  1426. ...makeParams(parsedValue)
  1427. ]);
  1428. }
  1429. };
  1430. const getSSRProps = (binding) => {
  1431. const [textContent] = _process(binding);
  1432. return { textContent };
  1433. };
  1434. return {
  1435. created: register,
  1436. unmounted: unregister,
  1437. beforeUpdate: update,
  1438. getSSRProps
  1439. };
  1440. }
  1441. function parseValue(value) {
  1442. if (isString(value)) {
  1443. return { path: value };
  1444. }
  1445. else if (isPlainObject(value)) {
  1446. if (!('path' in value)) {
  1447. throw createI18nError(I18nErrorCodes.REQUIRED_VALUE, 'path');
  1448. }
  1449. return value;
  1450. }
  1451. else {
  1452. throw createI18nError(I18nErrorCodes.INVALID_VALUE);
  1453. }
  1454. }
  1455. function makeParams(value) {
  1456. const { path, locale, args, choice, plural } = value;
  1457. const options = {};
  1458. const named = args || {};
  1459. if (isString(locale)) {
  1460. options.locale = locale;
  1461. }
  1462. if (isNumber(choice)) {
  1463. options.plural = choice;
  1464. }
  1465. if (isNumber(plural)) {
  1466. options.plural = plural;
  1467. }
  1468. return [path, named, options];
  1469. }
  1470. function apply(app, i18n, ...options) {
  1471. const pluginOptions = isPlainObject(options[0])
  1472. ? options[0]
  1473. : {};
  1474. const globalInstall = isBoolean(pluginOptions.globalInstall)
  1475. ? pluginOptions.globalInstall
  1476. : true;
  1477. if (globalInstall) {
  1478. [Translation.name, 'I18nT'].forEach(name => app.component(name, Translation));
  1479. [NumberFormat.name, 'I18nN'].forEach(name => app.component(name, NumberFormat));
  1480. [DatetimeFormat.name, 'I18nD'].forEach(name => app.component(name, DatetimeFormat));
  1481. }
  1482. // install directive
  1483. {
  1484. app.directive('t', vTDirective(i18n));
  1485. }
  1486. }
  1487. /**
  1488. * Injection key for {@link useI18n}
  1489. *
  1490. * @remarks
  1491. * The global injection key for I18n instances with `useI18n`. this injection key is used in Web Components.
  1492. * Specify the i18n instance created by {@link createI18n} together with `provide` function.
  1493. *
  1494. * @VueI18nGeneral
  1495. */
  1496. const I18nInjectionKey =
  1497. /* #__PURE__*/ makeSymbol('global-vue-i18n');
  1498. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1499. function createI18n(options = {}) {
  1500. // prettier-ignore
  1501. const __legacyMode = __VUE_I18N_LEGACY_API__ && isBoolean(options.legacy)
  1502. ? options.legacy
  1503. : __VUE_I18N_LEGACY_API__;
  1504. // prettier-ignore
  1505. const __globalInjection = isBoolean(options.globalInjection)
  1506. ? options.globalInjection
  1507. : true;
  1508. const __instances = new Map();
  1509. const [globalScope, __global] = createGlobal(options, __legacyMode);
  1510. const symbol = /* #__PURE__*/ makeSymbol('');
  1511. function __getInstance(component) {
  1512. return __instances.get(component) || null;
  1513. }
  1514. function __setInstance(component, instance) {
  1515. __instances.set(component, instance);
  1516. }
  1517. function __deleteInstance(component) {
  1518. __instances.delete(component);
  1519. }
  1520. const i18n = {
  1521. // mode
  1522. get mode() {
  1523. return __VUE_I18N_LEGACY_API__ && __legacyMode
  1524. ? 'legacy'
  1525. : 'composition';
  1526. },
  1527. // install plugin
  1528. async install(app, ...options) {
  1529. // setup global provider
  1530. app.__VUE_I18N_SYMBOL__ = symbol;
  1531. app.provide(app.__VUE_I18N_SYMBOL__, i18n);
  1532. // set composer & vuei18n extend hook options from plugin options
  1533. if (isPlainObject(options[0])) {
  1534. const opts = options[0];
  1535. i18n.__composerExtend =
  1536. opts.__composerExtend;
  1537. i18n.__vueI18nExtend =
  1538. opts.__vueI18nExtend;
  1539. }
  1540. // global method and properties injection for Composition API
  1541. let globalReleaseHandler = null;
  1542. if (!__legacyMode && __globalInjection) {
  1543. globalReleaseHandler = injectGlobalFields(app, i18n.global);
  1544. }
  1545. // install built-in components and directive
  1546. if (__VUE_I18N_FULL_INSTALL__) {
  1547. apply(app, i18n, ...options);
  1548. }
  1549. // setup mixin for Legacy API
  1550. if (__VUE_I18N_LEGACY_API__ && __legacyMode) {
  1551. app.mixin(defineMixin(__global, __global.__composer, i18n));
  1552. }
  1553. // release global scope
  1554. const unmountApp = app.unmount;
  1555. app.unmount = () => {
  1556. globalReleaseHandler && globalReleaseHandler();
  1557. i18n.dispose();
  1558. unmountApp();
  1559. };
  1560. },
  1561. // global accessor
  1562. get global() {
  1563. return __global;
  1564. },
  1565. dispose() {
  1566. globalScope.stop();
  1567. },
  1568. // @internal
  1569. __instances,
  1570. // @internal
  1571. __getInstance,
  1572. // @internal
  1573. __setInstance,
  1574. // @internal
  1575. __deleteInstance
  1576. };
  1577. return i18n;
  1578. }
  1579. function useI18n(options = {}) {
  1580. const instance = getCurrentInstance();
  1581. if (instance == null) {
  1582. throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
  1583. }
  1584. if (!instance.isCE &&
  1585. instance.appContext.app != null &&
  1586. !instance.appContext.app.__VUE_I18N_SYMBOL__) {
  1587. throw createI18nError(I18nErrorCodes.NOT_INSTALLED);
  1588. }
  1589. const i18n = getI18nInstance(instance);
  1590. const gl = getGlobalComposer(i18n);
  1591. const componentOptions = getComponentOptions(instance);
  1592. const scope = getScope(options, componentOptions);
  1593. if (scope === 'global') {
  1594. adjustI18nResources(gl, options, componentOptions);
  1595. return gl;
  1596. }
  1597. if (scope === 'parent') {
  1598. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1599. let composer = getComposer(i18n, instance, options.__useComponent);
  1600. if (composer == null) {
  1601. composer = gl;
  1602. }
  1603. return composer;
  1604. }
  1605. const i18nInternal = i18n;
  1606. let composer = i18nInternal.__getInstance(instance);
  1607. if (composer == null) {
  1608. const composerOptions = assign({}, options);
  1609. if ('__i18n' in componentOptions) {
  1610. composerOptions.__i18n = componentOptions.__i18n;
  1611. }
  1612. if (gl) {
  1613. composerOptions.__root = gl;
  1614. }
  1615. composer = createComposer(composerOptions);
  1616. if (i18nInternal.__composerExtend) {
  1617. composer[DisposeSymbol] =
  1618. i18nInternal.__composerExtend(composer);
  1619. }
  1620. setupLifeCycle(i18nInternal, instance, composer);
  1621. i18nInternal.__setInstance(instance, composer);
  1622. }
  1623. return composer;
  1624. }
  1625. function createGlobal(options, legacyMode) {
  1626. const scope = effectScope();
  1627. const obj = __VUE_I18N_LEGACY_API__ && legacyMode
  1628. ? scope.run(() => createVueI18n(options))
  1629. : scope.run(() => createComposer(options));
  1630. if (obj == null) {
  1631. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1632. }
  1633. return [scope, obj];
  1634. }
  1635. function getI18nInstance(instance) {
  1636. const i18n = inject(!instance.isCE
  1637. ? instance.appContext.app.__VUE_I18N_SYMBOL__
  1638. : I18nInjectionKey);
  1639. /* istanbul ignore if */
  1640. if (!i18n) {
  1641. throw createI18nError(!instance.isCE
  1642. ? I18nErrorCodes.UNEXPECTED_ERROR
  1643. : I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE);
  1644. }
  1645. return i18n;
  1646. }
  1647. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1648. function getScope(options, componentOptions) {
  1649. // prettier-ignore
  1650. return isEmptyObject(options)
  1651. ? ('__i18n' in componentOptions)
  1652. ? 'local'
  1653. : 'global'
  1654. : !options.useScope
  1655. ? 'local'
  1656. : options.useScope;
  1657. }
  1658. function getGlobalComposer(i18n) {
  1659. // prettier-ignore
  1660. return i18n.mode === 'composition'
  1661. ? i18n.global
  1662. : i18n.global.__composer;
  1663. }
  1664. function getComposer(i18n, target, useComponent = false) {
  1665. let composer = null;
  1666. const root = target.root;
  1667. let current = getParentComponentInstance(target, useComponent);
  1668. while (current != null) {
  1669. const i18nInternal = i18n;
  1670. if (i18n.mode === 'composition') {
  1671. composer = i18nInternal.__getInstance(current);
  1672. }
  1673. else {
  1674. if (__VUE_I18N_LEGACY_API__) {
  1675. const vueI18n = i18nInternal.__getInstance(current);
  1676. if (vueI18n != null) {
  1677. composer = vueI18n
  1678. .__composer;
  1679. if (useComponent &&
  1680. composer &&
  1681. !composer[InejctWithOptionSymbol] // eslint-disable-line @typescript-eslint/no-explicit-any
  1682. ) {
  1683. composer = null;
  1684. }
  1685. }
  1686. }
  1687. }
  1688. if (composer != null) {
  1689. break;
  1690. }
  1691. if (root === current) {
  1692. break;
  1693. }
  1694. current = current.parent;
  1695. }
  1696. return composer;
  1697. }
  1698. function getParentComponentInstance(target, useComponent = false) {
  1699. if (target == null) {
  1700. return null;
  1701. }
  1702. // if `useComponent: true` will be specified, we get lexical scope owner instance for use-case slots
  1703. return !useComponent
  1704. ? target.parent
  1705. : target.vnode.ctx || target.parent; // eslint-disable-line @typescript-eslint/no-explicit-any
  1706. }
  1707. function setupLifeCycle(i18n, target, composer) {
  1708. onMounted(() => {
  1709. }, target);
  1710. onUnmounted(() => {
  1711. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1712. const _composer = composer;
  1713. i18n.__deleteInstance(target);
  1714. // dispose extended resources
  1715. const dispose = _composer[DisposeSymbol];
  1716. if (dispose) {
  1717. dispose();
  1718. delete _composer[DisposeSymbol];
  1719. }
  1720. }, target);
  1721. }
  1722. const globalExportProps = [
  1723. 'locale',
  1724. 'fallbackLocale',
  1725. 'availableLocales'
  1726. ];
  1727. const globalExportMethods = ['t', 'rt', 'd', 'n', 'tm', 'te']
  1728. ;
  1729. function injectGlobalFields(app, composer) {
  1730. const i18n = Object.create(null);
  1731. globalExportProps.forEach(prop => {
  1732. const desc = Object.getOwnPropertyDescriptor(composer, prop);
  1733. if (!desc) {
  1734. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1735. }
  1736. const wrap = isRef(desc.value) // check computed props
  1737. ? {
  1738. get() {
  1739. return desc.value.value;
  1740. },
  1741. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1742. set(val) {
  1743. desc.value.value = val;
  1744. }
  1745. }
  1746. : {
  1747. get() {
  1748. return desc.get && desc.get();
  1749. }
  1750. };
  1751. Object.defineProperty(i18n, prop, wrap);
  1752. });
  1753. app.config.globalProperties.$i18n = i18n;
  1754. globalExportMethods.forEach(method => {
  1755. const desc = Object.getOwnPropertyDescriptor(composer, method);
  1756. if (!desc || !desc.value) {
  1757. throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
  1758. }
  1759. Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
  1760. });
  1761. const dispose = () => {
  1762. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1763. delete app.config.globalProperties.$i18n;
  1764. globalExportMethods.forEach(method => {
  1765. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1766. delete app.config.globalProperties[`$${method}`];
  1767. });
  1768. };
  1769. return dispose;
  1770. }
  1771. const DatetimeFormatImpl = /* #__PURE__*/ defineComponent({
  1772. /* eslint-disable */
  1773. name: 'i18n-d',
  1774. props: assign({
  1775. value: {
  1776. type: [Number, Date],
  1777. required: true
  1778. },
  1779. format: {
  1780. type: [String, Object]
  1781. }
  1782. }, baseFormatProps),
  1783. /* eslint-enable */
  1784. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1785. setup(props, context) {
  1786. const i18n = props.i18n ||
  1787. useI18n({
  1788. useScope: props.scope,
  1789. __useComponent: true
  1790. });
  1791. return renderFormatter(props, context, DATETIME_FORMAT_OPTIONS_KEYS, (...args) =>
  1792. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1793. i18n[DatetimePartsSymbol](...args));
  1794. }
  1795. });
  1796. /**
  1797. * Datetime Format Component
  1798. *
  1799. * @remarks
  1800. * See the following items for property about details
  1801. *
  1802. * @VueI18nSee [FormattableProps](component#formattableprops)
  1803. * @VueI18nSee [BaseFormatProps](component#baseformatprops)
  1804. * @VueI18nSee [Custom Formatting](../guide/essentials/datetime#custom-formatting)
  1805. *
  1806. * @VueI18nDanger
  1807. * 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)
  1808. *
  1809. * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
  1810. *
  1811. * @VueI18nComponent
  1812. */
  1813. const DatetimeFormat = DatetimeFormatImpl;
  1814. const I18nD = DatetimeFormat;
  1815. {
  1816. initFeatureFlags();
  1817. }
  1818. // register message compiler for jit compilation
  1819. registerMessageCompiler(compile);
  1820. // register message resolver at vue-i18n
  1821. registerMessageResolver(resolveValue);
  1822. // register fallback locale at vue-i18n
  1823. registerLocaleFallbacker(fallbackWithLocaleChain);
  1824. // NOTE: experimental !!
  1825. if (__INTLIFY_PROD_DEVTOOLS__) {
  1826. const target = getGlobalThis();
  1827. target.__INTLIFY__ = true;
  1828. setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
  1829. }
  1830. export { DatetimeFormat, I18nD, I18nInjectionKey, I18nN, I18nT, NumberFormat, Translation, VERSION, createI18n, useI18n, vTDirective };