-
-
Notifications
You must be signed in to change notification settings - Fork 110
Add locale-aware date formatting for UI dates #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rodrigost23
wants to merge
1
commit into
oss-apps:main
Choose a base branch
from
rodrigost23:fix-intl-date-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,20 @@ | ||
| import { type Locale, de, enUS, es, fr, it, pl, pt, ptBR, sv } from 'date-fns/locale'; | ||
|
|
||
| export interface SupportedLanguage { | ||
| code: string; | ||
| name: string; | ||
| dateLocale: Locale; | ||
| } | ||
|
|
||
| export const getSupportedLanguages = (): SupportedLanguage[] => [ | ||
| { code: 'en', name: 'English' }, | ||
| { code: 'de', name: 'Deutsch' }, | ||
| { code: 'fr', name: 'Français' }, | ||
| { code: 'it', name: 'Italiano' }, | ||
| { code: 'pl', name: 'Polski' }, | ||
| { code: 'pt-PT', name: 'Portuguese (Portugal)' }, | ||
| { code: 'pt-BR', name: 'Portuguese (Brazil)' }, | ||
| { code: 'sv', name: 'Svenska' }, | ||
| { code: 'es-MX', name: 'Spanish (Mexico)' }, | ||
| { code: 'es-AR', name: 'Spanish (Argentina)' }, | ||
| { code: 'en', name: 'English', dateLocale: enUS }, | ||
| { code: 'de', name: 'Deutsch', dateLocale: de }, | ||
| { code: 'fr', name: 'Français', dateLocale: fr }, | ||
| { code: 'it', name: 'Italiano', dateLocale: it }, | ||
| { code: 'pl', name: 'Polski', dateLocale: pl }, | ||
| { code: 'pt-PT', name: 'Portuguese (Portugal)', dateLocale: pt }, | ||
| { code: 'pt-BR', name: 'Portuguese (Brazil)', dateLocale: ptBR }, | ||
| { code: 'sv', name: 'Svenska', dateLocale: sv }, | ||
| { code: 'es-MX', name: 'Spanish (Mexico)', dateLocale: es }, | ||
| { code: 'es-AR', name: 'Spanish (Argentina)', dateLocale: es }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could just use
new Intl.DateTimeFormat(todayTranslation.usedLng, {day: '2-digit', month: 'short'}).format(date)?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that, but this Intl API is kind of weird. At least for pt-BR and pt-PT, the results are awful, so I'm not sure what other languages would look like to native speakers.
pt-PT:
I don't know why it would format "short" month to "11" (we have "numeric" for that, right?).
pt-BR:
The word "de" here is just a preposition that we can totally ignore when we want it to be shorter.
Maybe we could have a specific function only for this expense date prefix and use the Intl for other places, which would probably make this look better:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a native speaker in either of these, but maybe it is simply the proper way to format this in Portugal? For the brazilian version, yeah it looks kind of bad.
Personally I would prefer fixing locale specific edge cases rather than to import the bulky
date-fnslocale and pass it around.For the expense list, we could format the day and month separately and remove dots for now?
Actually returns the month name, so we could just built this in a consistent format. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting day and month separately makes sense.
Do we need to care about the order, though? Some locales use MM/DD, others DD/MM.
There’s a way to detect that order if we really want to (expand for an example)
Feels a bit over-engineered, but it works.
In pt-BR I wouldn't mind if it stayed as "MM DD", since the layout stacks them on top of each other in the expense list.
Not sure how that reads in other locales...
What do you think? We just keep "MM DD" specifically in the expenses list for now? In that case, the following should be enough:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. One change would be to change day to
2-digitmaybe?