Skip to content
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

Localize heatmap #15541

Closed
1 of 2 tasks
firesoft-de opened this issue Apr 19, 2021 · 1 comment · Fixed by #21570
Closed
1 of 2 tasks

Localize heatmap #15541

firesoft-de opened this issue Apr 19, 2021 · 1 comment · Fixed by #21570

Comments

@firesoft-de
Copy link
Contributor

  • Gitea version (or commit ref): 1.14.0
  • Git version: not relevant
  • Operating system: not relevant
  • Database (use [x]): not relevant
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist: not relevant

Description

On my gitea instance I got a user request about localizing the heatmap. The legend, the months and the days are always in english (screenshot from german instance below).

grafik

I inspected the code and identified

<calendar-heatmap
:locale="locale"
:no-data-text="locale.no_contributions"
:tooltip-unit="locale.contributions"
:end-date="endDate"
:values="values"
:range-color="colorRange"
@day-click="handleDayClick($event)"
/>
as the point to adopt this change request.

locale is defined here

locale: {
contributions: 'contributions',
no_contributions: 'No contributions',

and is used in dependency like this
https://github.com/julienr114/vue-calendar-heatmap/blob/78963c3b97111b68ba063da631f3d1c2d37af7ec/src/components/consts.js#L3-L9

export const DEFAULT_LOCALE = {
  months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  days: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  on: 'on',
  less: 'Less',
  more: 'More'
}

Unfortunatley I'm not that fluent with javascript (and vue) and need a little kick start (example or something else) with importing the localizations from /options/locale/*.ini. Anyone has a tip on how to do this?

techknowlogick added a commit that referenced this issue Oct 28, 2022
Previously, the months and days were hardcoded into English

* Closes #15541

## Screenshots
### English

![image](https://user-images.githubusercontent.com/20454870/197410352-1b28a637-ce19-41ae-b4e5-27955555b082.png)

### German

![image](https://user-images.githubusercontent.com/20454870/197410455-f243ca84-807f-476e-b8ed-c24e827bfc2d.png)

### Spanish

![image](https://user-images.githubusercontent.com/20454870/197410366-55202ca5-08f9-4152-8f9d-d5eeebd532ef.png)

### Italian

![image](https://user-images.githubusercontent.com/20454870/197410385-75f754dd-e845-4444-8a04-472a8f45b617.png)

### Portuguese
This one has a bit of overflow

![image](https://user-images.githubusercontent.com/20454870/197410414-b91f962e-77e9-4cc7-990b-01c0fc0cbd0b.png)

Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
@fsologureng
Copy link
Contributor

I have an error with this fix because my timezone isn't the expected one:

 FAIL  web_src/js/utils.test.js > translateDay
AssertionError: expected 'dim.' to deeply equal 'lun.'
  web_src/js/utils.test.js:127:27
    125|   const originalLang = document.documentElement.lang;
    126|   document.documentElement.lang = 'fr-FR';
    127|   expect(translateDay(1)).toEqual('lun.');
       |                           ^
    128|   expect(translateDay(5)).toEqual('ven.');
    129|   document.documentElement.lang = 'pl-PL';

  - Expected   "lun."
  + Received   "dim."

I suggest the fix must considered the same timezone (UTC) for the localised test:

 
 // given a month (0-11), returns it in the documents language
 export function translateMonth(month) {
-  return new Date(Date.UTC(2022, month, 12)).toLocaleString(getCurrentLocale(), {month: 'short'});
+  return new Date(Date.UTC(2022, month, 12)).toLocaleString(getCurrentLocale(), {month: 'short', timeZone: 'UTC'});
 }
 
 // given a weekday (0-6, Sunday to Saturday), returns it in the documents language
 export function translateDay(day) {
-  return new Date(Date.UTC(2022, 7, day)).toLocaleString(getCurrentLocale(), {weekday: 'short'});
+  return new Date(Date.UTC(2022, 7, day)).toLocaleString(getCurrentLocale(), {weekday: 'short', timeZone: 'UTC'});
 }

ping @yardenshoham

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants