diff options
author | Yarden Shoham <hrsi88@gmail.com> | 2022-10-28 16:48:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 09:48:24 -0400 |
commit | 125e3e3d66d117d23e387c083d22a8d90820bb52 (patch) | |
tree | f70c2bd88cf339970f96d193bc0908a35a22be11 /web_src/js/utils.js | |
parent | 76e9a4f701880d798d90a3e069e571052e342da8 (diff) | |
download | gitea-125e3e3d66d117d23e387c083d22a8d90820bb52.tar.gz gitea-125e3e3d66d117d23e387c083d22a8d90820bb52.zip |
Localize time units on activity heatmap (#21570)
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>
Diffstat (limited to 'web_src/js/utils.js')
-rw-r--r-- | web_src/js/utils.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 4020b7a7f4..9b8bf925a9 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -70,3 +70,18 @@ export function prettyNumber(num, locale = 'en-US') { export function parseUrl(str) { return new URL(str, str.startsWith('http') ? undefined : window.location.origin); } + +// return current locale chosen by user +function getCurrentLocale() { + return document.documentElement.lang; +} + +// 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'}); +} + +// 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'}); +} |