vue-i18n.esm.js 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. /*!
  2. * vue-i18n v8.27.2
  3. * (c) 2022 kazuya kawaguchi
  4. * Released under the MIT License.
  5. */
  6. /* */
  7. /**
  8. * constants
  9. */
  10. var numberFormatKeys = [
  11. 'compactDisplay',
  12. 'currency',
  13. 'currencyDisplay',
  14. 'currencySign',
  15. 'localeMatcher',
  16. 'notation',
  17. 'numberingSystem',
  18. 'signDisplay',
  19. 'style',
  20. 'unit',
  21. 'unitDisplay',
  22. 'useGrouping',
  23. 'minimumIntegerDigits',
  24. 'minimumFractionDigits',
  25. 'maximumFractionDigits',
  26. 'minimumSignificantDigits',
  27. 'maximumSignificantDigits'
  28. ];
  29. /**
  30. * utilities
  31. */
  32. function warn (msg, err) {
  33. if (typeof console !== 'undefined') {
  34. console.warn('[vue-i18n] ' + msg);
  35. /* istanbul ignore if */
  36. if (err) {
  37. console.warn(err.stack);
  38. }
  39. }
  40. }
  41. function error (msg, err) {
  42. if (typeof console !== 'undefined') {
  43. console.error('[vue-i18n] ' + msg);
  44. /* istanbul ignore if */
  45. if (err) {
  46. console.error(err.stack);
  47. }
  48. }
  49. }
  50. var isArray = Array.isArray;
  51. function isObject (obj) {
  52. return obj !== null && typeof obj === 'object'
  53. }
  54. function isBoolean (val) {
  55. return typeof val === 'boolean'
  56. }
  57. function isString (val) {
  58. return typeof val === 'string'
  59. }
  60. var toString = Object.prototype.toString;
  61. var OBJECT_STRING = '[object Object]';
  62. function isPlainObject (obj) {
  63. return toString.call(obj) === OBJECT_STRING
  64. }
  65. function isNull (val) {
  66. return val === null || val === undefined
  67. }
  68. function isFunction (val) {
  69. return typeof val === 'function'
  70. }
  71. function parseArgs () {
  72. var args = [], len = arguments.length;
  73. while ( len-- ) args[ len ] = arguments[ len ];
  74. var locale = null;
  75. var params = null;
  76. if (args.length === 1) {
  77. if (isObject(args[0]) || isArray(args[0])) {
  78. params = args[0];
  79. } else if (typeof args[0] === 'string') {
  80. locale = args[0];
  81. }
  82. } else if (args.length === 2) {
  83. if (typeof args[0] === 'string') {
  84. locale = args[0];
  85. }
  86. /* istanbul ignore if */
  87. if (isObject(args[1]) || isArray(args[1])) {
  88. params = args[1];
  89. }
  90. }
  91. return { locale: locale, params: params }
  92. }
  93. function looseClone (obj) {
  94. return JSON.parse(JSON.stringify(obj))
  95. }
  96. function remove (arr, item) {
  97. if (arr.delete(item)) {
  98. return arr
  99. }
  100. }
  101. function arrayFrom (arr) {
  102. var ret = [];
  103. arr.forEach(function (a) { return ret.push(a); });
  104. return ret
  105. }
  106. function includes (arr, item) {
  107. return !!~arr.indexOf(item)
  108. }
  109. var hasOwnProperty = Object.prototype.hasOwnProperty;
  110. function hasOwn (obj, key) {
  111. return hasOwnProperty.call(obj, key)
  112. }
  113. function merge (target) {
  114. var arguments$1 = arguments;
  115. var output = Object(target);
  116. for (var i = 1; i < arguments.length; i++) {
  117. var source = arguments$1[i];
  118. if (source !== undefined && source !== null) {
  119. var key = (void 0);
  120. for (key in source) {
  121. if (hasOwn(source, key)) {
  122. if (isObject(source[key])) {
  123. output[key] = merge(output[key], source[key]);
  124. } else {
  125. output[key] = source[key];
  126. }
  127. }
  128. }
  129. }
  130. }
  131. return output
  132. }
  133. function looseEqual (a, b) {
  134. if (a === b) { return true }
  135. var isObjectA = isObject(a);
  136. var isObjectB = isObject(b);
  137. if (isObjectA && isObjectB) {
  138. try {
  139. var isArrayA = isArray(a);
  140. var isArrayB = isArray(b);
  141. if (isArrayA && isArrayB) {
  142. return a.length === b.length && a.every(function (e, i) {
  143. return looseEqual(e, b[i])
  144. })
  145. } else if (!isArrayA && !isArrayB) {
  146. var keysA = Object.keys(a);
  147. var keysB = Object.keys(b);
  148. return keysA.length === keysB.length && keysA.every(function (key) {
  149. return looseEqual(a[key], b[key])
  150. })
  151. } else {
  152. /* istanbul ignore next */
  153. return false
  154. }
  155. } catch (e) {
  156. /* istanbul ignore next */
  157. return false
  158. }
  159. } else if (!isObjectA && !isObjectB) {
  160. return String(a) === String(b)
  161. } else {
  162. return false
  163. }
  164. }
  165. /**
  166. * Sanitizes html special characters from input strings. For mitigating risk of XSS attacks.
  167. * @param rawText The raw input from the user that should be escaped.
  168. */
  169. function escapeHtml(rawText) {
  170. return rawText
  171. .replace(/</g, '&lt;')
  172. .replace(/>/g, '&gt;')
  173. .replace(/"/g, '&quot;')
  174. .replace(/'/g, '&apos;')
  175. }
  176. /**
  177. * Escapes html tags and special symbols from all provided params which were returned from parseArgs().params.
  178. * This method performs an in-place operation on the params object.
  179. *
  180. * @param {any} params Parameters as provided from `parseArgs().params`.
  181. * May be either an array of strings or a string->any map.
  182. *
  183. * @returns The manipulated `params` object.
  184. */
  185. function escapeParams(params) {
  186. if(params != null) {
  187. Object.keys(params).forEach(function (key) {
  188. if(typeof(params[key]) == 'string') {
  189. params[key] = escapeHtml(params[key]);
  190. }
  191. });
  192. }
  193. return params
  194. }
  195. /* */
  196. function extend (Vue) {
  197. if (!Vue.prototype.hasOwnProperty('$i18n')) {
  198. // $FlowFixMe
  199. Object.defineProperty(Vue.prototype, '$i18n', {
  200. get: function get () { return this._i18n }
  201. });
  202. }
  203. Vue.prototype.$t = function (key) {
  204. var values = [], len = arguments.length - 1;
  205. while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ];
  206. var i18n = this.$i18n;
  207. return i18n._t.apply(i18n, [ key, i18n.locale, i18n._getMessages(), this ].concat( values ))
  208. };
  209. Vue.prototype.$tc = function (key, choice) {
  210. var values = [], len = arguments.length - 2;
  211. while ( len-- > 0 ) values[ len ] = arguments[ len + 2 ];
  212. var i18n = this.$i18n;
  213. return i18n._tc.apply(i18n, [ key, i18n.locale, i18n._getMessages(), this, choice ].concat( values ))
  214. };
  215. Vue.prototype.$te = function (key, locale) {
  216. var i18n = this.$i18n;
  217. return i18n._te(key, i18n.locale, i18n._getMessages(), locale)
  218. };
  219. Vue.prototype.$d = function (value) {
  220. var ref;
  221. var args = [], len = arguments.length - 1;
  222. while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
  223. return (ref = this.$i18n).d.apply(ref, [ value ].concat( args ))
  224. };
  225. Vue.prototype.$n = function (value) {
  226. var ref;
  227. var args = [], len = arguments.length - 1;
  228. while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
  229. return (ref = this.$i18n).n.apply(ref, [ value ].concat( args ))
  230. };
  231. }
  232. /* */
  233. /**
  234. * Mixin
  235. *
  236. * If `bridge` mode, empty mixin is returned,
  237. * else regulary mixin implementation is returned.
  238. */
  239. function defineMixin (bridge) {
  240. if ( bridge === void 0 ) bridge = false;
  241. function mounted () {
  242. if (this !== this.$root && this.$options.__INTLIFY_META__ && this.$el) {
  243. this.$el.setAttribute('data-intlify', this.$options.__INTLIFY_META__);
  244. }
  245. }
  246. return bridge
  247. ? { mounted: mounted } // delegate `vue-i18n-bridge` mixin implementation
  248. : { // regulary
  249. beforeCreate: function beforeCreate () {
  250. var options = this.$options;
  251. options.i18n = options.i18n || ((options.__i18nBridge || options.__i18n) ? {} : null);
  252. if (options.i18n) {
  253. if (options.i18n instanceof VueI18n) {
  254. // init locale messages via custom blocks
  255. if ((options.__i18nBridge || options.__i18n)) {
  256. try {
  257. var localeMessages = options.i18n && options.i18n.messages ? options.i18n.messages : {};
  258. var _i18n = options.__i18nBridge || options.__i18n;
  259. _i18n.forEach(function (resource) {
  260. localeMessages = merge(localeMessages, JSON.parse(resource));
  261. });
  262. Object.keys(localeMessages).forEach(function (locale) {
  263. options.i18n.mergeLocaleMessage(locale, localeMessages[locale]);
  264. });
  265. } catch (e) {
  266. if (process.env.NODE_ENV !== 'production') {
  267. error("Cannot parse locale messages via custom blocks.", e);
  268. }
  269. }
  270. }
  271. this._i18n = options.i18n;
  272. this._i18nWatcher = this._i18n.watchI18nData();
  273. } else if (isPlainObject(options.i18n)) {
  274. var rootI18n = this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n
  275. ? this.$root.$i18n
  276. : null;
  277. // component local i18n
  278. if (rootI18n) {
  279. options.i18n.root = this.$root;
  280. options.i18n.formatter = rootI18n.formatter;
  281. options.i18n.fallbackLocale = rootI18n.fallbackLocale;
  282. options.i18n.formatFallbackMessages = rootI18n.formatFallbackMessages;
  283. options.i18n.silentTranslationWarn = rootI18n.silentTranslationWarn;
  284. options.i18n.silentFallbackWarn = rootI18n.silentFallbackWarn;
  285. options.i18n.pluralizationRules = rootI18n.pluralizationRules;
  286. options.i18n.preserveDirectiveContent = rootI18n.preserveDirectiveContent;
  287. }
  288. // init locale messages via custom blocks
  289. if ((options.__i18nBridge || options.__i18n)) {
  290. try {
  291. var localeMessages$1 = options.i18n && options.i18n.messages ? options.i18n.messages : {};
  292. var _i18n$1 = options.__i18nBridge || options.__i18n;
  293. _i18n$1.forEach(function (resource) {
  294. localeMessages$1 = merge(localeMessages$1, JSON.parse(resource));
  295. });
  296. options.i18n.messages = localeMessages$1;
  297. } catch (e) {
  298. if (process.env.NODE_ENV !== 'production') {
  299. warn("Cannot parse locale messages via custom blocks.", e);
  300. }
  301. }
  302. }
  303. var ref = options.i18n;
  304. var sharedMessages = ref.sharedMessages;
  305. if (sharedMessages && isPlainObject(sharedMessages)) {
  306. options.i18n.messages = merge(options.i18n.messages, sharedMessages);
  307. }
  308. this._i18n = new VueI18n(options.i18n);
  309. this._i18nWatcher = this._i18n.watchI18nData();
  310. if (options.i18n.sync === undefined || !!options.i18n.sync) {
  311. this._localeWatcher = this.$i18n.watchLocale();
  312. }
  313. if (rootI18n) {
  314. rootI18n.onComponentInstanceCreated(this._i18n);
  315. }
  316. } else {
  317. if (process.env.NODE_ENV !== 'production') {
  318. warn("Cannot be interpreted 'i18n' option.");
  319. }
  320. }
  321. } else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
  322. // root i18n
  323. this._i18n = this.$root.$i18n;
  324. } else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) {
  325. // parent i18n
  326. this._i18n = options.parent.$i18n;
  327. }
  328. },
  329. beforeMount: function beforeMount () {
  330. var options = this.$options;
  331. options.i18n = options.i18n || ((options.__i18nBridge || options.__i18n) ? {} : null);
  332. if (options.i18n) {
  333. if (options.i18n instanceof VueI18n) {
  334. // init locale messages via custom blocks
  335. this._i18n.subscribeDataChanging(this);
  336. this._subscribing = true;
  337. } else if (isPlainObject(options.i18n)) {
  338. this._i18n.subscribeDataChanging(this);
  339. this._subscribing = true;
  340. } else {
  341. if (process.env.NODE_ENV !== 'production') {
  342. warn("Cannot be interpreted 'i18n' option.");
  343. }
  344. }
  345. } else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
  346. this._i18n.subscribeDataChanging(this);
  347. this._subscribing = true;
  348. } else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) {
  349. this._i18n.subscribeDataChanging(this);
  350. this._subscribing = true;
  351. }
  352. },
  353. mounted: mounted,
  354. beforeDestroy: function beforeDestroy () {
  355. if (!this._i18n) { return }
  356. var self = this;
  357. this.$nextTick(function () {
  358. if (self._subscribing) {
  359. self._i18n.unsubscribeDataChanging(self);
  360. delete self._subscribing;
  361. }
  362. if (self._i18nWatcher) {
  363. self._i18nWatcher();
  364. self._i18n.destroyVM();
  365. delete self._i18nWatcher;
  366. }
  367. if (self._localeWatcher) {
  368. self._localeWatcher();
  369. delete self._localeWatcher;
  370. }
  371. });
  372. }
  373. }
  374. }
  375. /* */
  376. var interpolationComponent = {
  377. name: 'i18n',
  378. functional: true,
  379. props: {
  380. tag: {
  381. type: [String, Boolean, Object],
  382. default: 'span'
  383. },
  384. path: {
  385. type: String,
  386. required: true
  387. },
  388. locale: {
  389. type: String
  390. },
  391. places: {
  392. type: [Array, Object]
  393. }
  394. },
  395. render: function render (h, ref) {
  396. var data = ref.data;
  397. var parent = ref.parent;
  398. var props = ref.props;
  399. var slots = ref.slots;
  400. var $i18n = parent.$i18n;
  401. if (!$i18n) {
  402. if (process.env.NODE_ENV !== 'production') {
  403. warn('Cannot find VueI18n instance!');
  404. }
  405. return
  406. }
  407. var path = props.path;
  408. var locale = props.locale;
  409. var places = props.places;
  410. var params = slots();
  411. var children = $i18n.i(
  412. path,
  413. locale,
  414. onlyHasDefaultPlace(params) || places
  415. ? useLegacyPlaces(params.default, places)
  416. : params
  417. );
  418. var tag = (!!props.tag && props.tag !== true) || props.tag === false ? props.tag : 'span';
  419. return tag ? h(tag, data, children) : children
  420. }
  421. };
  422. function onlyHasDefaultPlace (params) {
  423. var prop;
  424. for (prop in params) {
  425. if (prop !== 'default') { return false }
  426. }
  427. return Boolean(prop)
  428. }
  429. function useLegacyPlaces (children, places) {
  430. var params = places ? createParamsFromPlaces(places) : {};
  431. if (!children) { return params }
  432. // Filter empty text nodes
  433. children = children.filter(function (child) {
  434. return child.tag || child.text.trim() !== ''
  435. });
  436. var everyPlace = children.every(vnodeHasPlaceAttribute);
  437. if (process.env.NODE_ENV !== 'production' && everyPlace) {
  438. warn('`place` attribute is deprecated in next major version. Please switch to Vue slots.');
  439. }
  440. return children.reduce(
  441. everyPlace ? assignChildPlace : assignChildIndex,
  442. params
  443. )
  444. }
  445. function createParamsFromPlaces (places) {
  446. if (process.env.NODE_ENV !== 'production') {
  447. warn('`places` prop is deprecated in next major version. Please switch to Vue slots.');
  448. }
  449. return Array.isArray(places)
  450. ? places.reduce(assignChildIndex, {})
  451. : Object.assign({}, places)
  452. }
  453. function assignChildPlace (params, child) {
  454. if (child.data && child.data.attrs && child.data.attrs.place) {
  455. params[child.data.attrs.place] = child;
  456. }
  457. return params
  458. }
  459. function assignChildIndex (params, child, index) {
  460. params[index] = child;
  461. return params
  462. }
  463. function vnodeHasPlaceAttribute (vnode) {
  464. return Boolean(vnode.data && vnode.data.attrs && vnode.data.attrs.place)
  465. }
  466. /* */
  467. var numberComponent = {
  468. name: 'i18n-n',
  469. functional: true,
  470. props: {
  471. tag: {
  472. type: [String, Boolean, Object],
  473. default: 'span'
  474. },
  475. value: {
  476. type: Number,
  477. required: true
  478. },
  479. format: {
  480. type: [String, Object]
  481. },
  482. locale: {
  483. type: String
  484. }
  485. },
  486. render: function render (h, ref) {
  487. var props = ref.props;
  488. var parent = ref.parent;
  489. var data = ref.data;
  490. var i18n = parent.$i18n;
  491. if (!i18n) {
  492. if (process.env.NODE_ENV !== 'production') {
  493. warn('Cannot find VueI18n instance!');
  494. }
  495. return null
  496. }
  497. var key = null;
  498. var options = null;
  499. if (isString(props.format)) {
  500. key = props.format;
  501. } else if (isObject(props.format)) {
  502. if (props.format.key) {
  503. key = props.format.key;
  504. }
  505. // Filter out number format options only
  506. options = Object.keys(props.format).reduce(function (acc, prop) {
  507. var obj;
  508. if (includes(numberFormatKeys, prop)) {
  509. return Object.assign({}, acc, ( obj = {}, obj[prop] = props.format[prop], obj ))
  510. }
  511. return acc
  512. }, null);
  513. }
  514. var locale = props.locale || i18n.locale;
  515. var parts = i18n._ntp(props.value, locale, key, options);
  516. var values = parts.map(function (part, index) {
  517. var obj;
  518. var slot = data.scopedSlots && data.scopedSlots[part.type];
  519. return slot ? slot(( obj = {}, obj[part.type] = part.value, obj.index = index, obj.parts = parts, obj )) : part.value
  520. });
  521. var tag = (!!props.tag && props.tag !== true) || props.tag === false ? props.tag : 'span';
  522. return tag
  523. ? h(tag, {
  524. attrs: data.attrs,
  525. 'class': data['class'],
  526. staticClass: data.staticClass
  527. }, values)
  528. : values
  529. }
  530. };
  531. /* */
  532. function bind (el, binding, vnode) {
  533. if (!assert(el, vnode)) { return }
  534. t(el, binding, vnode);
  535. }
  536. function update (el, binding, vnode, oldVNode) {
  537. if (!assert(el, vnode)) { return }
  538. var i18n = vnode.context.$i18n;
  539. if (localeEqual(el, vnode) &&
  540. (looseEqual(binding.value, binding.oldValue) &&
  541. looseEqual(el._localeMessage, i18n.getLocaleMessage(i18n.locale)))) { return }
  542. t(el, binding, vnode);
  543. }
  544. function unbind (el, binding, vnode, oldVNode) {
  545. var vm = vnode.context;
  546. if (!vm) {
  547. warn('Vue instance does not exists in VNode context');
  548. return
  549. }
  550. var i18n = vnode.context.$i18n || {};
  551. if (!binding.modifiers.preserve && !i18n.preserveDirectiveContent) {
  552. el.textContent = '';
  553. }
  554. el._vt = undefined;
  555. delete el['_vt'];
  556. el._locale = undefined;
  557. delete el['_locale'];
  558. el._localeMessage = undefined;
  559. delete el['_localeMessage'];
  560. }
  561. function assert (el, vnode) {
  562. var vm = vnode.context;
  563. if (!vm) {
  564. warn('Vue instance does not exists in VNode context');
  565. return false
  566. }
  567. if (!vm.$i18n) {
  568. warn('VueI18n instance does not exists in Vue instance');
  569. return false
  570. }
  571. return true
  572. }
  573. function localeEqual (el, vnode) {
  574. var vm = vnode.context;
  575. return el._locale === vm.$i18n.locale
  576. }
  577. function t (el, binding, vnode) {
  578. var ref$1, ref$2;
  579. var value = binding.value;
  580. var ref = parseValue(value);
  581. var path = ref.path;
  582. var locale = ref.locale;
  583. var args = ref.args;
  584. var choice = ref.choice;
  585. if (!path && !locale && !args) {
  586. warn('value type not supported');
  587. return
  588. }
  589. if (!path) {
  590. warn('`path` is required in v-t directive');
  591. return
  592. }
  593. var vm = vnode.context;
  594. if (choice != null) {
  595. el._vt = el.textContent = (ref$1 = vm.$i18n).tc.apply(ref$1, [ path, choice ].concat( makeParams(locale, args) ));
  596. } else {
  597. el._vt = el.textContent = (ref$2 = vm.$i18n).t.apply(ref$2, [ path ].concat( makeParams(locale, args) ));
  598. }
  599. el._locale = vm.$i18n.locale;
  600. el._localeMessage = vm.$i18n.getLocaleMessage(vm.$i18n.locale);
  601. }
  602. function parseValue (value) {
  603. var path;
  604. var locale;
  605. var args;
  606. var choice;
  607. if (isString(value)) {
  608. path = value;
  609. } else if (isPlainObject(value)) {
  610. path = value.path;
  611. locale = value.locale;
  612. args = value.args;
  613. choice = value.choice;
  614. }
  615. return { path: path, locale: locale, args: args, choice: choice }
  616. }
  617. function makeParams (locale, args) {
  618. var params = [];
  619. locale && params.push(locale);
  620. if (args && (Array.isArray(args) || isPlainObject(args))) {
  621. params.push(args);
  622. }
  623. return params
  624. }
  625. var Vue;
  626. function install (_Vue, options) {
  627. if ( options === void 0 ) options = { bridge: false };
  628. /* istanbul ignore if */
  629. if (process.env.NODE_ENV !== 'production' && install.installed && _Vue === Vue) {
  630. warn('already installed.');
  631. return
  632. }
  633. install.installed = true;
  634. Vue = _Vue;
  635. var version = (Vue.version && Number(Vue.version.split('.')[0])) || -1;
  636. /* istanbul ignore if */
  637. if (process.env.NODE_ENV !== 'production' && version < 2) {
  638. warn(("vue-i18n (" + (install.version) + ") need to use Vue 2.0 or later (Vue: " + (Vue.version) + ")."));
  639. return
  640. }
  641. extend(Vue);
  642. Vue.mixin(defineMixin(options.bridge));
  643. Vue.directive('t', { bind: bind, update: update, unbind: unbind });
  644. Vue.component(interpolationComponent.name, interpolationComponent);
  645. Vue.component(numberComponent.name, numberComponent);
  646. // use simple mergeStrategies to prevent i18n instance lose '__proto__'
  647. var strats = Vue.config.optionMergeStrategies;
  648. strats.i18n = function (parentVal, childVal) {
  649. return childVal === undefined
  650. ? parentVal
  651. : childVal
  652. };
  653. }
  654. /* */
  655. var BaseFormatter = function BaseFormatter () {
  656. this._caches = Object.create(null);
  657. };
  658. BaseFormatter.prototype.interpolate = function interpolate (message, values) {
  659. if (!values) {
  660. return [message]
  661. }
  662. var tokens = this._caches[message];
  663. if (!tokens) {
  664. tokens = parse(message);
  665. this._caches[message] = tokens;
  666. }
  667. return compile(tokens, values)
  668. };
  669. var RE_TOKEN_LIST_VALUE = /^(?:\d)+/;
  670. var RE_TOKEN_NAMED_VALUE = /^(?:\w)+/;
  671. function parse (format) {
  672. var tokens = [];
  673. var position = 0;
  674. var text = '';
  675. while (position < format.length) {
  676. var char = format[position++];
  677. if (char === '{') {
  678. if (text) {
  679. tokens.push({ type: 'text', value: text });
  680. }
  681. text = '';
  682. var sub = '';
  683. char = format[position++];
  684. while (char !== undefined && char !== '}') {
  685. sub += char;
  686. char = format[position++];
  687. }
  688. var isClosed = char === '}';
  689. var type = RE_TOKEN_LIST_VALUE.test(sub)
  690. ? 'list'
  691. : isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
  692. ? 'named'
  693. : 'unknown';
  694. tokens.push({ value: sub, type: type });
  695. } else if (char === '%') {
  696. // when found rails i18n syntax, skip text capture
  697. if (format[(position)] !== '{') {
  698. text += char;
  699. }
  700. } else {
  701. text += char;
  702. }
  703. }
  704. text && tokens.push({ type: 'text', value: text });
  705. return tokens
  706. }
  707. function compile (tokens, values) {
  708. var compiled = [];
  709. var index = 0;
  710. var mode = Array.isArray(values)
  711. ? 'list'
  712. : isObject(values)
  713. ? 'named'
  714. : 'unknown';
  715. if (mode === 'unknown') { return compiled }
  716. while (index < tokens.length) {
  717. var token = tokens[index];
  718. switch (token.type) {
  719. case 'text':
  720. compiled.push(token.value);
  721. break
  722. case 'list':
  723. compiled.push(values[parseInt(token.value, 10)]);
  724. break
  725. case 'named':
  726. if (mode === 'named') {
  727. compiled.push((values)[token.value]);
  728. } else {
  729. if (process.env.NODE_ENV !== 'production') {
  730. warn(("Type of token '" + (token.type) + "' and format of value '" + mode + "' don't match!"));
  731. }
  732. }
  733. break
  734. case 'unknown':
  735. if (process.env.NODE_ENV !== 'production') {
  736. warn("Detect 'unknown' type of token!");
  737. }
  738. break
  739. }
  740. index++;
  741. }
  742. return compiled
  743. }
  744. /* */
  745. /**
  746. * Path parser
  747. * - Inspired:
  748. * Vue.js Path parser
  749. */
  750. // actions
  751. var APPEND = 0;
  752. var PUSH = 1;
  753. var INC_SUB_PATH_DEPTH = 2;
  754. var PUSH_SUB_PATH = 3;
  755. // states
  756. var BEFORE_PATH = 0;
  757. var IN_PATH = 1;
  758. var BEFORE_IDENT = 2;
  759. var IN_IDENT = 3;
  760. var IN_SUB_PATH = 4;
  761. var IN_SINGLE_QUOTE = 5;
  762. var IN_DOUBLE_QUOTE = 6;
  763. var AFTER_PATH = 7;
  764. var ERROR = 8;
  765. var pathStateMachine = [];
  766. pathStateMachine[BEFORE_PATH] = {
  767. 'ws': [BEFORE_PATH],
  768. 'ident': [IN_IDENT, APPEND],
  769. '[': [IN_SUB_PATH],
  770. 'eof': [AFTER_PATH]
  771. };
  772. pathStateMachine[IN_PATH] = {
  773. 'ws': [IN_PATH],
  774. '.': [BEFORE_IDENT],
  775. '[': [IN_SUB_PATH],
  776. 'eof': [AFTER_PATH]
  777. };
  778. pathStateMachine[BEFORE_IDENT] = {
  779. 'ws': [BEFORE_IDENT],
  780. 'ident': [IN_IDENT, APPEND],
  781. '0': [IN_IDENT, APPEND],
  782. 'number': [IN_IDENT, APPEND]
  783. };
  784. pathStateMachine[IN_IDENT] = {
  785. 'ident': [IN_IDENT, APPEND],
  786. '0': [IN_IDENT, APPEND],
  787. 'number': [IN_IDENT, APPEND],
  788. 'ws': [IN_PATH, PUSH],
  789. '.': [BEFORE_IDENT, PUSH],
  790. '[': [IN_SUB_PATH, PUSH],
  791. 'eof': [AFTER_PATH, PUSH]
  792. };
  793. pathStateMachine[IN_SUB_PATH] = {
  794. "'": [IN_SINGLE_QUOTE, APPEND],
  795. '"': [IN_DOUBLE_QUOTE, APPEND],
  796. '[': [IN_SUB_PATH, INC_SUB_PATH_DEPTH],
  797. ']': [IN_PATH, PUSH_SUB_PATH],
  798. 'eof': ERROR,
  799. 'else': [IN_SUB_PATH, APPEND]
  800. };
  801. pathStateMachine[IN_SINGLE_QUOTE] = {
  802. "'": [IN_SUB_PATH, APPEND],
  803. 'eof': ERROR,
  804. 'else': [IN_SINGLE_QUOTE, APPEND]
  805. };
  806. pathStateMachine[IN_DOUBLE_QUOTE] = {
  807. '"': [IN_SUB_PATH, APPEND],
  808. 'eof': ERROR,
  809. 'else': [IN_DOUBLE_QUOTE, APPEND]
  810. };
  811. /**
  812. * Check if an expression is a literal value.
  813. */
  814. var literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
  815. function isLiteral (exp) {
  816. return literalValueRE.test(exp)
  817. }
  818. /**
  819. * Strip quotes from a string
  820. */
  821. function stripQuotes (str) {
  822. var a = str.charCodeAt(0);
  823. var b = str.charCodeAt(str.length - 1);
  824. return a === b && (a === 0x22 || a === 0x27)
  825. ? str.slice(1, -1)
  826. : str
  827. }
  828. /**
  829. * Determine the type of a character in a keypath.
  830. */
  831. function getPathCharType (ch) {
  832. if (ch === undefined || ch === null) { return 'eof' }
  833. var code = ch.charCodeAt(0);
  834. switch (code) {
  835. case 0x5B: // [
  836. case 0x5D: // ]
  837. case 0x2E: // .
  838. case 0x22: // "
  839. case 0x27: // '
  840. return ch
  841. case 0x5F: // _
  842. case 0x24: // $
  843. case 0x2D: // -
  844. return 'ident'
  845. case 0x09: // Tab
  846. case 0x0A: // Newline
  847. case 0x0D: // Return
  848. case 0xA0: // No-break space
  849. case 0xFEFF: // Byte Order Mark
  850. case 0x2028: // Line Separator
  851. case 0x2029: // Paragraph Separator
  852. return 'ws'
  853. }
  854. return 'ident'
  855. }
  856. /**
  857. * Format a subPath, return its plain form if it is
  858. * a literal string or number. Otherwise prepend the
  859. * dynamic indicator (*).
  860. */
  861. function formatSubPath (path) {
  862. var trimmed = path.trim();
  863. // invalid leading 0
  864. if (path.charAt(0) === '0' && isNaN(path)) { return false }
  865. return isLiteral(trimmed) ? stripQuotes(trimmed) : '*' + trimmed
  866. }
  867. /**
  868. * Parse a string path into an array of segments
  869. */
  870. function parse$1 (path) {
  871. var keys = [];
  872. var index = -1;
  873. var mode = BEFORE_PATH;
  874. var subPathDepth = 0;
  875. var c;
  876. var key;
  877. var newChar;
  878. var type;
  879. var transition;
  880. var action;
  881. var typeMap;
  882. var actions = [];
  883. actions[PUSH] = function () {
  884. if (key !== undefined) {
  885. keys.push(key);
  886. key = undefined;
  887. }
  888. };
  889. actions[APPEND] = function () {
  890. if (key === undefined) {
  891. key = newChar;
  892. } else {
  893. key += newChar;
  894. }
  895. };
  896. actions[INC_SUB_PATH_DEPTH] = function () {
  897. actions[APPEND]();
  898. subPathDepth++;
  899. };
  900. actions[PUSH_SUB_PATH] = function () {
  901. if (subPathDepth > 0) {
  902. subPathDepth--;
  903. mode = IN_SUB_PATH;
  904. actions[APPEND]();
  905. } else {
  906. subPathDepth = 0;
  907. if (key === undefined) { return false }
  908. key = formatSubPath(key);
  909. if (key === false) {
  910. return false
  911. } else {
  912. actions[PUSH]();
  913. }
  914. }
  915. };
  916. function maybeUnescapeQuote () {
  917. var nextChar = path[index + 1];
  918. if ((mode === IN_SINGLE_QUOTE && nextChar === "'") ||
  919. (mode === IN_DOUBLE_QUOTE && nextChar === '"')) {
  920. index++;
  921. newChar = '\\' + nextChar;
  922. actions[APPEND]();
  923. return true
  924. }
  925. }
  926. while (mode !== null) {
  927. index++;
  928. c = path[index];
  929. if (c === '\\' && maybeUnescapeQuote()) {
  930. continue
  931. }
  932. type = getPathCharType(c);
  933. typeMap = pathStateMachine[mode];
  934. transition = typeMap[type] || typeMap['else'] || ERROR;
  935. if (transition === ERROR) {
  936. return // parse error
  937. }
  938. mode = transition[0];
  939. action = actions[transition[1]];
  940. if (action) {
  941. newChar = transition[2];
  942. newChar = newChar === undefined
  943. ? c
  944. : newChar;
  945. if (action() === false) {
  946. return
  947. }
  948. }
  949. if (mode === AFTER_PATH) {
  950. return keys
  951. }
  952. }
  953. }
  954. var I18nPath = function I18nPath () {
  955. this._cache = Object.create(null);
  956. };
  957. /**
  958. * External parse that check for a cache hit first
  959. */
  960. I18nPath.prototype.parsePath = function parsePath (path) {
  961. var hit = this._cache[path];
  962. if (!hit) {
  963. hit = parse$1(path);
  964. if (hit) {
  965. this._cache[path] = hit;
  966. }
  967. }
  968. return hit || []
  969. };
  970. /**
  971. * Get path value from path string
  972. */
  973. I18nPath.prototype.getPathValue = function getPathValue (obj, path) {
  974. if (!isObject(obj)) { return null }
  975. var paths = this.parsePath(path);
  976. if (paths.length === 0) {
  977. return null
  978. } else {
  979. var length = paths.length;
  980. var last = obj;
  981. var i = 0;
  982. while (i < length) {
  983. var value = last[paths[i]];
  984. if (value === undefined || value === null) {
  985. return null
  986. }
  987. last = value;
  988. i++;
  989. }
  990. return last
  991. }
  992. };
  993. /* */
  994. var htmlTagMatcher = /<\/?[\w\s="/.':;#-\/]+>/;
  995. var linkKeyMatcher = /(?:@(?:\.[a-zA-Z]+)?:(?:[\w\-_|./]+|\([\w\-_:|./]+\)))/g;
  996. var linkKeyPrefixMatcher = /^@(?:\.([a-zA-Z]+))?:/;
  997. var bracketsMatcher = /[()]/g;
  998. var defaultModifiers = {
  999. 'upper': function (str) { return str.toLocaleUpperCase(); },
  1000. 'lower': function (str) { return str.toLocaleLowerCase(); },
  1001. 'capitalize': function (str) { return ("" + (str.charAt(0).toLocaleUpperCase()) + (str.substr(1))); }
  1002. };
  1003. var defaultFormatter = new BaseFormatter();
  1004. var VueI18n = function VueI18n (options) {
  1005. var this$1 = this;
  1006. if ( options === void 0 ) options = {};
  1007. // Auto install if it is not done yet and `window` has `Vue`.
  1008. // To allow users to avoid auto-installation in some cases,
  1009. // this code should be placed here. See #290
  1010. /* istanbul ignore if */
  1011. if (!Vue && typeof window !== 'undefined' && window.Vue) {
  1012. install(window.Vue);
  1013. }
  1014. var locale = options.locale || 'en-US';
  1015. var fallbackLocale = options.fallbackLocale === false
  1016. ? false
  1017. : options.fallbackLocale || 'en-US';
  1018. var messages = options.messages || {};
  1019. var dateTimeFormats = options.dateTimeFormats || options.datetimeFormats || {};
  1020. var numberFormats = options.numberFormats || {};
  1021. this._vm = null;
  1022. this._formatter = options.formatter || defaultFormatter;
  1023. this._modifiers = options.modifiers || {};
  1024. this._missing = options.missing || null;
  1025. this._root = options.root || null;
  1026. this._sync = options.sync === undefined ? true : !!options.sync;
  1027. this._fallbackRoot = options.fallbackRoot === undefined
  1028. ? true
  1029. : !!options.fallbackRoot;
  1030. this._fallbackRootWithEmptyString = options.fallbackRootWithEmptyString === undefined
  1031. ? true
  1032. : !!options.fallbackRootWithEmptyString;
  1033. this._formatFallbackMessages = options.formatFallbackMessages === undefined
  1034. ? false
  1035. : !!options.formatFallbackMessages;
  1036. this._silentTranslationWarn = options.silentTranslationWarn === undefined
  1037. ? false
  1038. : options.silentTranslationWarn;
  1039. this._silentFallbackWarn = options.silentFallbackWarn === undefined
  1040. ? false
  1041. : !!options.silentFallbackWarn;
  1042. this._dateTimeFormatters = {};
  1043. this._numberFormatters = {};
  1044. this._path = new I18nPath();
  1045. this._dataListeners = new Set();
  1046. this._componentInstanceCreatedListener = options.componentInstanceCreatedListener || null;
  1047. this._preserveDirectiveContent = options.preserveDirectiveContent === undefined
  1048. ? false
  1049. : !!options.preserveDirectiveContent;
  1050. this.pluralizationRules = options.pluralizationRules || {};
  1051. this._warnHtmlInMessage = options.warnHtmlInMessage || 'off';
  1052. this._postTranslation = options.postTranslation || null;
  1053. this._escapeParameterHtml = options.escapeParameterHtml || false;
  1054. if ('__VUE_I18N_BRIDGE__' in options) {
  1055. this.__VUE_I18N_BRIDGE__ = options.__VUE_I18N_BRIDGE__;
  1056. }
  1057. /**
  1058. * @param choice {number} a choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)`
  1059. * @param choicesLength {number} an overall amount of available choices
  1060. * @returns a final choice index
  1061. */
  1062. this.getChoiceIndex = function (choice, choicesLength) {
  1063. var thisPrototype = Object.getPrototypeOf(this$1);
  1064. if (thisPrototype && thisPrototype.getChoiceIndex) {
  1065. var prototypeGetChoiceIndex = (thisPrototype.getChoiceIndex);
  1066. return (prototypeGetChoiceIndex).call(this$1, choice, choicesLength)
  1067. }
  1068. // Default (old) getChoiceIndex implementation - english-compatible
  1069. var defaultImpl = function (_choice, _choicesLength) {
  1070. _choice = Math.abs(_choice);
  1071. if (_choicesLength === 2) {
  1072. return _choice
  1073. ? _choice > 1
  1074. ? 1
  1075. : 0
  1076. : 1
  1077. }
  1078. return _choice ? Math.min(_choice, 2) : 0
  1079. };
  1080. if (this$1.locale in this$1.pluralizationRules) {
  1081. return this$1.pluralizationRules[this$1.locale].apply(this$1, [choice, choicesLength])
  1082. } else {
  1083. return defaultImpl(choice, choicesLength)
  1084. }
  1085. };
  1086. this._exist = function (message, key) {
  1087. if (!message || !key) { return false }
  1088. if (!isNull(this$1._path.getPathValue(message, key))) { return true }
  1089. // fallback for flat key
  1090. if (message[key]) { return true }
  1091. return false
  1092. };
  1093. if (this._warnHtmlInMessage === 'warn' || this._warnHtmlInMessage === 'error') {
  1094. Object.keys(messages).forEach(function (locale) {
  1095. this$1._checkLocaleMessage(locale, this$1._warnHtmlInMessage, messages[locale]);
  1096. });
  1097. }
  1098. this._initVM({
  1099. locale: locale,
  1100. fallbackLocale: fallbackLocale,
  1101. messages: messages,
  1102. dateTimeFormats: dateTimeFormats,
  1103. numberFormats: numberFormats
  1104. });
  1105. };
  1106. var prototypeAccessors = { vm: { configurable: true },messages: { configurable: true },dateTimeFormats: { configurable: true },numberFormats: { configurable: true },availableLocales: { configurable: true },locale: { configurable: true },fallbackLocale: { configurable: true },formatFallbackMessages: { configurable: true },missing: { configurable: true },formatter: { configurable: true },silentTranslationWarn: { configurable: true },silentFallbackWarn: { configurable: true },preserveDirectiveContent: { configurable: true },warnHtmlInMessage: { configurable: true },postTranslation: { configurable: true },sync: { configurable: true } };
  1107. VueI18n.prototype._checkLocaleMessage = function _checkLocaleMessage (locale, level, message) {
  1108. var paths = [];
  1109. var fn = function (level, locale, message, paths) {
  1110. if (isPlainObject(message)) {
  1111. Object.keys(message).forEach(function (key) {
  1112. var val = message[key];
  1113. if (isPlainObject(val)) {
  1114. paths.push(key);
  1115. paths.push('.');
  1116. fn(level, locale, val, paths);
  1117. paths.pop();
  1118. paths.pop();
  1119. } else {
  1120. paths.push(key);
  1121. fn(level, locale, val, paths);
  1122. paths.pop();
  1123. }
  1124. });
  1125. } else if (isArray(message)) {
  1126. message.forEach(function (item, index) {
  1127. if (isPlainObject(item)) {
  1128. paths.push(("[" + index + "]"));
  1129. paths.push('.');
  1130. fn(level, locale, item, paths);
  1131. paths.pop();
  1132. paths.pop();
  1133. } else {
  1134. paths.push(("[" + index + "]"));
  1135. fn(level, locale, item, paths);
  1136. paths.pop();
  1137. }
  1138. });
  1139. } else if (isString(message)) {
  1140. var ret = htmlTagMatcher.test(message);
  1141. if (ret) {
  1142. var msg = "Detected HTML in message '" + message + "' of keypath '" + (paths.join('')) + "' at '" + locale + "'. Consider component interpolation with '<i18n>' to avoid XSS. See https://bit.ly/2ZqJzkp";
  1143. if (level === 'warn') {
  1144. warn(msg);
  1145. } else if (level === 'error') {
  1146. error(msg);
  1147. }
  1148. }
  1149. }
  1150. };
  1151. fn(level, locale, message, paths);
  1152. };
  1153. VueI18n.prototype._initVM = function _initVM (data) {
  1154. var silent = Vue.config.silent;
  1155. Vue.config.silent = true;
  1156. this._vm = new Vue({ data: data, __VUE18N__INSTANCE__: true });
  1157. Vue.config.silent = silent;
  1158. };
  1159. VueI18n.prototype.destroyVM = function destroyVM () {
  1160. this._vm.$destroy();
  1161. };
  1162. VueI18n.prototype.subscribeDataChanging = function subscribeDataChanging (vm) {
  1163. this._dataListeners.add(vm);
  1164. };
  1165. VueI18n.prototype.unsubscribeDataChanging = function unsubscribeDataChanging (vm) {
  1166. remove(this._dataListeners, vm);
  1167. };
  1168. VueI18n.prototype.watchI18nData = function watchI18nData () {
  1169. var this$1 = this;
  1170. return this._vm.$watch('$data', function () {
  1171. var listeners = arrayFrom(this$1._dataListeners);
  1172. var i = listeners.length;
  1173. while(i--) {
  1174. Vue.nextTick(function () {
  1175. listeners[i] && listeners[i].$forceUpdate();
  1176. });
  1177. }
  1178. }, { deep: true })
  1179. };
  1180. VueI18n.prototype.watchLocale = function watchLocale (composer) {
  1181. if (!composer) {
  1182. /* istanbul ignore if */
  1183. if (!this._sync || !this._root) { return null }
  1184. var target = this._vm;
  1185. return this._root.$i18n.vm.$watch('locale', function (val) {
  1186. target.$set(target, 'locale', val);
  1187. target.$forceUpdate();
  1188. }, { immediate: true })
  1189. } else {
  1190. // deal with vue-i18n-bridge
  1191. if (!this.__VUE_I18N_BRIDGE__) { return null }
  1192. var self = this;
  1193. var target$1 = this._vm;
  1194. return this.vm.$watch('locale', function (val) {
  1195. target$1.$set(target$1, 'locale', val);
  1196. if (self.__VUE_I18N_BRIDGE__ && composer) {
  1197. composer.locale.value = val;
  1198. }
  1199. target$1.$forceUpdate();
  1200. }, { immediate: true })
  1201. }
  1202. };
  1203. VueI18n.prototype.onComponentInstanceCreated = function onComponentInstanceCreated (newI18n) {
  1204. if (this._componentInstanceCreatedListener) {
  1205. this._componentInstanceCreatedListener(newI18n, this);
  1206. }
  1207. };
  1208. prototypeAccessors.vm.get = function () { return this._vm };
  1209. prototypeAccessors.messages.get = function () { return looseClone(this._getMessages()) };
  1210. prototypeAccessors.dateTimeFormats.get = function () { return looseClone(this._getDateTimeFormats()) };
  1211. prototypeAccessors.numberFormats.get = function () { return looseClone(this._getNumberFormats()) };
  1212. prototypeAccessors.availableLocales.get = function () { return Object.keys(this.messages).sort() };
  1213. prototypeAccessors.locale.get = function () { return this._vm.locale };
  1214. prototypeAccessors.locale.set = function (locale) {
  1215. this._vm.$set(this._vm, 'locale', locale);
  1216. };
  1217. prototypeAccessors.fallbackLocale.get = function () { return this._vm.fallbackLocale };
  1218. prototypeAccessors.fallbackLocale.set = function (locale) {
  1219. this._localeChainCache = {};
  1220. this._vm.$set(this._vm, 'fallbackLocale', locale);
  1221. };
  1222. prototypeAccessors.formatFallbackMessages.get = function () { return this._formatFallbackMessages };
  1223. prototypeAccessors.formatFallbackMessages.set = function (fallback) { this._formatFallbackMessages = fallback; };
  1224. prototypeAccessors.missing.get = function () { return this._missing };
  1225. prototypeAccessors.missing.set = function (handler) { this._missing = handler; };
  1226. prototypeAccessors.formatter.get = function () { return this._formatter };
  1227. prototypeAccessors.formatter.set = function (formatter) { this._formatter = formatter; };
  1228. prototypeAccessors.silentTranslationWarn.get = function () { return this._silentTranslationWarn };
  1229. prototypeAccessors.silentTranslationWarn.set = function (silent) { this._silentTranslationWarn = silent; };
  1230. prototypeAccessors.silentFallbackWarn.get = function () { return this._silentFallbackWarn };
  1231. prototypeAccessors.silentFallbackWarn.set = function (silent) { this._silentFallbackWarn = silent; };
  1232. prototypeAccessors.preserveDirectiveContent.get = function () { return this._preserveDirectiveContent };
  1233. prototypeAccessors.preserveDirectiveContent.set = function (preserve) { this._preserveDirectiveContent = preserve; };
  1234. prototypeAccessors.warnHtmlInMessage.get = function () { return this._warnHtmlInMessage };
  1235. prototypeAccessors.warnHtmlInMessage.set = function (level) {
  1236. var this$1 = this;
  1237. var orgLevel = this._warnHtmlInMessage;
  1238. this._warnHtmlInMessage = level;
  1239. if (orgLevel !== level && (level === 'warn' || level === 'error')) {
  1240. var messages = this._getMessages();
  1241. Object.keys(messages).forEach(function (locale) {
  1242. this$1._checkLocaleMessage(locale, this$1._warnHtmlInMessage, messages[locale]);
  1243. });
  1244. }
  1245. };
  1246. prototypeAccessors.postTranslation.get = function () { return this._postTranslation };
  1247. prototypeAccessors.postTranslation.set = function (handler) { this._postTranslation = handler; };
  1248. prototypeAccessors.sync.get = function () { return this._sync };
  1249. prototypeAccessors.sync.set = function (val) { this._sync = val; };
  1250. VueI18n.prototype._getMessages = function _getMessages () { return this._vm.messages };
  1251. VueI18n.prototype._getDateTimeFormats = function _getDateTimeFormats () { return this._vm.dateTimeFormats };
  1252. VueI18n.prototype._getNumberFormats = function _getNumberFormats () { return this._vm.numberFormats };
  1253. VueI18n.prototype._warnDefault = function _warnDefault (locale, key, result, vm, values, interpolateMode) {
  1254. if (!isNull(result)) { return result }
  1255. if (this._missing) {
  1256. var missingRet = this._missing.apply(null, [locale, key, vm, values]);
  1257. if (isString(missingRet)) {
  1258. return missingRet
  1259. }
  1260. } else {
  1261. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key)) {
  1262. warn(
  1263. "Cannot translate the value of keypath '" + key + "'. " +
  1264. 'Use the value of keypath as default.'
  1265. );
  1266. }
  1267. }
  1268. if (this._formatFallbackMessages) {
  1269. var parsedArgs = parseArgs.apply(void 0, values);
  1270. return this._render(key, interpolateMode, parsedArgs.params, key)
  1271. } else {
  1272. return key
  1273. }
  1274. };
  1275. VueI18n.prototype._isFallbackRoot = function _isFallbackRoot (val) {
  1276. return (this._fallbackRootWithEmptyString? !val : isNull(val)) && !isNull(this._root) && this._fallbackRoot
  1277. };
  1278. VueI18n.prototype._isSilentFallbackWarn = function _isSilentFallbackWarn (key) {
  1279. return this._silentFallbackWarn instanceof RegExp
  1280. ? this._silentFallbackWarn.test(key)
  1281. : this._silentFallbackWarn
  1282. };
  1283. VueI18n.prototype._isSilentFallback = function _isSilentFallback (locale, key) {
  1284. return this._isSilentFallbackWarn(key) && (this._isFallbackRoot() || locale !== this.fallbackLocale)
  1285. };
  1286. VueI18n.prototype._isSilentTranslationWarn = function _isSilentTranslationWarn (key) {
  1287. return this._silentTranslationWarn instanceof RegExp
  1288. ? this._silentTranslationWarn.test(key)
  1289. : this._silentTranslationWarn
  1290. };
  1291. VueI18n.prototype._interpolate = function _interpolate (
  1292. locale,
  1293. message,
  1294. key,
  1295. host,
  1296. interpolateMode,
  1297. values,
  1298. visitedLinkStack
  1299. ) {
  1300. if (!message) { return null }
  1301. var pathRet = this._path.getPathValue(message, key);
  1302. if (isArray(pathRet) || isPlainObject(pathRet)) { return pathRet }
  1303. var ret;
  1304. if (isNull(pathRet)) {
  1305. /* istanbul ignore else */
  1306. if (isPlainObject(message)) {
  1307. ret = message[key];
  1308. if (!(isString(ret) || isFunction(ret))) {
  1309. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallback(locale, key)) {
  1310. warn(("Value of key '" + key + "' is not a string or function !"));
  1311. }
  1312. return null
  1313. }
  1314. } else {
  1315. return null
  1316. }
  1317. } else {
  1318. /* istanbul ignore else */
  1319. if (isString(pathRet) || isFunction(pathRet)) {
  1320. ret = pathRet;
  1321. } else {
  1322. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallback(locale, key)) {
  1323. warn(("Value of key '" + key + "' is not a string or function!"));
  1324. }
  1325. return null
  1326. }
  1327. }
  1328. // Check for the existence of links within the translated string
  1329. if (isString(ret) && (ret.indexOf('@:') >= 0 || ret.indexOf('@.') >= 0)) {
  1330. ret = this._link(locale, message, ret, host, 'raw', values, visitedLinkStack);
  1331. }
  1332. return this._render(ret, interpolateMode, values, key)
  1333. };
  1334. VueI18n.prototype._link = function _link (
  1335. locale,
  1336. message,
  1337. str,
  1338. host,
  1339. interpolateMode,
  1340. values,
  1341. visitedLinkStack
  1342. ) {
  1343. var ret = str;
  1344. // Match all the links within the local
  1345. // We are going to replace each of
  1346. // them with its translation
  1347. var matches = ret.match(linkKeyMatcher);
  1348. // eslint-disable-next-line no-autofix/prefer-const
  1349. for (var idx in matches) {
  1350. // ie compatible: filter custom array
  1351. // prototype method
  1352. if (!matches.hasOwnProperty(idx)) {
  1353. continue
  1354. }
  1355. var link = matches[idx];
  1356. var linkKeyPrefixMatches = link.match(linkKeyPrefixMatcher);
  1357. var linkPrefix = linkKeyPrefixMatches[0];
  1358. var formatterName = linkKeyPrefixMatches[1];
  1359. // Remove the leading @:, @.case: and the brackets
  1360. var linkPlaceholder = link.replace(linkPrefix, '').replace(bracketsMatcher, '');
  1361. if (includes(visitedLinkStack, linkPlaceholder)) {
  1362. if (process.env.NODE_ENV !== 'production') {
  1363. warn(("Circular reference found. \"" + link + "\" is already visited in the chain of " + (visitedLinkStack.reverse().join(' <- '))));
  1364. }
  1365. return ret
  1366. }
  1367. visitedLinkStack.push(linkPlaceholder);
  1368. // Translate the link
  1369. var translated = this._interpolate(
  1370. locale, message, linkPlaceholder, host,
  1371. interpolateMode === 'raw' ? 'string' : interpolateMode,
  1372. interpolateMode === 'raw' ? undefined : values,
  1373. visitedLinkStack
  1374. );
  1375. if (this._isFallbackRoot(translated)) {
  1376. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(linkPlaceholder)) {
  1377. warn(("Fall back to translate the link placeholder '" + linkPlaceholder + "' with root locale."));
  1378. }
  1379. /* istanbul ignore if */
  1380. if (!this._root) { throw Error('unexpected error') }
  1381. var root = this._root.$i18n;
  1382. translated = root._translate(
  1383. root._getMessages(), root.locale, root.fallbackLocale,
  1384. linkPlaceholder, host, interpolateMode, values
  1385. );
  1386. }
  1387. translated = this._warnDefault(
  1388. locale, linkPlaceholder, translated, host,
  1389. isArray(values) ? values : [values],
  1390. interpolateMode
  1391. );
  1392. if (this._modifiers.hasOwnProperty(formatterName)) {
  1393. translated = this._modifiers[formatterName](translated);
  1394. } else if (defaultModifiers.hasOwnProperty(formatterName)) {
  1395. translated = defaultModifiers[formatterName](translated);
  1396. }
  1397. visitedLinkStack.pop();
  1398. // Replace the link with the translated
  1399. ret = !translated ? ret : ret.replace(link, translated);
  1400. }
  1401. return ret
  1402. };
  1403. VueI18n.prototype._createMessageContext = function _createMessageContext (values, formatter, path, interpolateMode) {
  1404. var this$1 = this;
  1405. var _list = isArray(values) ? values : [];
  1406. var _named = isObject(values) ? values : {};
  1407. var list = function (index) { return _list[index]; };
  1408. var named = function (key) { return _named[key]; };
  1409. var messages = this._getMessages();
  1410. var locale = this.locale;
  1411. return {
  1412. list: list,
  1413. named: named,
  1414. values: values,
  1415. formatter: formatter,
  1416. path: path,
  1417. messages: messages,
  1418. locale: locale,
  1419. linked: function (linkedKey) { return this$1._interpolate(locale, messages[locale] || {}, linkedKey, null, interpolateMode, undefined, [linkedKey]); }
  1420. }
  1421. };
  1422. VueI18n.prototype._render = function _render (message, interpolateMode, values, path) {
  1423. if (isFunction(message)) {
  1424. return message(
  1425. this._createMessageContext(values, this._formatter || defaultFormatter, path, interpolateMode)
  1426. )
  1427. }
  1428. var ret = this._formatter.interpolate(message, values, path);
  1429. // If the custom formatter refuses to work - apply the default one
  1430. if (!ret) {
  1431. ret = defaultFormatter.interpolate(message, values, path);
  1432. }
  1433. // if interpolateMode is **not** 'string' ('row'),
  1434. // return the compiled data (e.g. ['foo', VNode, 'bar']) with formatter
  1435. return interpolateMode === 'string' && !isString(ret) ? ret.join('') : ret
  1436. };
  1437. VueI18n.prototype._appendItemToChain = function _appendItemToChain (chain, item, blocks) {
  1438. var follow = false;
  1439. if (!includes(chain, item)) {
  1440. follow = true;
  1441. if (item) {
  1442. follow = item[item.length - 1] !== '!';
  1443. item = item.replace(/!/g, '');
  1444. chain.push(item);
  1445. if (blocks && blocks[item]) {
  1446. follow = blocks[item];
  1447. }
  1448. }
  1449. }
  1450. return follow
  1451. };
  1452. VueI18n.prototype._appendLocaleToChain = function _appendLocaleToChain (chain, locale, blocks) {
  1453. var follow;
  1454. var tokens = locale.split('-');
  1455. do {
  1456. var item = tokens.join('-');
  1457. follow = this._appendItemToChain(chain, item, blocks);
  1458. tokens.splice(-1, 1);
  1459. } while (tokens.length && (follow === true))
  1460. return follow
  1461. };
  1462. VueI18n.prototype._appendBlockToChain = function _appendBlockToChain (chain, block, blocks) {
  1463. var follow = true;
  1464. for (var i = 0; (i < block.length) && (isBoolean(follow)); i++) {
  1465. var locale = block[i];
  1466. if (isString(locale)) {
  1467. follow = this._appendLocaleToChain(chain, locale, blocks);
  1468. }
  1469. }
  1470. return follow
  1471. };
  1472. VueI18n.prototype._getLocaleChain = function _getLocaleChain (start, fallbackLocale) {
  1473. if (start === '') { return [] }
  1474. if (!this._localeChainCache) {
  1475. this._localeChainCache = {};
  1476. }
  1477. var chain = this._localeChainCache[start];
  1478. if (!chain) {
  1479. if (!fallbackLocale) {
  1480. fallbackLocale = this.fallbackLocale;
  1481. }
  1482. chain = [];
  1483. // first block defined by start
  1484. var block = [start];
  1485. // while any intervening block found
  1486. while (isArray(block)) {
  1487. block = this._appendBlockToChain(
  1488. chain,
  1489. block,
  1490. fallbackLocale
  1491. );
  1492. }
  1493. // last block defined by default
  1494. var defaults;
  1495. if (isArray(fallbackLocale)) {
  1496. defaults = fallbackLocale;
  1497. } else if (isObject(fallbackLocale)) {
  1498. /* $FlowFixMe */
  1499. if (fallbackLocale['default']) {
  1500. defaults = fallbackLocale['default'];
  1501. } else {
  1502. defaults = null;
  1503. }
  1504. } else {
  1505. defaults = fallbackLocale;
  1506. }
  1507. // convert defaults to array
  1508. if (isString(defaults)) {
  1509. block = [defaults];
  1510. } else {
  1511. block = defaults;
  1512. }
  1513. if (block) {
  1514. this._appendBlockToChain(
  1515. chain,
  1516. block,
  1517. null
  1518. );
  1519. }
  1520. this._localeChainCache[start] = chain;
  1521. }
  1522. return chain
  1523. };
  1524. VueI18n.prototype._translate = function _translate (
  1525. messages,
  1526. locale,
  1527. fallback,
  1528. key,
  1529. host,
  1530. interpolateMode,
  1531. args
  1532. ) {
  1533. var chain = this._getLocaleChain(locale, fallback);
  1534. var res;
  1535. for (var i = 0; i < chain.length; i++) {
  1536. var step = chain[i];
  1537. res =
  1538. this._interpolate(step, messages[step], key, host, interpolateMode, args, [key]);
  1539. if (!isNull(res)) {
  1540. if (step !== locale && process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) {
  1541. warn(("Fall back to translate the keypath '" + key + "' with '" + step + "' locale."));
  1542. }
  1543. return res
  1544. }
  1545. }
  1546. return null
  1547. };
  1548. VueI18n.prototype._t = function _t (key, _locale, messages, host) {
  1549. var ref;
  1550. var values = [], len = arguments.length - 4;
  1551. while ( len-- > 0 ) values[ len ] = arguments[ len + 4 ];
  1552. if (!key) { return '' }
  1553. var parsedArgs = parseArgs.apply(void 0, values);
  1554. if(this._escapeParameterHtml) {
  1555. parsedArgs.params = escapeParams(parsedArgs.params);
  1556. }
  1557. var locale = parsedArgs.locale || _locale;
  1558. var ret = this._translate(
  1559. messages, locale, this.fallbackLocale, key,
  1560. host, 'string', parsedArgs.params
  1561. );
  1562. if (this._isFallbackRoot(ret)) {
  1563. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) {
  1564. warn(("Fall back to translate the keypath '" + key + "' with root locale."));
  1565. }
  1566. /* istanbul ignore if */
  1567. if (!this._root) { throw Error('unexpected error') }
  1568. return (ref = this._root).$t.apply(ref, [ key ].concat( values ))
  1569. } else {
  1570. ret = this._warnDefault(locale, key, ret, host, values, 'string');
  1571. if (this._postTranslation && ret !== null && ret !== undefined) {
  1572. ret = this._postTranslation(ret, key);
  1573. }
  1574. return ret
  1575. }
  1576. };
  1577. VueI18n.prototype.t = function t (key) {
  1578. var ref;
  1579. var values = [], len = arguments.length - 1;
  1580. while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ];
  1581. return (ref = this)._t.apply(ref, [ key, this.locale, this._getMessages(), null ].concat( values ))
  1582. };
  1583. VueI18n.prototype._i = function _i (key, locale, messages, host, values) {
  1584. var ret =
  1585. this._translate(messages, locale, this.fallbackLocale, key, host, 'raw', values);
  1586. if (this._isFallbackRoot(ret)) {
  1587. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key)) {
  1588. warn(("Fall back to interpolate the keypath '" + key + "' with root locale."));
  1589. }
  1590. if (!this._root) { throw Error('unexpected error') }
  1591. return this._root.$i18n.i(key, locale, values)
  1592. } else {
  1593. return this._warnDefault(locale, key, ret, host, [values], 'raw')
  1594. }
  1595. };
  1596. VueI18n.prototype.i = function i (key, locale, values) {
  1597. /* istanbul ignore if */
  1598. if (!key) { return '' }
  1599. if (!isString(locale)) {
  1600. locale = this.locale;
  1601. }
  1602. return this._i(key, locale, this._getMessages(), null, values)
  1603. };
  1604. VueI18n.prototype._tc = function _tc (
  1605. key,
  1606. _locale,
  1607. messages,
  1608. host,
  1609. choice
  1610. ) {
  1611. var ref;
  1612. var values = [], len = arguments.length - 5;
  1613. while ( len-- > 0 ) values[ len ] = arguments[ len + 5 ];
  1614. if (!key) { return '' }
  1615. if (choice === undefined) {
  1616. choice = 1;
  1617. }
  1618. var predefined = { 'count': choice, 'n': choice };
  1619. var parsedArgs = parseArgs.apply(void 0, values);
  1620. parsedArgs.params = Object.assign(predefined, parsedArgs.params);
  1621. values = parsedArgs.locale === null ? [parsedArgs.params] : [parsedArgs.locale, parsedArgs.params];
  1622. return this.fetchChoice((ref = this)._t.apply(ref, [ key, _locale, messages, host ].concat( values )), choice)
  1623. };
  1624. VueI18n.prototype.fetchChoice = function fetchChoice (message, choice) {
  1625. /* istanbul ignore if */
  1626. if (!message || !isString(message)) { return null }
  1627. var choices = message.split('|');
  1628. choice = this.getChoiceIndex(choice, choices.length);
  1629. if (!choices[choice]) { return message }
  1630. return choices[choice].trim()
  1631. };
  1632. VueI18n.prototype.tc = function tc (key, choice) {
  1633. var ref;
  1634. var values = [], len = arguments.length - 2;
  1635. while ( len-- > 0 ) values[ len ] = arguments[ len + 2 ];
  1636. return (ref = this)._tc.apply(ref, [ key, this.locale, this._getMessages(), null, choice ].concat( values ))
  1637. };
  1638. VueI18n.prototype._te = function _te (key, locale, messages) {
  1639. var args = [], len = arguments.length - 3;
  1640. while ( len-- > 0 ) args[ len ] = arguments[ len + 3 ];
  1641. var _locale = parseArgs.apply(void 0, args).locale || locale;
  1642. return this._exist(messages[_locale], key)
  1643. };
  1644. VueI18n.prototype.te = function te (key, locale) {
  1645. return this._te(key, this.locale, this._getMessages(), locale)
  1646. };
  1647. VueI18n.prototype.getLocaleMessage = function getLocaleMessage (locale) {
  1648. return looseClone(this._vm.messages[locale] || {})
  1649. };
  1650. VueI18n.prototype.setLocaleMessage = function setLocaleMessage (locale, message) {
  1651. if (this._warnHtmlInMessage === 'warn' || this._warnHtmlInMessage === 'error') {
  1652. this._checkLocaleMessage(locale, this._warnHtmlInMessage, message);
  1653. }
  1654. this._vm.$set(this._vm.messages, locale, message);
  1655. };
  1656. VueI18n.prototype.mergeLocaleMessage = function mergeLocaleMessage (locale, message) {
  1657. if (this._warnHtmlInMessage === 'warn' || this._warnHtmlInMessage === 'error') {
  1658. this._checkLocaleMessage(locale, this._warnHtmlInMessage, message);
  1659. }
  1660. this._vm.$set(this._vm.messages, locale, merge(
  1661. typeof this._vm.messages[locale] !== 'undefined' && Object.keys(this._vm.messages[locale]).length
  1662. ? Object.assign({}, this._vm.messages[locale])
  1663. : {},
  1664. message
  1665. ));
  1666. };
  1667. VueI18n.prototype.getDateTimeFormat = function getDateTimeFormat (locale) {
  1668. return looseClone(this._vm.dateTimeFormats[locale] || {})
  1669. };
  1670. VueI18n.prototype.setDateTimeFormat = function setDateTimeFormat (locale, format) {
  1671. this._vm.$set(this._vm.dateTimeFormats, locale, format);
  1672. this._clearDateTimeFormat(locale, format);
  1673. };
  1674. VueI18n.prototype.mergeDateTimeFormat = function mergeDateTimeFormat (locale, format) {
  1675. this._vm.$set(this._vm.dateTimeFormats, locale, merge(this._vm.dateTimeFormats[locale] || {}, format));
  1676. this._clearDateTimeFormat(locale, format);
  1677. };
  1678. VueI18n.prototype._clearDateTimeFormat = function _clearDateTimeFormat (locale, format) {
  1679. // eslint-disable-next-line no-autofix/prefer-const
  1680. for (var key in format) {
  1681. var id = locale + "__" + key;
  1682. if (!this._dateTimeFormatters.hasOwnProperty(id)) {
  1683. continue
  1684. }
  1685. delete this._dateTimeFormatters[id];
  1686. }
  1687. };
  1688. VueI18n.prototype._localizeDateTime = function _localizeDateTime (
  1689. value,
  1690. locale,
  1691. fallback,
  1692. dateTimeFormats,
  1693. key
  1694. ) {
  1695. var _locale = locale;
  1696. var formats = dateTimeFormats[_locale];
  1697. var chain = this._getLocaleChain(locale, fallback);
  1698. for (var i = 0; i < chain.length; i++) {
  1699. var current = _locale;
  1700. var step = chain[i];
  1701. formats = dateTimeFormats[step];
  1702. _locale = step;
  1703. // fallback locale
  1704. if (isNull(formats) || isNull(formats[key])) {
  1705. if (step !== locale && process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) {
  1706. warn(("Fall back to '" + step + "' datetime formats from '" + current + "' datetime formats."));
  1707. }
  1708. } else {
  1709. break
  1710. }
  1711. }
  1712. if (isNull(formats) || isNull(formats[key])) {
  1713. return null
  1714. } else {
  1715. var format = formats[key];
  1716. var id = _locale + "__" + key;
  1717. var formatter = this._dateTimeFormatters[id];
  1718. if (!formatter) {
  1719. formatter = this._dateTimeFormatters[id] = new Intl.DateTimeFormat(_locale, format);
  1720. }
  1721. return formatter.format(value)
  1722. }
  1723. };
  1724. VueI18n.prototype._d = function _d (value, locale, key) {
  1725. /* istanbul ignore if */
  1726. if (process.env.NODE_ENV !== 'production' && !VueI18n.availabilities.dateTimeFormat) {
  1727. warn('Cannot format a Date value due to not supported Intl.DateTimeFormat.');
  1728. return ''
  1729. }
  1730. if (!key) {
  1731. return new Intl.DateTimeFormat(locale).format(value)
  1732. }
  1733. var ret =
  1734. this._localizeDateTime(value, locale, this.fallbackLocale, this._getDateTimeFormats(), key);
  1735. if (this._isFallbackRoot(ret)) {
  1736. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) {
  1737. warn(("Fall back to datetime localization of root: key '" + key + "'."));
  1738. }
  1739. /* istanbul ignore if */
  1740. if (!this._root) { throw Error('unexpected error') }
  1741. return this._root.$i18n.d(value, key, locale)
  1742. } else {
  1743. return ret || ''
  1744. }
  1745. };
  1746. VueI18n.prototype.d = function d (value) {
  1747. var args = [], len = arguments.length - 1;
  1748. while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
  1749. var locale = this.locale;
  1750. var key = null;
  1751. if (args.length === 1) {
  1752. if (isString(args[0])) {
  1753. key = args[0];
  1754. } else if (isObject(args[0])) {
  1755. if (args[0].locale) {
  1756. locale = args[0].locale;
  1757. }
  1758. if (args[0].key) {
  1759. key = args[0].key;
  1760. }
  1761. }
  1762. } else if (args.length === 2) {
  1763. if (isString(args[0])) {
  1764. key = args[0];
  1765. }
  1766. if (isString(args[1])) {
  1767. locale = args[1];
  1768. }
  1769. }
  1770. return this._d(value, locale, key)
  1771. };
  1772. VueI18n.prototype.getNumberFormat = function getNumberFormat (locale) {
  1773. return looseClone(this._vm.numberFormats[locale] || {})
  1774. };
  1775. VueI18n.prototype.setNumberFormat = function setNumberFormat (locale, format) {
  1776. this._vm.$set(this._vm.numberFormats, locale, format);
  1777. this._clearNumberFormat(locale, format);
  1778. };
  1779. VueI18n.prototype.mergeNumberFormat = function mergeNumberFormat (locale, format) {
  1780. this._vm.$set(this._vm.numberFormats, locale, merge(this._vm.numberFormats[locale] || {}, format));
  1781. this._clearNumberFormat(locale, format);
  1782. };
  1783. VueI18n.prototype._clearNumberFormat = function _clearNumberFormat (locale, format) {
  1784. // eslint-disable-next-line no-autofix/prefer-const
  1785. for (var key in format) {
  1786. var id = locale + "__" + key;
  1787. if (!this._numberFormatters.hasOwnProperty(id)) {
  1788. continue
  1789. }
  1790. delete this._numberFormatters[id];
  1791. }
  1792. };
  1793. VueI18n.prototype._getNumberFormatter = function _getNumberFormatter (
  1794. value,
  1795. locale,
  1796. fallback,
  1797. numberFormats,
  1798. key,
  1799. options
  1800. ) {
  1801. var _locale = locale;
  1802. var formats = numberFormats[_locale];
  1803. var chain = this._getLocaleChain(locale, fallback);
  1804. for (var i = 0; i < chain.length; i++) {
  1805. var current = _locale;
  1806. var step = chain[i];
  1807. formats = numberFormats[step];
  1808. _locale = step;
  1809. // fallback locale
  1810. if (isNull(formats) || isNull(formats[key])) {
  1811. if (step !== locale && process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) {
  1812. warn(("Fall back to '" + step + "' number formats from '" + current + "' number formats."));
  1813. }
  1814. } else {
  1815. break
  1816. }
  1817. }
  1818. if (isNull(formats) || isNull(formats[key])) {
  1819. return null
  1820. } else {
  1821. var format = formats[key];
  1822. var formatter;
  1823. if (options) {
  1824. // If options specified - create one time number formatter
  1825. formatter = new Intl.NumberFormat(_locale, Object.assign({}, format, options));
  1826. } else {
  1827. var id = _locale + "__" + key;
  1828. formatter = this._numberFormatters[id];
  1829. if (!formatter) {
  1830. formatter = this._numberFormatters[id] = new Intl.NumberFormat(_locale, format);
  1831. }
  1832. }
  1833. return formatter
  1834. }
  1835. };
  1836. VueI18n.prototype._n = function _n (value, locale, key, options) {
  1837. /* istanbul ignore if */
  1838. if (!VueI18n.availabilities.numberFormat) {
  1839. if (process.env.NODE_ENV !== 'production') {
  1840. warn('Cannot format a Number value due to not supported Intl.NumberFormat.');
  1841. }
  1842. return ''
  1843. }
  1844. if (!key) {
  1845. var nf = !options ? new Intl.NumberFormat(locale) : new Intl.NumberFormat(locale, options);
  1846. return nf.format(value)
  1847. }
  1848. var formatter = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options);
  1849. var ret = formatter && formatter.format(value);
  1850. if (this._isFallbackRoot(ret)) {
  1851. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key) && !this._isSilentFallbackWarn(key)) {
  1852. warn(("Fall back to number localization of root: key '" + key + "'."));
  1853. }
  1854. /* istanbul ignore if */
  1855. if (!this._root) { throw Error('unexpected error') }
  1856. return this._root.$i18n.n(value, Object.assign({}, { key: key, locale: locale }, options))
  1857. } else {
  1858. return ret || ''
  1859. }
  1860. };
  1861. VueI18n.prototype.n = function n (value) {
  1862. var args = [], len = arguments.length - 1;
  1863. while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
  1864. var locale = this.locale;
  1865. var key = null;
  1866. var options = null;
  1867. if (args.length === 1) {
  1868. if (isString(args[0])) {
  1869. key = args[0];
  1870. } else if (isObject(args[0])) {
  1871. if (args[0].locale) {
  1872. locale = args[0].locale;
  1873. }
  1874. if (args[0].key) {
  1875. key = args[0].key;
  1876. }
  1877. // Filter out number format options only
  1878. options = Object.keys(args[0]).reduce(function (acc, key) {
  1879. var obj;
  1880. if (includes(numberFormatKeys, key)) {
  1881. return Object.assign({}, acc, ( obj = {}, obj[key] = args[0][key], obj ))
  1882. }
  1883. return acc
  1884. }, null);
  1885. }
  1886. } else if (args.length === 2) {
  1887. if (isString(args[0])) {
  1888. key = args[0];
  1889. }
  1890. if (isString(args[1])) {
  1891. locale = args[1];
  1892. }
  1893. }
  1894. return this._n(value, locale, key, options)
  1895. };
  1896. VueI18n.prototype._ntp = function _ntp (value, locale, key, options) {
  1897. /* istanbul ignore if */
  1898. if (!VueI18n.availabilities.numberFormat) {
  1899. if (process.env.NODE_ENV !== 'production') {
  1900. warn('Cannot format to parts a Number value due to not supported Intl.NumberFormat.');
  1901. }
  1902. return []
  1903. }
  1904. if (!key) {
  1905. var nf = !options ? new Intl.NumberFormat(locale) : new Intl.NumberFormat(locale, options);
  1906. return nf.formatToParts(value)
  1907. }
  1908. var formatter = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options);
  1909. var ret = formatter && formatter.formatToParts(value);
  1910. if (this._isFallbackRoot(ret)) {
  1911. if (process.env.NODE_ENV !== 'production' && !this._isSilentTranslationWarn(key)) {
  1912. warn(("Fall back to format number to parts of root: key '" + key + "' ."));
  1913. }
  1914. /* istanbul ignore if */
  1915. if (!this._root) { throw Error('unexpected error') }
  1916. return this._root.$i18n._ntp(value, locale, key, options)
  1917. } else {
  1918. return ret || []
  1919. }
  1920. };
  1921. Object.defineProperties( VueI18n.prototype, prototypeAccessors );
  1922. var availabilities;
  1923. // $FlowFixMe
  1924. Object.defineProperty(VueI18n, 'availabilities', {
  1925. get: function get () {
  1926. if (!availabilities) {
  1927. var intlDefined = typeof Intl !== 'undefined';
  1928. availabilities = {
  1929. dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
  1930. numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
  1931. };
  1932. }
  1933. return availabilities
  1934. }
  1935. });
  1936. VueI18n.install = install;
  1937. VueI18n.version = '8.27.2';
  1938. export default VueI18n;