Skip to content

Commit

Permalink
Revert "同步源仓库到Fock仓库 (#1)"
Browse files Browse the repository at this point in the history
This reverts commit 8f8a88b.
  • Loading branch information
xuhongbo authored Mar 25, 2019
1 parent 8f8a88b commit ed0c17d
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 682 deletions.
9 changes: 0 additions & 9 deletions decls/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ declare type DateTimeFormatResult = string;
declare type NumberFormatResult = string;
declare type MissingHandler = (locale: Locale, key: Path, vm?: any) => string | void;

declare type FormattedNumberPartType = 'currency' | 'decimal' | 'fraction' | 'group' | 'infinity' | 'integer' | 'literal' | 'minusSign' | 'nan' | 'plusSign' | 'percentSign';
declare type FormattedNumberPart = {
type: FormattedNumberPartType,
value: string,
};
// This array is the same as Intl.NumberFormat.formatToParts() return value:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts#Return_value
declare type NumberFormatToPartsResult = Array<FormattedNumberPart>;

declare type I18nOptions = {
locale?: Locale,
fallbackLocale?: Locale,
Expand Down
70 changes: 0 additions & 70 deletions examples/number-formatting/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"dist/vue-i18n.min.js",
"dist/vue-i18n.common.js",
"dist/vue-i18n.esm.js",
"src/**/*.js",
"src/*.js",
"types/*.d.ts",
"decls"
],
Expand Down
2 changes: 1 addition & 1 deletion src/components/interpolation.js → src/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { warn } from '../util'
import { warn } from './util'

export default {
name: 'i18n',
Expand Down
63 changes: 0 additions & 63 deletions src/components/number.js

This file was deleted.

54 changes: 19 additions & 35 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ import {
isObject,
looseClone,
remove,
merge,
numberFormatKeys
merge
} from './util'
import BaseFormatter from './format'
import I18nPath from './path'

import type { PathValue } from './path'

const numberFormatKeys = [
'style',
'currency',
'currencyDisplay',
'useGrouping',
'minimumIntegerDigits',
'minimumFractionDigits',
'maximumFractionDigits',
'minimumSignificantDigits',
'maximumSignificantDigits',
'localeMatcher',
'formatMatcher'
]
const linkKeyMatcher = /(?:@(?:\.[a-z]+)?:(?:[\w\-_|.]+|\([\w\-_|.]+\)))/g
const linkKeyPrefixMatcher = /^@(?:\.([a-z]+))?:/
const bracketsMatcher = /[()]/g
Expand Down Expand Up @@ -614,14 +626,14 @@ export default class VueI18n {
this._vm.$set(this._vm.numberFormats, locale, merge(this._vm.numberFormats[locale] || {}, format))
}

_getNumberFormatter (
_localizeNumber (
value: number,
locale: Locale,
fallback: Locale,
numberFormats: NumberFormats,
key: string,
options: ?NumberFormatOptions
): ?Object {
): ?NumberFormatResult {
let _locale: Locale = locale
let formats: NumberFormat = numberFormats[_locale]

Expand Down Expand Up @@ -650,7 +662,7 @@ export default class VueI18n {
formatter = this._numberFormatters[id] = new Intl.NumberFormat(_locale, format)
}
}
return formatter
return formatter.format(value)
}
}

Expand All @@ -668,8 +680,8 @@ export default class VueI18n {
return nf.format(value)
}

const formatter: ?Object = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options)
const ret: ?NumberFormatResult = formatter && formatter.format(value)
const ret: ?NumberFormatResult =
this._localizeNumber(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options)
if (this._isFallbackRoot(ret)) {
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) {
warn(`Fall back to number localization of root: key '${key}' .`)
Expand Down Expand Up @@ -717,34 +729,6 @@ export default class VueI18n {

return this._n(value, locale, key, options)
}

_ntp (value: number, locale: Locale, key: ?string, options: ?NumberFormatOptions): NumberFormatToPartsResult {
/* istanbul ignore if */
if (!VueI18n.availabilities.numberFormat) {
if (process.env.NODE_ENV !== 'production') {
warn('Cannot format to parts a Number value due to not supported Intl.NumberFormat.')
}
return []
}

if (!key) {
const nf = !options ? new Intl.NumberFormat(locale) : new Intl.NumberFormat(locale, options)
return nf.formatToParts(value)
}

const formatter: ?Object = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options)
const ret: ?NumberFormatToPartsResult = formatter && formatter.formatToParts(value)
if (this._isFallbackRoot(ret)) {
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) {
warn(`Fall back to format number to parts of root: key '${key}' .`)
}
/* istanbul ignore if */
if (!this._root) { throw Error('unexpected error') }
return this._root.$i18n._ntp(value, locale, key, options)
} else {
return ret || []
}
}
}

let availabilities: IntlAvailability
Expand Down
6 changes: 2 additions & 4 deletions src/install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { warn } from './util'
import extend from './extend'
import mixin from './mixin'
import interpolationComponent from './components/interpolation'
import numberComponent from './components/number'
import component from './component'
import { bind, update, unbind } from './directive'

export let Vue
Expand All @@ -27,8 +26,7 @@ export function install (_Vue) {
extend(Vue)
Vue.mixin(mixin)
Vue.directive('t', { bind, update, unbind })
Vue.component(interpolationComponent.name, interpolationComponent)
Vue.component(numberComponent.name, numberComponent)
Vue.component(component.name, component)

// use simple mergeStrategies to prevent i18n instance lose '__proto__'
const strats = Vue.config.optionMergeStrategies
Expand Down
1 change: 1 addition & 0 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function getPathCharType (ch: ?string): string {
case 0x2D: // -
return 'ident'

case 0x20: // Space
case 0x09: // Tab
case 0x0A: // Newline
case 0x0D: // Return
Expand Down
18 changes: 0 additions & 18 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
/* @flow */

/**
* constants
*/

export const numberFormatKeys = [
'style',
'currency',
'currencyDisplay',
'useGrouping',
'minimumIntegerDigits',
'minimumFractionDigits',
'maximumFractionDigits',
'minimumSignificantDigits',
'maximumSignificantDigits',
'localeMatcher',
'formatMatcher'
]

/**
* utilities
*/
Expand Down
11 changes: 0 additions & 11 deletions test/e2e/test/number_formatting.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ describe('basic', () => {
it('should be translated', () => {
assert.strictEqual(i18n.t('message.format'), messages.en.message.format)
})

it('should be translated if keypath contains spaces', () => {
assert.strictEqual(
i18n.t('message.Hello {0}', ['kazupon']),
'Hello kazupon'
)
})
})

describe('array keypath', () => {
Expand Down
1 change: 0 additions & 1 deletion test/unit/fixture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default {
circular2: 'Bar @:message.circular3',
circular3: 'Buz @:message.circular1',
linkTwice: '@:message.hello: @:message.hello',
'Hello {0}': 'Hello {0}',
'hyphen-locale': 'hello hyphen',
'1234': 'Number-based keys are found',
'1mixedKey': 'Mixed keys are not found.',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/interpolation.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Component from '../../src/components/interpolation'
import Component from '../../src/component'

const messages = {
en: {
Expand Down
Loading

0 comments on commit ed0c17d

Please sign in to comment.