8109: Japanese data localisation

This commit is contained in:
Mathieu MD 2015-03-17 12:35:26 -07:00 committed by Ross Gammon
parent 7afda11c9b
commit 7ef7e3bbf5
4 changed files with 315 additions and 51 deletions

View File

@ -49,6 +49,7 @@ from . import _date_fi
from . import _date_fr
from . import _date_hr
from . import _date_it
from . import _date_ja
from . import _date_lt
from . import _date_nb
from . import _date_nl

View File

@ -0,0 +1,264 @@
# -*- coding: utf-8 -*-
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2004-2006 Donald N. Allingham
# Copyright (C) 2014 Mathieu MD <mathieu.md@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
"""
Japanese-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
from . import _grampslocale
#-------------------------------------------------------------------------
#
# Japanese parser
#
#-------------------------------------------------------------------------
class DateParserJA(DateParser):
"""
Convert a text string into a Date object. If the date cannot be
converted, the text string is assigned.
"""
# modifiers before the date
modifier_to_int = {
'以前' : Date.MOD_BEFORE,
'以降' : Date.MOD_AFTER,
'' : Date.MOD_ABOUT,
'ごろ' : Date.MOD_ABOUT,
}
month_to_int = DateParser.month_to_int
quality_to_int = {
'およそ' : Date.QUAL_ESTIMATED,
'ごろ' : Date.QUAL_ESTIMATED,
'計算上' : Date.QUAL_CALCULATED,
}
bce = ["紀元前", "BC"] + DateParser.bce
def init_strings(self):
"""
This method compiles regular expression strings for matching dates.
"""
DateParser.init_strings(self)
DateParser.calendar_to_int.update({
'グレゴリオ暦' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'ユリウス暦' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'ユダヤ暦' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'ヒジュラ暦' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'フランス革命暦' : Date.CAL_FRENCH,
'共和暦' : Date.CAL_FRENCH,
'f' : Date.CAL_FRENCH,
'イラン暦' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'スウェーデン暦' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
})
DateParser.month_to_int.update({
"一月" : 1,
"ichigatsu" : 1,
"睦月" : 1,
"mutsuki" : 1,
"二月" : 2,
"nigatsu" : 2,
"如月" : 2,
"kisaragi" : 2,
"衣更着" : 2,
"kinusaragi" : 2,
"三月" : 3,
"sangatsu" : 3,
"弥生" : 3,
"yayoi" : 3,
"四月" : 4,
"shigatsu" : 4,
"卯月" : 4,
"uzuki" : 4,
"五月" : 5,
"gogatsu" : 5,
"皐月" : 5,
"satsuki" : 5,
"早苗月" : 5,
"sanaetsuki" : 5,
"六月" : 6,
"rokugatsu" : 6,
"水無月" : 6,
"minazuki" : 6,
"七月" : 7,
"shichigatsu" : 7,
"文月" : 7,
"fumizuki" : 7,
"八月" : 8,
"hachigatsu" : 8,
"葉月" : 8,
"hazuki" : 8,
"九月" : 9,
"kugatsu" : 9,
"長月" : 9,
"nagatsuki" : 9,
"十月" : 10,
"jugatsu" : 10,
"jūgatsu" : 10,
"juugatsu" : 10,
"神無月" : 10,
"kannazuki" : 10,
"kaminazuki" : 10,
"神有月" : 10,
"神在月" : 10,
"kamiarizuki" : 10,
"十一月" : 11,
"juichigatsu" : 11,
"jūichigatsu" : 11,
"juuichigatsu" : 11,
"霜月" : 11,
"shimotsuki" : 11,
"十二月" : 12,
"junigatsu" : 12,
"jūnigatsu" : 12,
"juunigatsu" : 12,
"師走" : 12,
"shiwasu" : 12,
})
_span_1 = ['から', '~', '']
_span_2 = ['まで', '']
_range_1 = ['から', '', '~', '']
_range_2 = ['までの間', 'の間']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
#-------------------------------------------------------------------------
#
# Japanese display
#
#-------------------------------------------------------------------------
class DateDisplayJA(DateDisplay):
"""
Japanese language date display class.
"""
# Specify what is actually the "System Default".
_locale_tformat = _grampslocale.tformat
_locale_tformat = _locale_tformat.replace('%d', "31")
_locale_tformat = _locale_tformat.replace('%m', "12")
_locale_tformat = _locale_tformat.replace('%Y', "1999")
# This definition must agree with its "_display_gregorian" method
formats = ("YYYY-MM-DD (ISO)", # 0
"システムデフォールト (" + _locale_tformat + ")", # 1
"1999年12月31日", # 2
"1999年十二月31日", # 3
)
def _display_gregorian(self, date_val, **kwargs):
"""
display gregorian calendar date in different format
"""
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3])
if self.format == 0:
# ISO
return self.display_iso(date_val)
elif self.format == 1:
# System Default
if date_val[2] < 0 or date_val[3]:
return self.display_iso(date_val)
else:
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y', str(date_val[2]))
elif self.format == 2:
# 1999年12月31日
if date_val[0] == 0:
if date_val[1] == 0:
value = "%s" % year
else:
value = "%s%s" % (year,
self.short_months[date_val[1]])
else:
value = "%s%s%s" % (year,
self.short_months[date_val[1]],
date_val[0])
elif self.format == 3:
# 1999年十二月31日
if date_val[0] == 0:
if date_val[1] == 0:
value = "%s" % year
else:
value = "%s%s" % (year,
self.long_months[date_val[1]])
else:
value = "%s%s%s" % (year,
self.long_months[date_val[1]],
date_val[0])
else:
return self.display_iso(date_val)
if date_val[2] < 0:
return self._bce_str % value
else:
return value
display = DateDisplay.display_formatted
#-------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
register_datehandler(('ja_JP', 'ja', 'japanese', 'Japanese'),
DateParserJA, DateDisplayJA)

View File

@ -83,7 +83,6 @@ LANG_TO_DISPLAY = {
'en' : DateDisplayEn,
'en_GB' : DateDisplayEn,
'English_United States' : DateDisplayEn,
'ja_JP' : DateDisplay,
'ko_KR' : DateDisplay,
'nb_NO' : DateDisplay,
}

100
po/ja.po
View File

@ -1211,7 +1211,7 @@ msgstr "日付"
#: ../gramps/gen/datehandler/_datedisplay.py:348
msgid "{date_quality}from {date_start} to {date_stop}{nonstd_calendar_and_ny}"
msgstr ""
msgstr "{nonstd_calendar_and_ny}{date_start}から{date_stop}まで{date_quality}"
#. If there is no special inflection for "between <Month>" in your
#. language, don't translate this string.
@ -1235,7 +1235,7 @@ msgstr "日付"
#: ../gramps/gen/datehandler/_datedisplay.py:370
msgid "{date_quality}between {date_start} and {date_stop}{nonstd_calendar_and_ny}"
msgstr ""
msgstr "{nonstd_calendar_and_ny}{date_start}と{date_stop}の間{date_quality}"
#. If there is no special inflection for "before/after/around <Month>" in your
#. language, don't translate this string.
@ -1291,51 +1291,51 @@ msgstr ""
#. DateDisplayer code!
#: ../gramps/gen/datehandler/_datestrings.py:65
msgid "localized lexeme inflections||January"
msgstr ""
msgstr "一月"
#: ../gramps/gen/datehandler/_datestrings.py:66
msgid "localized lexeme inflections||February"
msgstr ""
msgstr "二月"
#: ../gramps/gen/datehandler/_datestrings.py:67
msgid "localized lexeme inflections||March"
msgstr ""
msgstr "三月"
#: ../gramps/gen/datehandler/_datestrings.py:68
msgid "localized lexeme inflections||April"
msgstr ""
msgstr "四月"
#: ../gramps/gen/datehandler/_datestrings.py:69
msgid "localized lexeme inflections||May"
msgstr ""
msgstr "五月"
#: ../gramps/gen/datehandler/_datestrings.py:70
msgid "localized lexeme inflections||June"
msgstr ""
msgstr "六月"
#: ../gramps/gen/datehandler/_datestrings.py:71
msgid "localized lexeme inflections||July"
msgstr ""
msgstr "七月"
#: ../gramps/gen/datehandler/_datestrings.py:72
msgid "localized lexeme inflections||August"
msgstr ""
msgstr "八月"
#: ../gramps/gen/datehandler/_datestrings.py:73
msgid "localized lexeme inflections||September"
msgstr ""
msgstr "九月"
#: ../gramps/gen/datehandler/_datestrings.py:74
msgid "localized lexeme inflections||October"
msgstr ""
msgstr "十月"
#: ../gramps/gen/datehandler/_datestrings.py:75
msgid "localized lexeme inflections||November"
msgstr ""
msgstr "十一月"
#: ../gramps/gen/datehandler/_datestrings.py:76
msgid "localized lexeme inflections||December"
msgstr ""
msgstr "十二月"
#. TRANSLATORS: see
#. http://gramps-project.org/wiki/index.php?title=Translating_Gramps#Translating_dates
@ -1343,51 +1343,51 @@ msgstr ""
#. DateDisplayer code!
#: ../gramps/gen/datehandler/_datestrings.py:83
msgid "localized lexeme inflections - short month form||Jan"
msgstr ""
msgstr "1月"
#: ../gramps/gen/datehandler/_datestrings.py:84
msgid "localized lexeme inflections - short month form||Feb"
msgstr ""
msgstr "2月"
#: ../gramps/gen/datehandler/_datestrings.py:85
msgid "localized lexeme inflections - short month form||Mar"
msgstr ""
msgstr "3月"
#: ../gramps/gen/datehandler/_datestrings.py:86
msgid "localized lexeme inflections - short month form||Apr"
msgstr ""
msgstr "4月"
#: ../gramps/gen/datehandler/_datestrings.py:87
msgid "localized lexeme inflections - short month form||May"
msgstr ""
msgstr "5月"
#: ../gramps/gen/datehandler/_datestrings.py:88
msgid "localized lexeme inflections - short month form||Jun"
msgstr ""
msgstr "6月"
#: ../gramps/gen/datehandler/_datestrings.py:89
msgid "localized lexeme inflections - short month form||Jul"
msgstr ""
msgstr "7月"
#: ../gramps/gen/datehandler/_datestrings.py:90
msgid "localized lexeme inflections - short month form||Aug"
msgstr ""
msgstr "8月"
#: ../gramps/gen/datehandler/_datestrings.py:91
msgid "localized lexeme inflections - short month form||Sep"
msgstr ""
msgstr "9月"
#: ../gramps/gen/datehandler/_datestrings.py:92
msgid "localized lexeme inflections - short month form||Oct"
msgstr ""
msgstr "10月"
#: ../gramps/gen/datehandler/_datestrings.py:93
msgid "localized lexeme inflections - short month form||Nov"
msgstr ""
msgstr "11月"
#: ../gramps/gen/datehandler/_datestrings.py:94
msgid "localized lexeme inflections - short month form||Dec"
msgstr ""
msgstr "12月"
#. TRANSLATORS: see
#. http://gramps-project.org/wiki/index.php?title=Translating_Gramps#Translating_dates
@ -1698,53 +1698,53 @@ msgstr ""
msgid "Persian month lexeme|Esfand"
msgstr ""
#: ../gramps/gen/datehandler/_datestrings.py:209
#: /gramps/gen/datehandler/_datestrings.py:10024
msgid "date modifier|before "
msgstr ""
msgstr "以前 "
#: ../gramps/gen/datehandler/_datestrings.py:210
#: /gramps/gen/datehandler/_datestrings.py:10025
msgid "date modifier|after "
msgstr ""
msgstr "以降 "
#: ../gramps/gen/datehandler/_datestrings.py:211
#: /gramps/gen/datehandler/_datestrings.py:10026
msgid "date modifier|about "
msgstr ""
msgstr ""
#: ../gramps/gen/datehandler/_datestrings.py:215
#: /gramps/gen/datehandler/_datestrings.py:10027
msgid "date quality|estimated "
msgstr ""
msgstr ""
#: ../gramps/gen/datehandler/_datestrings.py:216
#: /gramps/gen/datehandler/_datestrings.py:10028
msgid "date quality|calculated "
msgstr ""
msgstr "計算上 "
#: ../gramps/gen/datehandler/_datestrings.py:222
#: /gramps/gen/datehandler/_datestrings.py:10029
msgid "Sunday"
msgstr ""
msgstr "日曜日"
#: ../gramps/gen/datehandler/_datestrings.py:223
#: /gramps/gen/datehandler/_datestrings.py:10030
msgid "Monday"
msgstr ""
msgstr "月曜日"
#: ../gramps/gen/datehandler/_datestrings.py:224
#: /gramps/gen/datehandler/_datestrings.py:10031
msgid "Tuesday"
msgstr ""
msgstr "火曜日"
#: ../gramps/gen/datehandler/_datestrings.py:225
#: /gramps/gen/datehandler/_datestrings.py:10032
msgid "Wednesday"
msgstr ""
msgstr "水曜日"
#: ../gramps/gen/datehandler/_datestrings.py:226
#: /gramps/gen/datehandler/_datestrings.py:10033
msgid "Thursday"
msgstr ""
msgstr "木曜日"
#: ../gramps/gen/datehandler/_datestrings.py:227
#: /gramps/gen/datehandler/_datestrings.py:10034
msgid "Friday"
msgstr ""
msgstr "金曜日"
#: ../gramps/gen/datehandler/_datestrings.py:228
#: /gramps/gen/datehandler/_datestrings.py:10035
msgid "Saturday"
msgstr ""
msgstr "土曜日"
#: ../gramps/gen/db/base.py:1635
msgid "Add child to family"