vue-i18n.cjs.js 82 KB

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