Skip to content

Commit

Permalink
Merge pull request #768 from iamkun/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
iamkun authored Jan 6, 2020
2 parents 6b587da + 3f080f7 commit 2cc9d8f
Show file tree
Hide file tree
Showing 34 changed files with 500 additions and 49 deletions.
6 changes: 6 additions & 0 deletions docs/en/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,9 @@ plugin [`MinMax`](./Plugin.md#minmax)
`.calendar` to display calendar time

plugin [`Calendar`](./Plugin.md#calendar)

### UpdateLocale

`.updateLocale` to update a locale's properties

plugin [`UpdateLocale`](./Plugin.md#updateLocale)
4 changes: 3 additions & 1 deletion docs/en/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ dayjs()

## Customize

You could create your own locale.
You could update locale config via plugin [`UpdateLocale`](./Plugin.md#updateLocale)

You could also create your own locale.

Feel free to open a pull request to share your locale.

Expand Down
13 changes: 13 additions & 0 deletions docs/en/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,19 @@ dayjs().calendar(null, {
})
```

### UpdateLocale

- UpdateLocale adds `.updateLocale` API to update a locale's properties.

```javascript
import updateLocale from 'dayjs/plugin/updateLocale'
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
months : String[]
})
```

## Customize

You could build your own Day.js plugin to meet different needs.
Expand Down
6 changes: 6 additions & 0 deletions docs/es-es/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,9 @@ plugin [`MinMax`](./Plugin.md#minmax)
`.calendar` to display calendar time

plugin [`Calendar`](./Plugin.md#calendar)

### UpdateLocale

`.updateLocale` to update a locale's properties

plugin [`UpdateLocale`](./Plugin.md#updateLocale)
4 changes: 3 additions & 1 deletion docs/es-es/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ dayjs()

## Personalización

You could create your own locale.
You could update locale config via plugin [`UpdateLocale`](./Plugin.md#updateLocale)

You could also create your own locale.

Feel free to open a pull request to share your locale.

Expand Down
13 changes: 13 additions & 0 deletions docs/es-es/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ dayjs().calendar(null, {
})
```

### UpdateLocale

- UpdateLocale adds `.updateLocale` API to update a locale's properties.

```javascript
import updateLocale from 'dayjs/plugin/updateLocale'
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
months : String[]
})
```

## Personalización

Puedes construir tu propio complemento de Day.js para cubrir tus necesidades.
Expand Down
6 changes: 6 additions & 0 deletions docs/ja/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,9 @@ UTC でパースや表示をしたい場合は、[`UTC`](./Plugin.md#utc)プラ
`.calendar`で与えた日付のカレンダー上の情報が得られます。

プラグイン [`Calendar`](./Plugin.md#calendar)

### UpdateLocale

`.updateLocale` to update a locale's properties

plugin [`UpdateLocale`](./Plugin.md#updateLocale)
2 changes: 2 additions & 0 deletions docs/ja/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ dayjs()

## カスタマイズ

You could update locale config via plugin [`UpdateLocale`](./Plugin.md#updateLocale)

独自のロケールを作成することもできます。

あなたのプラグインを共有する pull request を是非送ってみてください。
Expand Down
13 changes: 13 additions & 0 deletions docs/ja/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ dayjs().calendar(null, {
})
```

### UpdateLocale

- UpdateLocale adds `.updateLocale` API to update a locale's properties.

```javascript
import updateLocale from 'dayjs/plugin/updateLocale'
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
months : String[]
})
```

## カスタマイズ

さまざまなニーズに合わせて独自の Day.js プラグインを構築することができます。
Expand Down
6 changes: 6 additions & 0 deletions docs/ko/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,9 @@ plugin [`MinMax`](./Plugin.md#minmax)
`.calendar` to display calendar time

plugin [`Calendar`](./Plugin.md#calendar)

### UpdateLocale

`.updateLocale` to update a locale's properties

plugin [`UpdateLocale`](./Plugin.md#updateLocale)
2 changes: 2 additions & 0 deletions docs/ko/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ dayjs()

## Customize

You could update locale config via plugin [`UpdateLocale`](./Plugin.md#updateLocale)

당신만의 locale을 만들 수 있습니다.

locale을 공휴하기위해 풀 리퀘스트를 여십시오.
Expand Down
13 changes: 13 additions & 0 deletions docs/ko/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,19 @@ dayjs().calendar(null, {
})
```

### UpdateLocale

- UpdateLocale adds `.updateLocale` API to update a locale's properties.

```javascript
import updateLocale from 'dayjs/plugin/updateLocale'
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
months : String[]
})
```

## Customize

다양한 요구를 충족하기위해 자신만의 Day.js 플러그인을 만들 수 있습니다.
Expand Down
6 changes: 6 additions & 0 deletions docs/pt-br/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,9 @@ plugin [`MinMax`](./Plugin.md#minmax)
`.calendar` to display calendar time

plugin [`Calendar`](./Plugin.md#calendar)

### UpdateLocale

`.updateLocale` to update a locale's properties

plugin [`UpdateLocale`](./Plugin.md#updateLocale)
2 changes: 2 additions & 0 deletions docs/pt-br/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ dayjs()

## Customizar

You could update locale config via plugin [`UpdateLocale`](./Plugin.md#updateLocale)

Você pode criar o seu próprio _locale_.

Sinta-se a vontade para abrir uma pull request e compartilhar sua _locale_.
Expand Down
13 changes: 13 additions & 0 deletions docs/pt-br/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ dayjs().calendar(null, {
})
```

### UpdateLocale

- UpdateLocale adds `.updateLocale` API to update a locale's properties.

```javascript
import updateLocale from 'dayjs/plugin/updateLocale'
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
months : String[]
})
```

## Customizar

Você também pode construir seu próprio plugin Day.js para diferentes necessidades.
Expand Down
6 changes: 6 additions & 0 deletions docs/zh-cn/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,9 @@ plugin [`MinMax`](./Plugin.md#minmax)
`.calendar` 来显示日历时间

plugin [`Calendar`](./Plugin.md#calendar)

### 更新语言配置

`.updateLocale` 来更新语言配置的属性

plugin [`UpdateLocale`](./Plugin.md#updateLocale)
18 changes: 17 additions & 1 deletion docs/zh-cn/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ dayjs()

## 自定义

你可以根据需要自由的编写一个 Day.js 语言配置
你可以使用 [`UpdateLocale`](./Plugin.md#updateLocale) 插件来更新语言配置

你还可以根据需要自由的编写一个 Day.js 语言配置

同时欢迎提交 PR 与大家分享你的语言配置

Expand All @@ -93,6 +95,20 @@ const localeObject = {
months: 'Enero_Febrero ... '.split('_'), // 月份 Array
monthsShort: 'Jan_F'.split('_'), // 可选, 短的月份 Array, 如果没提供则使用前三个字符
ordinal: n => `${n}º`, // 序号生成工厂函数 Function (number) => return number + output
formats: {
// 时间日期格式 - 长
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A',
// 时间日期格式 - 短
l: 'D/M/YYYY',
ll: 'D MMM, YYYY',
lll: 'D MMM, YYYY h:mm A',
llll: 'ddd, MMM D, YYYY h:mm A'
},
relativeTime: {
// 相对时间, %s %d 不用翻译
future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours
Expand Down
13 changes: 13 additions & 0 deletions docs/zh-cn/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ dayjs().calendar(null, {
})
```

### UpdateLocale

- UpdateLocale 增加了 `.updateLocale` API 来更新语言配置的属性。

```javascript
import updateLocale from 'dayjs/plugin/updateLocale'
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
months : String[]
})
```

## 自定义

你可以根据需要自由的编写一个 Day.js 插件
Expand Down
69 changes: 58 additions & 11 deletions src/locale/cs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
import dayjs from 'dayjs'

function plural(n) {
return (n > 1) && (n < 5) && (~~(n / 10) !== 1) // eslint-disable-line
}
/* eslint-disable */
function translate(number, withoutSuffix, key, isFuture) {
const result = `${number} `
switch (key) {
case 's': // a few seconds / in a few seconds / a few seconds ago
return (withoutSuffix || isFuture) ? 'pár sekund' : 'pár sekundami'
case 'm': // a minute / in a minute / a minute ago
return withoutSuffix ? 'minuta' : (isFuture ? 'minutu' : 'minutou')
case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'minuty' : 'minut')
}
return `${result}minutami`
case 'h': // an hour / in an hour / an hour ago
return withoutSuffix ? 'hodina' : (isFuture ? 'hodinu' : 'hodinou')
case 'hh': // 9 hours / in 9 hours / 9 hours ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'hodiny' : 'hodin')
}
return `${result}hodinami`
case 'd': // a day / in a day / a day ago
return (withoutSuffix || isFuture) ? 'den' : 'dnem'
case 'dd': // 9 days / in 9 days / 9 days ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'dny' : 'dní')
}
return `${result}dny`
case 'M': // a month / in a month / a month ago
return (withoutSuffix || isFuture) ? 'měsíc' : 'měsícem'
case 'MM': // 9 months / in 9 months / 9 months ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'měsíce' : 'měsíců')
}
return `${result}měsíci`
case 'y': // a year / in a year / a year ago
return (withoutSuffix || isFuture) ? 'rok' : 'rokem'
case 'yy': // 9 years / in 9 years / 9 years ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'roky' : 'let')
}
return `${result}lety`
}
}
/* eslint-enable */
const locale = {
name: 'cs',
weekdays: 'neděle_pondělí_úterý_středa_čtvrtek_pátek_sobota'.split('_'),
Expand All @@ -21,17 +68,17 @@ const locale = {
relativeTime: {
future: 'za %s',
past: 'před %s',
s: 'několik sekund',
m: 'minuta',
mm: '%d minut',
h: 'hodina',
hh: '%d hodin',
d: 'den',
dd: '%d dnů',
M: 'měsíc',
MM: '%d měsíců',
y: 'rok',
yy: '%d roků'
s: translate,
m: translate,
mm: translate,
h: translate,
hh: translate,
d: translate,
dd: translate,
M: translate,
MM: translate,
y: translate,
yy: translate
}
}

Expand Down
32 changes: 26 additions & 6 deletions src/locale/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ const monthShortFormat = 'янв._февр._мар._апр._мая_июня_ию
const monthShortStandalone = 'янв._февр._март_апр._май_июнь_июль_авг._сент._окт._нояб._дек.'.split('_')

const MONTHS_IN_FORMAT = /D[oD]?(\[[^[\]]*\]|\s)+MMMM?/

function plural(word, num) {
const forms = word.split('_')
return num % 10 === 1 && num % 100 !== 11 ? forms[0] : (num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) ? forms[1] : forms[2]) // eslint-disable-line
}
function relativeTimeWithPlural(number, withoutSuffix, key) {
const format = {
mm: withoutSuffix ? 'минута_минуты_минут' : 'минуту_минуты_минут',
hh: 'час_часа_часов',
dd: 'день_дня_дней',
MM: 'месяц_месяца_месяцев',
yy: 'год_года_лет'
}
if (key === 'm') {
return withoutSuffix ? 'минута' : 'минуту'
}

return `${number} ${plural(format[key], +number)}`
}

const locale = {
name: 'ru',
weekdays: 'воскресенье_понедельник_вторник_среда_четверг_пятница_суббота'.split('_'),
Expand Down Expand Up @@ -37,16 +57,16 @@ const locale = {
future: 'через %s',
past: '%s назад',
s: 'несколько секунд',
m: 'минута',
mm: '%d минут',
m: relativeTimeWithPlural,
mm: relativeTimeWithPlural,
h: 'час',
hh: '%d часов',
hh: relativeTimeWithPlural,
d: 'день',
dd: '%d дней',
dd: relativeTimeWithPlural,
M: 'месяц',
MM: '%d месяцев',
MM: relativeTimeWithPlural,
y: 'год',
yy: '%d лет'
yy: relativeTimeWithPlural
},
ordinal: n => n
}
Expand Down
Loading

0 comments on commit 2cc9d8f

Please sign in to comment.