diff --git a/pendulum/locales/ja/__init__.py b/pendulum/locales/ja/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pendulum/locales/ja/custom.py b/pendulum/locales/ja/custom.py new file mode 100644 index 00000000..c0762503 --- /dev/null +++ b/pendulum/locales/ja/custom.py @@ -0,0 +1,21 @@ +""" +ja custom locale file. +""" + +translations = { + "units": {"few_second": "数秒"}, + # Relative time + "ago": "{} 前に", + "from_now": "今から {}", + "after": "{0} 後", + "before": "{0} 前", + # Date formats + "date_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", + }, +} diff --git a/pendulum/locales/ja/locale.py b/pendulum/locales/ja/locale.py new file mode 100644 index 00000000..574d2ec0 --- /dev/null +++ b/pendulum/locales/ja/locale.py @@ -0,0 +1,194 @@ +from .custom import translations as custom_translations + + +""" +ja locale file. + +It has been generated automatically and must not be modified directly. +""" + + +locale = { + "plural": lambda n: "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: "1月", + 2: "2月", + 3: "3月", + 4: "4月", + 5: "5月", + 6: "6月", + 7: "7月", + 8: "8月", + 9: "9月", + 10: "10月", + 11: "11月", + 12: "12月", + }, + "narrow": { + 1: "1", + 2: "2", + 3: "3", + 4: "4", + 5: "5", + 6: "6", + 7: "7", + 8: "8", + 9: "9", + 10: "10", + 11: "11", + 12: "12", + }, + "wide": { + 1: "1月", + 2: "2月", + 3: "3月", + 4: "4月", + 5: "5月", + 6: "6月", + 7: "7月", + 8: "8月", + 9: "9月", + 10: "10月", + 11: "11月", + 12: "12月", + }, + }, + "units": { + "year": { + "other": "{0} 年", + }, + "month": { + "other": "{0} か月", + }, + "week": { + "other": "{0} 週間", + }, + "day": { + "other": "{0} 日", + }, + "hour": { + "other": "{0} 時間", + }, + "minute": { + "other": "{0} 分", + }, + "second": { + "other": "{0} 秒", + }, + "microsecond": { + "other": "{0} マイクロ秒", + }, + }, + "relative": { + "year": { + "future": { + "other": "{0} 年後", + }, + "past": { + "other": "{0} 年前", + }, + }, + "month": { + "future": { + "other": "{0} か月後", + }, + "past": { + "other": "{0} か月前", + }, + }, + "week": { + "future": { + "other": "{0} 週間後", + }, + "past": { + "other": "{0} 週間前", + }, + }, + "day": { + "future": { + "other": "{0} 日後", + }, + "past": { + "other": "{0} 日前", + }, + }, + "hour": { + "future": { + "other": "{0} 時間後", + }, + "past": { + "other": "{0} 時間前", + }, + }, + "minute": { + "future": { + "other": "{0} 分後", + }, + "past": { + "other": "{0} 分前", + }, + }, + "second": { + "future": { + "other": "{0} 秒後", + }, + "past": { + "other": "{0} 秒前", + }, + }, + }, + "day_periods": { + "midnight": "真夜中", + "am": "午前", + "noon": "正午", + "pm": "午後", + "morning1": "朝", + "afternoon1": "昼", + "evening1": "夕方", + "night1": "夜", + "night2": "夜中", + }, + }, + "custom": custom_translations, +} diff --git a/tests/localization/test_ja.py b/tests/localization/test_ja.py new file mode 100644 index 00000000..9dba6091 --- /dev/null +++ b/tests/localization/test_ja.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +import pendulum + + +locale = "ja" + + +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) == "数秒 前に" + + d = pendulum.now().subtract(seconds=2) + assert d.diff_for_humans(locale=locale) == "数秒 前に" + + 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(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(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(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(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().add(seconds=1) + assert d.diff_for_humans(locale=locale) == "今から 数秒" + + d = pendulum.now().add(seconds=1) + d2 = pendulum.now() + assert d.diff_for_humans(d2, locale=locale) == "数秒 後" + assert d2.diff_for_humans(d, locale=locale) == "数秒 前" + + assert d.diff_for_humans(d2, True, locale=locale) == "数秒" + assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == "数秒"