Skip to content

Commit

Permalink
fix: validate even number of single quotes in date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Oct 31, 2024
1 parent a7b92ec commit 84c6d7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions crowdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,14 @@ def validate_translation(locale, path, key, text, en_string, errors, warnings,
print("\t\t{}".format(errors[path][key][-1]))

if text and key in DATE_FORMAT_KEYS and locale not in SKIP_DATE_FORMAT_CHECK:
if "\\'\\'\\'" in text:
single_quotes = [l for l in text if l == "'"]
# If there is an odd number of single quotes, that means some are
# unescaped
if len(single_quotes) % 2 == 1:
if key not in errors[path]:
errors[path][key] = []
errors[path][key].append(
f"Invalid date format characters: Has extra/unbalanced apostrophe")
f"Invalid date format characters: unescaped / unclosed single quotes")
if options.debug:
print("\t\t{}".format(errors[path][key][-1]))

Expand Down
14 changes: 7 additions & 7 deletions iNaturalist/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -970,19 +970,19 @@
<string name="terms_of_service">Terms of Service</string>
<!-- Placeholder text shown in place of a username when the user has been deleted -->
<string name="deleted_user">Deleted User</string>
<!-- Short date formatting template for dates in the current year. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Short date formatting template for dates in the current year. You must use *some* of the date formatting letters, and non-formatting Roman letters from A-z must be surrounded by single quotes. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="date_short_this_year">MMM d</string>
<!-- Short date formatting template for any date. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Short date formatting template for any date. You must use *some* of the date formatting letters, and non-formatting Roman letters from A-z must be surrounded by single quotes. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="date_short">MM/dd/yy</string>
<!-- Short time formatting template for 24-hour locales. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Short time formatting template for 24-hour locales. You must use *some* of the date formatting letters, and non-formatting Roman letters from A-z must be surrounded by single quotes. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="time_short_24_hour">HH:mm</string>
<!-- Short time formatting template for 12-hour locales. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Short time formatting template for 12-hour locales. You must use *some* of the date formatting letters, and non-formatting Roman letters from A-z must be surrounded by single quotes. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="time_short_12_hour">hh:mma</string>
<!-- Long date formatting template. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Long date formatting template. You must use *some* of the date formatting letters, and non-formatting Roman letters from A-z must be surrounded by single quotes. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="date_long">MMM d, yyyy</string>
<!-- Obscured observations date formatting template (only month+year). See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Obscured observations date formatting template (only month+year). Note that non-formatting letters should be surrounded by single quotes, and to include an actual single quote you need to double it, so "MMM ''yy" will render as "Oct '24", and "'Month:' MMM, ''yy" will render as "Month: Oct '24" Odd numbers of single quotes are not allowed. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="date_obscured">MMM \'\'yy</string>
<!-- Long date with time formatting template. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<!-- Long date with time formatting template. You must use *some* of the date formatting letters, and non-formatting Roman letters from A-z must be surrounded by single quotes. See https://developer.android.com/reference/java/text/SimpleDateFormat#date-and-time-patterns for formatting options -->
<string name="date_long_with_time">MMMM d, yyyy hh:mma</string>
<string name="show_common_names">Show common names</string>
<string name="show_common_names_description">Disable if you only want to view scientific names.</string>
Expand Down

0 comments on commit 84c6d7b

Please sign in to comment.