vue-i18n 7.1.2 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ <a name="7.3.2"></a>
2
+ ## [7.3.2](https://github.com/kazupon/vue-i18n/compare/v7.3.1...v7.3.2) (2017-10-19)
3
+
4
+
5
+ ### :zap: Improvements
6
+
7
+ * **typescript:** fix import problem of vue2.5 because of the types update ([#238](https://github.com/kazupon/vue-i18n/issues/238)) by [@peterchealse](https://github.com/peterchealse) ([cb98347](https://github.com/kazupon/vue-i18n/commit/cb98347)), closes [#238](https://github.com/kazupon/vue-i18n/issues/238)
8
+
9
+
10
+
11
+ <a name="7.3.1"></a>
12
+ ## [7.3.1](https://github.com/kazupon/vue-i18n/compare/v7.3.0...v7.3.1) (2017-10-04)
13
+
14
+
15
+ ### :bug: Bug Fixes
16
+
17
+ * **directive:** fix cannot locale reactivity ([e1fc12e](https://github.com/kazupon/vue-i18n/commit/e1fc12e)), closes [#227](https://github.com/kazupon/vue-i18n/issues/227)
18
+
19
+
20
+
21
+ <a name="7.3.0"></a>
22
+ # [7.3.0](https://github.com/kazupon/vue-i18n/compare/v7.2.0...v7.3.0) (2017-09-22)
23
+
24
+
25
+ ### :star: New Features
26
+
27
+ * **directives:** support v-t custom directive (welcome back!) ([af9a2e7](https://github.com/kazupon/vue-i18n/commit/af9a2e7))
28
+
29
+
30
+ ### :up: Updates
31
+
32
+ * **typing:** fix flowtype ([fa06f44](https://github.com/kazupon/vue-i18n/commit/fa06f44))
33
+
34
+
35
+
36
+ <a name="7.2.0"></a>
37
+ # [7.2.0](https://github.com/kazupon/vue-i18n/compare/v7.1.2...v7.2.0) (2017-08-28)
38
+
39
+
40
+ ### :star: New Features
41
+
42
+ * **interpolation:** list formatting refactor and places/place feature ([#218](https://github.com/kazupon/vue-i18n/issues/218)) by [@myst729](https://github.com/myst729) ([0f0f3ff](https://github.com/kazupon/vue-i18n/commit/0f0f3ff))
43
+
44
+
45
+
1
46
  <a name="7.1.2"></a>
2
47
  ## [7.1.2](https://github.com/kazupon/vue-i18n/compare/v7.1.1...v7.1.2) (2017-08-25)
3
48
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # vue-i18n
1
+ # :globe_with_meridians: vue-i18n
2
2
 
3
3
  [![Build Status](https://circleci.com/gh/kazupon/vue-i18n/tree/dev.svg?style=shield)](https://circleci.com/gh/kazupon/vue-i18n/tree/dev)
4
4
  [![Coverage Status](https://codecov.io/gh/kazupon/vue-i18n/branch/dev/graph/badge.svg)](https://codecov.io/gh/kazupon/vue-i18n)
package/decls/i18n.js CHANGED
@@ -90,7 +90,7 @@ declare interface I18n {
90
90
  setLocaleMessage (locale: Locale, message: LocaleMessageObject): void,
91
91
  mergeLocaleMessage (locale: Locale, message: LocaleMessageObject): void,
92
92
  t (key: Path, ...values: any): TranslateResult,
93
- i (key: Path, ...values: any): TranslateResult,
93
+ i (key: Path, locale: Locale, values: Object): TranslateResult,
94
94
  tc (key: Path, choice?: number, ...values: any): TranslateResult,
95
95
  te (key: Path, locale?: Locale): boolean,
96
96
  getDateTimeFormat (locale: Locale): DateTimeFormat,
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v7.1.2
2
+ * vue-i18n v7.3.2
3
3
  * (c) 2017 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -126,6 +126,39 @@ function merge (target) {
126
126
  return output
127
127
  }
128
128
 
129
+ function looseEqual (a, b) {
130
+ if (a === b) { return true }
131
+ var isObjectA = isObject(a);
132
+ var isObjectB = isObject(b);
133
+ if (isObjectA && isObjectB) {
134
+ try {
135
+ var isArrayA = Array.isArray(a);
136
+ var isArrayB = Array.isArray(b);
137
+ if (isArrayA && isArrayB) {
138
+ return a.length === b.length && a.every(function (e, i) {
139
+ return looseEqual(e, b[i])
140
+ })
141
+ } else if (!isArrayA && !isArrayB) {
142
+ var keysA = Object.keys(a);
143
+ var keysB = Object.keys(b);
144
+ return keysA.length === keysB.length && keysA.every(function (key) {
145
+ return looseEqual(a[key], b[key])
146
+ })
147
+ } else {
148
+ /* istanbul ignore next */
149
+ return false
150
+ }
151
+ } catch (e) {
152
+ /* istanbul ignore next */
153
+ return false
154
+ }
155
+ } else if (!isObjectA && !isObjectB) {
156
+ return String(a) === String(b)
157
+ } else {
158
+ return false
159
+ }
160
+ }
161
+
129
162
  var canUseDateTimeFormat =
130
163
  typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat !== 'undefined';
131
164
 
@@ -289,6 +322,9 @@ var component = {
289
322
  },
290
323
  locale: {
291
324
  type: String
325
+ },
326
+ places: {
327
+ type: [Array, Object]
292
328
  }
293
329
  },
294
330
  render: function render (h, ref) {
@@ -298,6 +334,11 @@ var component = {
298
334
  var parent = ref.parent;
299
335
 
300
336
  var i18n = parent.$i18n;
337
+
338
+ children = (children || []).filter(function (child) {
339
+ return child.tag || (child.text = child.text.trim())
340
+ });
341
+
301
342
  if (!i18n) {
302
343
  if (process.env.NODE_ENV !== 'production') {
303
344
  warn('Cannot find VueI18n instance!');
@@ -308,18 +349,131 @@ var component = {
308
349
  var path = props.path;
309
350
  var locale = props.locale;
310
351
 
311
- var params = [];
312
- locale && params.push(locale);
313
- children.forEach(function (child) {
314
- if (child.tag || child.text.trim()) {
315
- params.push(child);
352
+ var params = {};
353
+ var places = props.places || {};
354
+
355
+ var hasPlaces = Array.isArray(places)
356
+ ? places.length > 0
357
+ : Object.keys(places).length > 0;
358
+
359
+ var everyPlace = children.every(function (child) {
360
+ if (child.data && child.data.attrs) {
361
+ var place = child.data.attrs.place;
362
+ return (typeof place !== 'undefined') && place !== ''
316
363
  }
317
364
  });
318
365
 
319
- return h(props.tag, data, i18n.i.apply(i18n, [ path ].concat( params )))
366
+ if (hasPlaces && children.length > 0 && !everyPlace) {
367
+ warn('If places prop is set, all child elements must have place prop set.');
368
+ }
369
+
370
+ if (Array.isArray(places)) {
371
+ places.forEach(function (el, i) {
372
+ params[i] = el;
373
+ });
374
+ } else {
375
+ Object.keys(places).forEach(function (key) {
376
+ params[key] = places[key];
377
+ });
378
+ }
379
+
380
+ children.forEach(function (child, i) {
381
+ var key = everyPlace
382
+ ? ("" + (child.data.attrs.place))
383
+ : ("" + i);
384
+ params[key] = child;
385
+ });
386
+
387
+ return h(props.tag, data, i18n.i(path, locale, params))
320
388
  }
321
389
  };
322
390
 
391
+ /* */
392
+
393
+ function bind (el, binding, vnode) {
394
+ if (!assert(el, vnode)) { return }
395
+
396
+ t$1(el, binding, vnode);
397
+ }
398
+
399
+ function update (el, binding, vnode, oldVNode) {
400
+ if (!assert(el, vnode)) { return }
401
+
402
+ if (localeEqual(el, vnode) && looseEqual(binding.value, binding.oldValue)) { return }
403
+
404
+ t$1(el, binding, vnode);
405
+ }
406
+
407
+ function assert (el, vnode) {
408
+ var vm = vnode.context;
409
+ if (!vm) {
410
+ warn('not exist Vue instance in VNode context');
411
+ return false
412
+ }
413
+
414
+ if (!vm.$i18n) {
415
+ warn('not exist VueI18n instance in Vue instance');
416
+ return false
417
+ }
418
+
419
+ return true
420
+ }
421
+
422
+ function localeEqual (el, vnode) {
423
+ var vm = vnode.context;
424
+ return el._locale === vm.$i18n.locale
425
+ }
426
+
427
+ function t$1 (el, binding, vnode) {
428
+ var value = binding.value;
429
+
430
+ var ref = parseValue(value);
431
+ var path = ref.path;
432
+ var locale = ref.locale;
433
+ var args = ref.args;
434
+ if (!path && !locale && !args) {
435
+ warn('not support value type');
436
+ return
437
+ }
438
+
439
+ if (!path) {
440
+ warn('required `path` in v-t directive');
441
+ return
442
+ }
443
+
444
+ var vm = vnode.context;
445
+ el._vt = el.textContent = (ref$1 = vm.$i18n).t.apply(ref$1, [ path ].concat( makeParams(locale, args) ));
446
+ el._locale = vm.$i18n.locale;
447
+ var ref$1;
448
+ }
449
+
450
+ function parseValue (value) {
451
+ var path;
452
+ var locale;
453
+ var args;
454
+
455
+ if (typeof value === 'string') {
456
+ path = value;
457
+ } else if (isPlainObject(value)) {
458
+ path = value.path;
459
+ locale = value.locale;
460
+ args = value.args;
461
+ }
462
+
463
+ return { path: path, locale: locale, args: args }
464
+ }
465
+
466
+ function makeParams (locale, args) {
467
+ var params = [];
468
+
469
+ locale && params.push(locale);
470
+ if (args && (Array.isArray(args) || isPlainObject(args))) {
471
+ params.push(args);
472
+ }
473
+
474
+ return params
475
+ }
476
+
323
477
  var Vue;
324
478
 
325
479
  function install (_Vue) {
@@ -345,6 +499,7 @@ function install (_Vue) {
345
499
 
346
500
  extend(Vue);
347
501
  Vue.mixin(mixin);
502
+ Vue.directive('t', { bind: bind, update: update });
348
503
  Vue.component(component.name, component);
349
504
 
350
505
  // use object-based merge strategy
@@ -429,13 +584,7 @@ function compile (tokens, values) {
429
584
  compiled.push(token.value);
430
585
  break
431
586
  case 'list':
432
- if (mode === 'list') {
433
- compiled.push(values[parseInt(token.value, 10)]);
434
- } else {
435
- if (process.env.NODE_ENV !== 'production') {
436
- warn(("Type of token '" + (token.type) + "' and format of value '" + mode + "' don't match!"));
437
- }
438
- }
587
+ compiled.push(values[parseInt(token.value, 10)]);
439
588
  break
440
589
  case 'named':
441
590
  if (mode === 'named') {
@@ -1070,10 +1219,7 @@ VueI18n.prototype.t = function t (key) {
1070
1219
  var ref;
1071
1220
  };
1072
1221
 
1073
- VueI18n.prototype._i = function _i (key, locale, messages, host) {
1074
- var values = [], len = arguments.length - 4;
1075
- while ( len-- > 0 ) values[ len ] = arguments[ len + 4 ];
1076
-
1222
+ VueI18n.prototype._i = function _i (key, locale, messages, host, values) {
1077
1223
  var ret =
1078
1224
  this._translate(messages, locale, this.fallbackLocale, key, host, 'raw', values);
1079
1225
  if (this._isFallbackRoot(ret)) {
@@ -1081,47 +1227,34 @@ VueI18n.prototype._i = function _i (key, locale, messages, host) {
1081
1227
  warn(("Fall back to interpolate the keypath '" + key + "' with root locale."));
1082
1228
  }
1083
1229
  if (!this._root) { throw Error('unexpected error') }
1084
- return (ref = this._root).i.apply(ref, [ key ].concat( values ))
1230
+ return this._root.i(key, locale, values)
1085
1231
  } else {
1086
1232
  return this._warnDefault(locale, key, ret, host)
1087
1233
  }
1088
- var ref;
1089
1234
  };
1090
1235
 
1091
- VueI18n.prototype.i = function i (key) {
1092
- var values = [], len = arguments.length - 1;
1093
- while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ];
1094
-
1236
+ VueI18n.prototype.i = function i (key, locale, values) {
1095
1237
  /* istanbul ignore if */
1096
1238
  if (!key) { return '' }
1097
1239
 
1098
- var locale = this.locale;
1099
- var index = 0;
1100
- if (typeof values[0] === 'string') {
1101
- locale = values[0];
1102
- index = 1;
1240
+ if (typeof locale !== 'string') {
1241
+ locale = this.locale;
1103
1242
  }
1104
1243
 
1105
- var params = [];
1106
- for (var i = index; i < values.length; i++) {
1107
- params.push(values[i]);
1108
- }
1109
-
1110
- return (ref = this)._i.apply(ref, [ key, locale, this._getMessages(), null ].concat( params ))
1111
- var ref;
1244
+ return this._i(key, locale, this._getMessages(), null, values)
1112
1245
  };
1113
1246
 
1114
1247
  VueI18n.prototype._tc = function _tc (
1115
1248
  key,
1116
1249
  _locale,
1117
1250
  messages,
1118
- host,
1119
- choice
1251
+ host,
1252
+ choice
1120
1253
  ) {
1121
1254
  var values = [], len = arguments.length - 5;
1122
1255
  while ( len-- > 0 ) values[ len ] = arguments[ len + 5 ];
1123
1256
 
1124
- if (!key) { return '' }
1257
+ if (!key) { return '' }
1125
1258
  if (choice === undefined) {
1126
1259
  choice = 1;
1127
1260
  }
@@ -1157,7 +1290,7 @@ VueI18n.prototype.setLocaleMessage = function setLocaleMessage (locale, message)
1157
1290
  this._vm.messages[locale] = message;
1158
1291
  };
1159
1292
 
1160
- VueI18n.prototype.mergeLocaleMessage = function mergeLocaleMessage (locale, message) {
1293
+ VueI18n.prototype.mergeLocaleMessage = function mergeLocaleMessage (locale, message) {
1161
1294
  this._vm.messages[locale] = Vue.util.extend(this._vm.messages[locale] || {}, message);
1162
1295
  };
1163
1296
 
@@ -1243,16 +1376,16 @@ VueI18n.prototype.d = function d (value) {
1243
1376
  } else if (isObject(args[0])) {
1244
1377
  if (args[0].locale) {
1245
1378
  locale = args[0].locale;
1246
- }
1247
- if (args[0].key) {
1379
+ }
1380
+ if (args[0].key) {
1248
1381
  key = args[0].key;
1249
1382
  }
1250
1383
  }
1251
1384
  } else if (args.length === 2) {
1252
- if (typeof args[0] === 'string') {
1253
- key = args[0];
1254
- }
1255
- if (typeof args[1] === 'string') {
1385
+ if (typeof args[0] === 'string') {
1386
+ key = args[0];
1387
+ }
1388
+ if (typeof args[1] === 'string') {
1256
1389
  locale = args[1];
1257
1390
  }
1258
1391
  }
@@ -1353,10 +1486,10 @@ VueI18n.prototype.n = function n (value) {
1353
1486
  }
1354
1487
  if (typeof args[1] === 'string') {
1355
1488
  locale = args[1];
1356
- }
1357
1489
  }
1490
+ }
1358
1491
 
1359
- return this._n(value, locale, key)
1492
+ return this._n(value, locale, key)
1360
1493
  };
1361
1494
 
1362
1495
  Object.defineProperties( VueI18n.prototype, prototypeAccessors );
@@ -1366,7 +1499,7 @@ VueI18n.availabilities = {
1366
1499
  numberFormat: canUseNumberFormat
1367
1500
  };
1368
1501
  VueI18n.install = install;
1369
- VueI18n.version = '7.1.2';
1502
+ VueI18n.version = '7.3.2';
1370
1503
 
1371
1504
  /* istanbul ignore if */
1372
1505
  if (typeof window !== 'undefined' && window.Vue) {