Skip to content

DOC-18365 Internationalize time#205

Merged
kristleschulz-wk merged 20 commits intomasterfrom
internationalize-time
Jan 9, 2026
Merged

DOC-18365 Internationalize time#205
kristleschulz-wk merged 20 commits intomasterfrom
internationalize-time

Conversation

@abescheideman-wf
Copy link
Contributor

@abescheideman-wf abescheideman-wf commented Dec 30, 2025

Motivation

As part of an effort to internationalize the Document Health panel, let's internationalize our time helper.

See https://workiva.slack.com/archives/CEDM9RH1N/p1767112008311229 for more context.

Changes

Use getters to format the time when it's needed to avoid potential race conditions when initializing the DateFormat variables before our locale is set.

Release Notes

Review

See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.

Please review:

QA Checklist

Since there's not a way to change your locale on deploys or a local build of DPC, there's no real way to QA these changes

  • CI Passing

Merge Checklist

While we perform many automated checks before auto-merging, some manual checks are needed:

  • A Frontend Architecture member has reviewed these changes
  • There are no unaddressed comments - this check can be automated if reviewers use the "Request Changes" feature
  • For release PRs - Version metadata in Rosie comment is correct

@abescheideman-wf abescheideman-wf changed the title Try internationalizing DOC-18365 Internationalize time Dec 31, 2025
@abescheideman-wf abescheideman-wf marked this pull request as ready for review December 31, 2025 01:25
fail-fast: false
matrix:
sdk: [ 2.19.6, stable ]
sdk: [ 2.19.6, 3.9.4 ]

Choose a reason for hiding this comment

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

Is this a CI issue unrelated to your change? What are we downgrading to 3.9.4 here? Will we want to go back and change this to stable at some point?

Copy link

@braxtonlyddon-wk braxtonlyddon-wk Jan 2, 2026

Choose a reason for hiding this comment

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

Looks like w_common is on an older version 1.4.2 of workiva_analysis_options. So bumping to 1.4.3 should fix as those lint options were removed. Workiva/workiva_analysis_options#221

mocktail: ^1.0.4
test: ^1.21.1
workiva_analysis_options: ^1.4.2
workiva_analysis_options: ^1.0.0

Choose a reason for hiding this comment

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

It looks like we'll want to upgrade this instead of downgrading


/// The format of a timestamp with no date.
DateFormat timeFormat = DateFormat('h:mma');
DateFormat timeFormat = DateFormat('h:mma', locale);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is going to work. If you don't pass a locale, it should already get the default one. The problem (if this isn't working) is probably a race condition between the locale being set and these format variables being set.
Since we save the date locale in the session, it isn't set until fairly late in the initialization process. If these variables are referenced before that, then they'll have invalid values.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say try changing these be getters, without passing the locale, and see if that fixes it. If it does, then, depending how often these are used, you might want to look at making it not recompute them every time.

if (deltaDays < 1 && now.day == time.day) {
// "Today, XX:XXam"
return 'Today, $timeOfDay';
return '${Intl.message('Today')}, $timeOfDay';
Copy link
Contributor

@alanknight-wk alanknight-wk Jan 5, 2026

Choose a reason for hiding this comment

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

This (the bare Intl.message call) also isn't going to work. You need to put this inside a method inside an _intl.dart file in this package. Also, probably better to depend on w_intl than the base intl.

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 see that pattern, but I don't totally understand why we need a separate _intl.dart file?

Also, I don't think there are 1:1 ways to get the same DateFormats from w_intl. Is that something we want to add to w_intl, or is the current iteration more like what we want?

Copy link
Contributor

Choose a reason for hiding this comment

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

They need to be wrapped in a function, but the requirement for the _intl.dart file is internal, it's just how we find the messages to send for translation without parsing the whole source tree. For external it probably won't matter, but if you want these to work internally, you'll need them to be in a file like that.

Comment on lines 22 to 25
w_intl:
hosted:
name: w_intl
url: https://pub.workiva.org
Copy link
Contributor Author

@abescheideman-wf abescheideman-wf Jan 5, 2026

Choose a reason for hiding this comment

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

Just stumbling my way through this, w_common is currently open source, so I'm guessing this is another blocker @alanknight-wk ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, then you should probably just use the basic intl.


/// The format of a timestamp with no date.
DateFormat timeFormat = DateFormat('h:mma');
DateFormat get timeFormat => DateFormat('h:mma');
Copy link
Contributor

Choose a reason for hiding this comment

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

Another comment, you probably don't want this. If it doesn't match one of the skeletons, then it won't know how to convert it for other locales. You probably want DateFormat.jm()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keatoncarter-wf
keatoncarter-wf previously approved these changes Jan 6, 2026

/// The format of a timestamp with no date.
DateFormat timeFormat = DateFormat('h:mma');
DateFormat get timeFormat => DateFormat.jm();

Choose a reason for hiding this comment

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

Is this change going to add a space before the AM/PM?

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will add a space, but we're preferring to adapt to locale now.
Screenshot 2026-01-06 at 14 56 12

Screenshot 2026-01-06 at 14 57 02

timothyellis-wk
timothyellis-wk previously approved these changes Jan 6, 2026
if (deltaDays < 1 && now.day == time.day) {
// "Today, XX:XXam"
return 'Today, $timeOfDay';
return '${TimeIntl.today}, $timeOfDay';
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 it would be preferred to include the punctuation in the internationalized string. I'd pass in the time as a parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

if (deltaDays < 1 && now.day == time.day) {
// "Today, XX:XXam"
return 'Today, $timeOfDay';
return TimeIntl.today(timeOfDay);
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to take out that toLowerCase on timeOfDay above. That's not necessarily correct in other locales.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah, good catch!

@jacobfeddersen-wf
Copy link
Contributor

I consumed this in DPC and ran CI just to make sure we won't break anything https://github.com/Workiva/doc_plat_client/pull/57492

@kristleschulz-wk
Copy link
Contributor

QA +1

@kristleschulz-wk
Copy link
Contributor

@Workiva/release-management-p

@kristleschulz-wk kristleschulz-wk merged commit 54040ac into master Jan 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants