forked from python-pendulum/pendulum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RU locale * Show "few seconds" as numbers, as in 1.x for RU locale * Add RU locale tests * Fix styling in locale.py
- Loading branch information
Showing
4 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
""" | ||
ru custom locale file. | ||
""" | ||
|
||
translations = { | ||
# Relative time | ||
'ago': '{} назад', | ||
'from_now': 'через {}', | ||
'after': '{0} после', | ||
'before': '{0} до', | ||
|
||
# Date formats | ||
'date_formats': { | ||
'LTS': 'HH:mm:ss', | ||
'LT': 'HH:mm', | ||
'L': 'DD.MM.YYYY', | ||
'LL': 'D MMMM YYYY г.', | ||
'LLL': 'D MMMM YYYY г., HH:mm', | ||
'LLLL': 'dddd, D MMMM YYYY г., HH:mm' | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
""" | ||
ru locale file. | ||
It has been generated automatically and must not be modified directly. | ||
""" | ||
|
||
from .custom import translations as custom_translations | ||
|
||
|
||
locale = { | ||
'plural': lambda n: 'few' if (((0 == 0 and ((0 == 0))) and ((n % 10) == (n % 10) and (((n % 10) >= 2 and (n % 10) <= 4)))) and (not ((n % 100) == (n % 100) and (((n % 100) >= 12 and (n % 100) <= 14))))) else 'many' if ((((0 == 0 and ((0 == 0))) and ((n % 10) == (n % 10) and (((n % 10) == 0)))) or ((0 == 0 and ((0 == 0))) and ((n % 10) == (n % 10) and (((n % 10) >= 5 and (n % 10) <= 9))))) or ((0 == 0 and ((0 == 0))) and ((n % 100) == (n % 100) and (((n % 100) >= 11 and (n % 100) <= 14))))) else 'one' if (((0 == 0 and ((0 == 0))) and ((n % 10) == (n % 10) and (((n % 10) == 1)))) and (not ((n % 100) == (n % 100) and (((n % 100) == 11))))) else 'other', | ||
'ordinal': lambda n: 'other', | ||
'translations': { | ||
'days': { | ||
'abbreviated': { | ||
0: 'вс', | ||
1: 'пн', | ||
2: 'вт', | ||
3: 'ср', | ||
4: 'чт', | ||
5: 'пт', | ||
6: 'сб', | ||
}, | ||
'narrow': { | ||
0: 'вс', | ||
1: 'пн', | ||
2: 'вт', | ||
3: 'ср', | ||
4: 'чт', | ||
5: 'пт', | ||
6: 'сб', | ||
}, | ||
'short': { | ||
0: 'вс', | ||
1: 'пн', | ||
2: 'вт', | ||
3: 'ср', | ||
4: 'чт', | ||
5: 'пт', | ||
6: 'сб', | ||
}, | ||
'wide': { | ||
0: 'воскресенье', | ||
1: 'понедельник', | ||
2: 'вторник', | ||
3: 'среда', | ||
4: 'четверг', | ||
5: 'пятница', | ||
6: 'суббота', | ||
}, | ||
}, | ||
'months': { | ||
'abbreviated': { | ||
1: 'янв.', | ||
2: 'февр.', | ||
3: 'мар.', | ||
4: 'апр.', | ||
5: 'мая', | ||
6: 'июн.', | ||
7: 'июл.', | ||
8: 'авг.', | ||
9: 'сент.', | ||
10: 'окт.', | ||
11: 'нояб.', | ||
12: 'дек.', | ||
}, | ||
'narrow': { | ||
1: 'Я', | ||
2: 'Ф', | ||
3: 'М', | ||
4: 'А', | ||
5: 'М', | ||
6: 'И', | ||
7: 'И', | ||
8: 'А', | ||
9: 'С', | ||
10: 'О', | ||
11: 'Н', | ||
12: 'Д', | ||
}, | ||
'wide': { | ||
1: 'января', | ||
2: 'февраля', | ||
3: 'марта', | ||
4: 'апреля', | ||
5: 'мая', | ||
6: 'июня', | ||
7: 'июля', | ||
8: 'августа', | ||
9: 'сентября', | ||
10: 'октября', | ||
11: 'ноября', | ||
12: 'декабря', | ||
}, | ||
}, | ||
'units': { | ||
'year': { | ||
'one': '{0} год', | ||
'few': '{0} года', | ||
'many': '{0} лет', | ||
'other': '{0} года', | ||
}, | ||
'month': { | ||
'one': '{0} месяц', | ||
'few': '{0} месяца', | ||
'many': '{0} месяцев', | ||
'other': '{0} месяца', | ||
}, | ||
'week': { | ||
'one': '{0} неделя', | ||
'few': '{0} недели', | ||
'many': '{0} недель', | ||
'other': '{0} недели', | ||
}, | ||
'day': { | ||
'one': '{0} день', | ||
'few': '{0} дня', | ||
'many': '{0} дней', | ||
'other': '{0} дня', | ||
}, | ||
'hour': { | ||
'one': '{0} час', | ||
'few': '{0} часа', | ||
'many': '{0} часов', | ||
'other': '{0} часа', | ||
}, | ||
'minute': { | ||
'one': '{0} минута', | ||
'few': '{0} минуты', | ||
'many': '{0} минут', | ||
'other': '{0} минуты', | ||
}, | ||
'second': { | ||
'one': '{0} секунда', | ||
'few': '{0} секунды', | ||
'many': '{0} секунд', | ||
'other': '{0} секунды', | ||
}, | ||
'microsecond': { | ||
'one': '{0} микросекунда', | ||
'few': '{0} микросекунды', | ||
'many': '{0} микросекунд', | ||
'other': '{0} микросекунды', | ||
}, | ||
}, | ||
'relative': { | ||
'year': { | ||
'future': { | ||
'other': 'через {0} года', | ||
'one': 'через {0} год', | ||
'few': 'через {0} года', | ||
'many': 'через {0} лет', | ||
}, | ||
'past': { | ||
'other': '{0} года назад', | ||
'one': '{0} год назад', | ||
'few': '{0} года назад', | ||
'many': '{0} лет назад', | ||
}, | ||
}, | ||
'month': { | ||
'future': { | ||
'other': 'через {0} месяца', | ||
'one': 'через {0} месяц', | ||
'few': 'через {0} месяца', | ||
'many': 'через {0} месяцев', | ||
}, | ||
'past': { | ||
'other': '{0} месяца назад', | ||
'one': '{0} месяц назад', | ||
'few': '{0} месяца назад', | ||
'many': '{0} месяцев назад', | ||
}, | ||
}, | ||
'week': { | ||
'future': { | ||
'other': 'через {0} недели', | ||
'one': 'через {0} неделю', | ||
'few': 'через {0} недели', | ||
'many': 'через {0} недель', | ||
}, | ||
'past': { | ||
'other': '{0} недели назад', | ||
'one': '{0} неделю назад', | ||
'few': '{0} недели назад', | ||
'many': '{0} недель назад', | ||
}, | ||
}, | ||
'day': { | ||
'future': { | ||
'other': 'через {0} дня', | ||
'one': 'через {0} день', | ||
'few': 'через {0} дня', | ||
'many': 'через {0} дней', | ||
}, | ||
'past': { | ||
'other': '{0} дня назад', | ||
'one': '{0} день назад', | ||
'few': '{0} дня назад', | ||
'many': '{0} дней назад', | ||
}, | ||
}, | ||
'hour': { | ||
'future': { | ||
'other': 'через {0} часа', | ||
'one': 'через {0} час', | ||
'few': 'через {0} часа', | ||
'many': 'через {0} часов', | ||
}, | ||
'past': { | ||
'other': '{0} часа назад', | ||
'one': '{0} час назад', | ||
'few': '{0} часа назад', | ||
'many': '{0} часов назад', | ||
}, | ||
}, | ||
'minute': { | ||
'future': { | ||
'other': 'через {0} минуты', | ||
'one': 'через {0} минуту', | ||
'few': 'через {0} минуты', | ||
'many': 'через {0} минут', | ||
}, | ||
'past': { | ||
'other': '{0} минуты назад', | ||
'one': '{0} минуту назад', | ||
'few': '{0} минуты назад', | ||
'many': '{0} минут назад', | ||
}, | ||
}, | ||
'second': { | ||
'future': { | ||
'other': 'через {0} секунды', | ||
'one': 'через {0} секунду', | ||
'few': 'через {0} секунды', | ||
'many': 'через {0} секунд', | ||
}, | ||
'past': { | ||
'other': '{0} секунды назад', | ||
'one': '{0} секунду назад', | ||
'few': '{0} секунды назад', | ||
'many': '{0} секунд назад', | ||
}, | ||
}, | ||
}, | ||
'day_periods': { | ||
'midnight': 'полночь', | ||
'am': 'AM', | ||
'noon': 'полдень', | ||
'pm': 'PM', | ||
'morning1': 'утра', | ||
'afternoon1': 'дня', | ||
'evening1': 'вечера', | ||
'night1': 'ночи', | ||
}, | ||
}, | ||
'custom': custom_translations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import pendulum | ||
|
||
|
||
locale = 'ru' | ||
|
||
|
||
def test_diff_for_humans(): | ||
with pendulum.test(pendulum.datetime(2016, 8, 29)): | ||
diff_for_humans() | ||
|
||
|
||
def diff_for_humans(): | ||
d = pendulum.now().subtract(seconds=1) | ||
assert d.diff_for_humans(locale=locale) == '1 секунду назад' | ||
|
||
d = pendulum.now().subtract(seconds=2) | ||
assert d.diff_for_humans(locale=locale) == '2 секунды назад' | ||
|
||
d = pendulum.now().subtract(seconds=5) | ||
assert d.diff_for_humans(locale=locale) == '5 секунд назад' | ||
|
||
d = pendulum.now().subtract(seconds=21) | ||
assert d.diff_for_humans(locale=locale) == '21 секунду назад' | ||
|
||
d = pendulum.now().subtract(minutes=1) | ||
assert d.diff_for_humans(locale=locale) == '1 минуту назад' | ||
|
||
d = pendulum.now().subtract(minutes=2) | ||
assert d.diff_for_humans(locale=locale) == '2 минуты назад' | ||
|
||
d = pendulum.now().subtract(minutes=5) | ||
assert d.diff_for_humans(locale=locale) == '5 минут назад' | ||
|
||
d = pendulum.now().subtract(hours=1) | ||
assert d.diff_for_humans(locale=locale) == '1 час назад' | ||
|
||
d = pendulum.now().subtract(hours=2) | ||
assert d.diff_for_humans(locale=locale) == '2 часа назад' | ||
|
||
d = pendulum.now().subtract(hours=5) | ||
assert d.diff_for_humans(locale=locale) == '5 часов назад' | ||
|
||
d = pendulum.now().subtract(days=1) | ||
assert d.diff_for_humans(locale=locale) == '1 день назад' | ||
|
||
d = pendulum.now().subtract(days=2) | ||
assert d.diff_for_humans(locale=locale) == '2 дня назад' | ||
|
||
d = pendulum.now().subtract(days=5) | ||
assert d.diff_for_humans(locale=locale) == '5 дней назад' | ||
|
||
d = pendulum.now().subtract(weeks=1) | ||
assert d.diff_for_humans(locale=locale) == '1 неделю назад' | ||
|
||
d = pendulum.now().subtract(weeks=2) | ||
assert d.diff_for_humans(locale=locale) == '2 недели назад' | ||
|
||
d = pendulum.now().subtract(months=1) | ||
assert d.diff_for_humans(locale=locale) == '1 месяц назад' | ||
|
||
d = pendulum.now().subtract(months=2) | ||
assert d.diff_for_humans(locale=locale) == '2 месяца назад' | ||
|
||
d = pendulum.now().subtract(months=5) | ||
assert d.diff_for_humans(locale=locale) == '5 месяцев назад' | ||
|
||
d = pendulum.now().subtract(years=1) | ||
assert d.diff_for_humans(locale=locale) == '1 год назад' | ||
|
||
d = pendulum.now().subtract(years=2) | ||
assert d.diff_for_humans(locale=locale) == '2 года назад' | ||
|
||
d = pendulum.now().subtract(years=5) | ||
assert d.diff_for_humans(locale=locale) == '5 лет назад' | ||
|
||
d = pendulum.now().add(seconds=1) | ||
assert d.diff_for_humans(locale=locale) == 'через 1 секунду' | ||
|
||
d = pendulum.now().add(seconds=1) | ||
d2 = pendulum.now() | ||
assert d.diff_for_humans(d2, locale=locale) == '1 секунда после' | ||
assert d2.diff_for_humans(d, locale=locale) == '1 секунда до' | ||
|
||
assert d.diff_for_humans(d2, True, locale=locale) == '1 секунда' | ||
assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == '2 секунды' |