DOC-18365 Internationalize time#205
Conversation
…rnationalize-time # Conflicts: # w_common/pubspec.yaml
.github/workflows/dart_ci.yml
Outdated
| fail-fast: false | ||
| matrix: | ||
| sdk: [ 2.19.6, stable ] | ||
| sdk: [ 2.19.6, 3.9.4 ] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
w_common/pubspec.yaml
Outdated
| mocktail: ^1.0.4 | ||
| test: ^1.21.1 | ||
| workiva_analysis_options: ^1.4.2 | ||
| workiva_analysis_options: ^1.0.0 |
There was a problem hiding this comment.
It looks like we'll want to upgrade this instead of downgrading
w_common/lib/time.dart
Outdated
|
|
||
| /// The format of a timestamp with no date. | ||
| DateFormat timeFormat = DateFormat('h:mma'); | ||
| DateFormat timeFormat = DateFormat('h:mma', locale); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
w_common/lib/time.dart
Outdated
| if (deltaDays < 1 && now.day == time.day) { | ||
| // "Today, XX:XXam" | ||
| return 'Today, $timeOfDay'; | ||
| return '${Intl.message('Today')}, $timeOfDay'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
w_common/pubspec.yaml
Outdated
| w_intl: | ||
| hosted: | ||
| name: w_intl | ||
| url: https://pub.workiva.org |
There was a problem hiding this comment.
Just stumbling my way through this, w_common is currently open source, so I'm guessing this is another blocker @alanknight-wk ?
There was a problem hiding this comment.
Ah, then you should probably just use the basic intl.
w_common/lib/time.dart
Outdated
|
|
||
| /// The format of a timestamp with no date. | ||
| DateFormat timeFormat = DateFormat('h:mma'); | ||
| DateFormat get timeFormat => DateFormat('h:mma'); |
There was a problem hiding this comment.
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()
|
|
||
| /// The format of a timestamp with no date. | ||
| DateFormat timeFormat = DateFormat('h:mma'); | ||
| DateFormat get timeFormat => DateFormat.jm(); |
w_common/lib/time.dart
Outdated
| if (deltaDays < 1 && now.day == time.day) { | ||
| // "Today, XX:XXam" | ||
| return 'Today, $timeOfDay'; | ||
| return '${TimeIntl.today}, $timeOfDay'; |
There was a problem hiding this comment.
I think it would be preferred to include the punctuation in the internationalized string. I'd pass in the time as a parameter.
There was a problem hiding this comment.
b85897e
| if (deltaDays < 1 && now.day == time.day) { | ||
| // "Today, XX:XXam" | ||
| return 'Today, $timeOfDay'; | ||
| return TimeIntl.today(timeOfDay); |
There was a problem hiding this comment.
You probably want to take out that toLowerCase on timeOfDay above. That's not necessarily correct in other locales.
There was a problem hiding this comment.
Oh yeah, good catch!
|
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 |
|
QA +1 |
|
@Workiva/release-management-p |



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
Merge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: