fix(NcDateTimePicker): use translated words in dates formatted with a format string - #8644
Conversation
| if (localeCode === 'be-tarask') { | ||
| exportName = 'beTarasak' | ||
| } | ||
| content += `loader['${localeCode}'] = async () => (await import('date-fns/locale/${localeCode}')).${exportName}\n` |
There was a problem hiding this comment.
Generated module looks like this.
const loader = {};
loader["af"] = async () => (await import("date-fns/locale/af")).af;
loader["ar-DZ"] = async () => (await import("date-fns/locale/ar-DZ")).arDZ;
...
loader["zh-HK"] = async () => (await import("date-fns/locale/zh-HK")).zhHK;
loader["zh-TW"] = async () => (await import("date-fns/locale/zh-TW")).zhTW;There was a problem hiding this comment.
It tested it with Vite and Rspack apps.
| nodeExternalsOptions: { | ||
| // Packages with paths imports should be added here to mark them as external as well | ||
| include: [/^@nextcloud\/.+\//, /^@mdi\/svg\//], | ||
| include: [/^@nextcloud\/.+\//, /^@mdi\/svg\//, /^date-fns\/locale\//], |
There was a problem hiding this comment.
Externalized as suggested in #7767 (comment)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8644 +/- ##
=======================================
Coverage 53.31% 53.31%
=======================================
Files 109 109
Lines 3697 3697
Branches 1083 1082 -1
=======================================
Hits 1971 1971
Misses 1472 1472
Partials 254 254 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1fc990a to
427346d
Compare
|
|
||
| <template> | ||
| <div class="vue-date-time-picker__wrapper"> | ||
| <!-- Setting :key="dateFnsLocaleCode" forces the component to rerender when `:formatLocale` changes. |
There was a problem hiding this comment.
Is there an upstream bug report for this? If not please create one when adding such a work-around
There was a problem hiding this comment.
Done. I Created an issue upstream and added a link.
Also simplified the workaround by removing an intermediate computed var.
(...I got lazy there because we are behind a few major versions, and I just assumed it's probably fixed. But no, the issue persists in the most recent version too.)
d25f659 to
20a290a
Compare
b2b9764 to
20e1809
Compare
GVodyanov
left a comment
There was a problem hiding this comment.
Tested with Italian and code looks good!
susnux
left a comment
There was a problem hiding this comment.
seems to work fine locally
|
One note here: This will increase bundle sizes of such apps a lot. |
… format string Signed-off-by: Oleksandr Dzhychko <hey@oleks.dev>
20e1809 to
007171b
Compare
The problem with that is that the server allows ~750 locales. Almost any dateFns-locale has a corresponding server locale. One idea i had was to load it for the set locale as we load translations only for the set language. But that would require new server code... My preferred solution to reduce bundle size is to construct a dateFns-locale at runtime by extracting the required data by poking at the formatting outputs of For example, https://tempo.formkit.com/#format-str can extract the format rather reliably from some calls to But I thought of that as being too complex for now. I keep it in mind if bundle size becomes a concern for a concrete app. |
No not really, because this is not about locale itself its translated words. e.g. its common to configure
The expected formatting would be to have |
Uh, I haven't thought about that. Locale objects directly provided by It should be possible to combine the I would consider trying that out after #8657 |
Given:
"de-DE"NcDateTimePickerformatprop"yyyy MMM dd"Expect:
Actual:
☑️ Resolves
If a format string is provided, the component now uses the user defined locale to use translated names of month, weekday etc.
🖼️ Screenshots
🚧 Tasks
🏁 Checklist
stable8for maintained Vue 2 version or not applicableNotes
This fix is a byproduct of loading locales from
data-fns/locale, which I intent to use in fixing #8639 (in PR #8657)I opened this PR to make the review easier and get feedback faster.
The loading of
date-fns/localesis the bulk of the PR.Loading those locales seemed to be a blocker in #7767 (comment)