From 69aaec11a5a55f04c7a445b05e377d42291de965 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Mon, 1 Oct 2018 10:59:51 -0700 Subject: [PATCH] Setting the year as an ordinal number in Croatian When I started investigating 10822 I saw some Croatian dates didn't seem to be working in 5.0.0, to my surprise. There seems to have been some kind of regression from 4.2.8. But the Croatian translation for gramps hasn't been updated in about three years -- except by non-Croatians. So I don't know why some "translated" strings which control how dates are displayed were disabled (marked as "fuzzy") in this: 6c67053e1fa22405bde0fae38e81de7ace222d41 Also, I saw some code in the 4.2.8 Croatian date handler which was not in the 5.0.0 Croatian date handler -- somehow. So I believe this commit fixes the Croatian date handler. Issue #10822 --- gramps/gen/datehandler/_date_hr.py | 38 +++++++++++++++++++++++++- gramps/gen/datehandler/_datedisplay.py | 14 ++++++---- po/hr.po | 26 +++++++++--------- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/gramps/gen/datehandler/_date_hr.py b/gramps/gen/datehandler/_date_hr.py index 4a9d38de4..4d04b6f64 100644 --- a/gramps/gen/datehandler/_date_hr.py +++ b/gramps/gen/datehandler/_date_hr.py @@ -79,6 +79,18 @@ class DateParserHR(DateParser): #~ 'персидский' : Date.CAL_PERSIAN, #~ 'п' : Date.CAL_PERSIAN, #~ }) + + # match 'Day. MONTH year.' format with or without dots + self._text2 = re.compile(r'(\d+)?\.?\s*?%s\.?\s*((\d+)(/\d+)?)?\s*\.?$' + % self._mon_str, re.IGNORECASE) + + # match Day.Month.Year. + self._numeric = re.compile( + r"((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\.?$") + + self._jtext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' + % self._jmon_str, re.IGNORECASE) + _span_1 = ['od'] _span_2 = ['do'] _range_1 = ['između'] @@ -105,11 +117,35 @@ class DateDisplayHR(DateDisplay): display = DateDisplay.display_formatted + def format_short_month_year(self, month, year, inflect, short_months): + """ Allow a subclass to modify the year, e.g. add a period """ + if not hasattr(short_months[1], 'f'): # not a Lexeme: no inflection + return "{short_month} {year}.".format( + short_month = short_months[month], year = year) + return self.FORMATS_short_month_year[inflect].format( + short_month = short_months[month], year = year) + + def _get_localized_year(self, year): + """ Allow a subclass to modify the year, e.g. add a period """ + return year + '.' + + # FIXME probably there should be a Croatian-specific "formats" (and this + # ("American comma") format (and dd_dformat03 too) should be eliminated) + def dd_dformat02(self, date_val, inflect, long_months): + """ month_name day, year """ + return DateDisplay.dd_dformat02( + self, date_val, inflect, long_months).replace(' .', '') + + def dd_dformat04(self, date_val, inflect, long_months): + """ day month_name year """ + return DateDisplay.dd_dformat04( + self, date_val, inflect, long_months).replace(' .', '') + #------------------------------------------------------------------------- # # Register classes # #------------------------------------------------------------------------- register_datehandler( - ('hr_HR', 'hr', 'HR', 'croatian', 'Croatian', 'hrvatski', ('%d.%m.%Y',)), + ('hr_HR', 'hr', 'HR', 'croatian', 'Croatian', 'hrvatski', ('%d.%m.%Y.',)), DateParserHR, DateDisplayHR) diff --git a/gramps/gen/datehandler/_datedisplay.py b/gramps/gen/datehandler/_datedisplay.py index 3baafec62..e9db3db06 100644 --- a/gramps/gen/datehandler/_datedisplay.py +++ b/gramps/gen/datehandler/_datedisplay.py @@ -585,6 +585,10 @@ class DateDisplay: w_day = datetime.date(date_val[2], date_val[1], date_val[0]) # y, m, d return self.long_days[((w_day.weekday() + 1) % 7) + 1] + def _get_localized_year(self, year): + """ Allow a subclass to modify the year, e.g. add a period """ + return year + def dd_dformat01(self, date_val): """ numerical @@ -596,7 +600,7 @@ class DateDisplay: return self.display_iso(date_val) else: if date_val[0] == date_val[1] == 0: - return str(date_val[2]) + return self._get_localized_year(str(date_val[2])) else: value = self.dhformat.replace('%m', str(date_val[1])) if '%b' in value or '%B' in value: @@ -634,7 +638,7 @@ class DateDisplay: year = self._slash_year(date_val[2], date_val[3]) if date_val[0] == 0: if date_val[1] == 0: - return year + return self._get_localized_year(year) else: return self.format_long_month_year(date_val[1], year, inflect, long_months) @@ -660,7 +664,7 @@ class DateDisplay: year = self._slash_year(date_val[2], date_val[3]) if date_val[0] == 0: if date_val[1] == 0: - return year + return self._get_localized_year(year) else: return self.format_short_month_year(date_val[1], year, inflect, short_months) @@ -686,7 +690,7 @@ class DateDisplay: year = self._slash_year(date_val[2], date_val[3]) if date_val[0] == 0: if date_val[1] == 0: - return year + return self._get_localized_year(year) else: return self.format_long_month_year(date_val[1], year, inflect, long_months) @@ -712,7 +716,7 @@ class DateDisplay: year = self._slash_year(date_val[2], date_val[3]) if date_val[0] == 0: if date_val[1] == 0: - return year + return self._get_localized_year(year) else: return self.format_short_month_year(date_val[1], year, inflect, short_months) diff --git a/po/hr.po b/po/hr.po index 9255e589b..ef16541e7 100644 --- a/po/hr.po +++ b/po/hr.po @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Gramps 4.2\n" +"Project-Id-Version: Gramps 5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-05-20 09:31-0500\n" "PO-Revision-Date: 2015-07-13 23:42+0100\n" @@ -2080,7 +2080,7 @@ msgstr "D MMM GGGG" #. to learn how to select proper inflection for your language. #: ../gramps/gen/datehandler/_datedisplay.py:181 #: ../gramps/plugins/drawreport/calendarreport.py:233 -#, fuzzy, python-brace-format +#, python-format msgid "{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2090,7 +2090,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:189 -#, fuzzy, python-brace-format +#, python-format msgid "from|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2100,7 +2100,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:197 -#, fuzzy, python-brace-format +#, python-format msgid "to|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2110,7 +2110,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:205 -#, fuzzy, python-brace-format +#, python-format msgid "between|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2120,7 +2120,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:213 -#, fuzzy, python-brace-format +#, python-format msgid "and|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2129,7 +2129,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:220 -#, fuzzy, python-brace-format +#, python-format msgid "before|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2138,7 +2138,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:227 -#, fuzzy, python-brace-format +#, python-format msgid "after|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2147,7 +2147,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:234 -#, fuzzy, python-brace-format +#, python-format msgid "about|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2156,7 +2156,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:241 -#, fuzzy, python-brace-format +#, python-format msgid "estimated|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2165,7 +2165,7 @@ msgstr "{long_month.f[G]} {year}." #. (where X is one of the month-name inflections you defined) #. else leave it untranslated #: ../gramps/gen/datehandler/_datedisplay.py:248 -#, fuzzy, python-brace-format +#, python-format msgid "calculated|{long_month} {year}" msgstr "{long_month.f[G]} {year}." @@ -2276,7 +2276,7 @@ msgstr "to" #: ../gramps/gen/datehandler/_datedisplay.py:433 #, python-brace-format msgid "{date_quality}from {date_start} to {date_stop}{nonstd_calendar_and_ny}" -msgstr "{date_quality} od {date_start} do {date_stop}{nonstd_calendar_and_ny}" +msgstr "{date_quality}od {date_start} do {date_stop}{nonstd_calendar_and_ny}" #. If there is no special inflection for "between " #. in your language, DON'T translate this string. Otherwise, @@ -2297,7 +2297,7 @@ msgstr "and" msgid "" "{date_quality}between {date_start} and {date_stop}{nonstd_calendar_and_ny}" msgstr "" -"{date_quality} između {date_start} i {date_stop}{nonstd_calendar_and_ny}" +"{date_quality}između {date_start} i {date_stop}{nonstd_calendar_and_ny}" #. If there is no special inflection for "before " #. in your language, DON'T translate this string. Otherwise,