antalotec opened a new pull request, #45982:
URL: https://github.com/apache/superset/pull/45982

   ### SUMMARY
   
   `dayjs.locale(name)` is a silent no-op when `name` was never imported: dayjs 
keeps the
   locale already in effect and returns *that* name instead of the one asked 
for. Nothing
   throws and nothing is logged.
   
   `preamble.ts` calls `dayjs.locale(toDayjsLocale(lang))` for whatever 
language the user is
   on, for all 30 languages that have a catalog under `superset/translations/`. 
But
   `useLocale.ts` imports only 16 of them — the same 16 that `LOCALE_MAPPING` 
covers for Ant
   Design. For the remaining 14, the call does nothing and every relative date 
renders in
   English next to a fully translated UI.
   
   Measured against `master` with the real dayjs build, starting from `en` each 
time:
   
   | language | asks dayjs for | locale left in effect | "3 days ago" renders 
as |
   |---|---|---|---|
   | `ar` `ca` `fa` `fi` `lv` `mi` `pl` `ro` `ta` `th` `tr` `uk` | its own code 
| `en` | *3 days ago* |
   | `sr` | `sr` | `en` | *3 days ago* |
   | `sr_Latn` | `sr-latn` | `en` | *3 days ago* |
   
   14 of 30. With the imports added, all 30 resolve to a locale that is 
actually loaded:
   *fa 3 dies*, *3 dni temu*, *pirms 3 dienām*, *пре 3 дана*, *3 gün önce*, and 
so on.
   
   **The Serbian pair needs more than an import.** The two projects name the 
scripts the other
   way around:
   
   | | Cyrillic | Latin |
   |---|---|---|
   | Superset catalogs | `sr` (143,945 Cyrillic chars) | `sr_Latn` (0) |
   | dayjs locales | `sr-cyrl` (404 Cyrillic chars) | `sr` (0) |
   
   So normalizing `sr` → `sr` hands the **Cyrillic** catalog the **Latin** 
locale — verified:
   with the imports in place but no override, the `sr` catalog renders *pre 3 
dana* instead of
   *пре 3 дана*. `DAYJS_LOCALE_OVERRIDES` fixes that.
   
   The `sr_Latn` entry is a smaller point, stated for honesty: `sr-latn` is not 
a locale dayjs
   ships, and dayjs retries the base language on a suffixed name, so `sr-latn` 
already lands on
   `sr` (Latin) once `sr` is imported — correct, but by way of an undocumented 
retry. The entry
   makes the intent explicit instead.
   
   Finally, `'ta'` is added to the `Locale` type in `@apache-superset/core`, 
whose own comment
   says *"every locale with a catalog in superset/translations"* and lists the 
other 29.
   
   Follows #45834, which replaced the hardcoded name map with 
`toDayjsLocale()`. That
   derivation is right for 27 of the 29 codes; this adds the imports those 
names need, and the
   one pair normalization cannot derive. Part of a short run of i18n fixes: 
#45953 (merged),
   #45973 and #45974.
   
   ### TESTING INSTRUCTIONS
   
   The locale imports are side effects, and `useLocale.test.tsx` mocks both 
`extendedDayjs` and
   every `dayjs/locale/*` module, so a unit test there can only assert the 
*name* passed to
   `dayjs.locale()` — which is what the new `toDayjsLocale` test does. Proving 
that the locale
   is really loaded needs the unmocked library:
   
   ```js
   const dayjs = require('dayjs');
   dayjs.extend(require('dayjs/plugin/relativeTime'));
   require('dayjs/locale/ca');
   dayjs.locale('en');
   console.log(dayjs.locale('ca'), dayjs().subtract(3, 'day').fromNow());
   // with the import:    ca   fa 3 dies
   // without the import: en   3 days ago
   ```
   
   `dayjs.locale()` returning something other than what you passed is the tell.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ---
   
   Developed at MYSPHERA, S.L.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

  • [PR] fix(i1... antalotec (via GitHub) via notifications
    • Re: [P... netlify[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codecov[bot] (via GitHub) via notifications

Reply via email to