Skip to content

Fix distance_of_time_in_words "and" connector#4562

Merged
aduth merged 6 commits intomasterfrom
aduth-fix-dotiw
Jan 6, 2021
Merged

Fix distance_of_time_in_words "and" connector#4562
aduth merged 6 commits intomasterfrom
aduth-fix-dotiw

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Jan 5, 2021

Why:

Before: "4 minutesand59 seconds"
After: "4 minutes and 59 seconds"

**Why**:

Before: "4 minutesand59 seconds"
After: "4 minutes and 59 seconds"
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

datetime:
dotiw:
two_words_connector: and
two_words_connector: " and "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our YAML normalization will trim/strip this 😬

I worked around this by adding the spaces in Ruby in a different file: https://github.com/18F/identity-idp/blob/master/app/presenters/account_reset/pending_presenter.rb#L17

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our YAML normalization will trim/strip this 😬

I worked around this by adding the spaces in Ruby in a different file: https://github.com/18F/identity-idp/blob/master/app/presenters/account_reset/pending_presenter.rb#L17

Hm! I don't see those normalizations happening locally, though I could see how that'd be an interesting challenge to deal with.

The current failures actually seem to be caused by a doubling-up of the spaces for specs associated with the file you mention. Should be as easy to fix as removing said workaround.

Not sure if it's something that changed in a more recent upgrade of the i18n-tasks dependency. It would seem to me as overly-opinionated of a normalization tool to forbid meaningful whitespace like this 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possibility is that previous attempts hadn't included the " quoting, in which case I'd expect the trimming behavior you describe to be applied to any excess whitespace in the YAML file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'd missed the additional normalization we do beyond i18n-tasks. Yeah, I now see the problem you mention.

Thoughts:

  • Should we avoid the trimming altogether? Or maybe at least apply trimming on the dumped output, rather than on the individual values?
  • I've found some examples of using Psych combined with its parse_stream and AST node style attribute + SINGLE_QUOTED / DOUBLE_QUOTED constants to have better control on the parsing and output styles (example). Could consider for a refactor to give us better control to avoid trimming quoted values.

In the meantime, I think I'll revert back to a workaround like you originally proposed, since it seems those ideas may take a bit more effort to implement than I can afford now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in c91c509 to pass option everywhere we use distance_of_time_in_words.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think a great alternative would be trim but only for unquoted strings or something but agree, definitely better to tackle in a separate PR

aduth added 5 commits January 5, 2021 16:54
**Why**: Not ideal, but since YAML normalization currently cannot tolerate string whitespace padding (even when quoted), we cannot include the spaces in the original YAML localization and instead must provide the option in usage.

In the future, consider refactoring our YAML normalization to be more tolerant of intentional whitespace.

See: https://github.com/18F/identity-idp/pull/4562/files#r552217136
@aduth aduth merged commit 5fb8700 into master Jan 6, 2021
@aduth aduth deleted the aduth-fix-dotiw branch January 6, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants