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 time units on activity heatmap #21570

Merged
merged 25 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0479791
Localize time units on activity heatmap
yardenshoham Oct 23, 2022
9bbba06
Localize heatmap constants and tooltip
yardenshoham Oct 24, 2022
5cadb9d
Merge remote-tracking branch 'upstream/main' into localize-heatmap
yardenshoham Oct 24, 2022
57e4135
Add tests
yardenshoham Oct 24, 2022
2d01191
Destructure
yardenshoham Oct 24, 2022
95dd077
Merge remote-tracking branch 'upstream/main' into localize-heatmap
yardenshoham Oct 24, 2022
eba5ff3
Drop line
yardenshoham Oct 24, 2022
50092fc
Merge branch 'main' into localize-heatmap
yardenshoham Oct 25, 2022
d1a8a92
Rename `format` --> `translate`
yardenshoham Oct 25, 2022
fa30c07
Remove overhead
yardenshoham Oct 25, 2022
9e07322
Merge remote-tracking branch 'upstream/main' into localize-heatmap
yardenshoham Oct 25, 2022
d2d5081
Update web_src/js/utils.js
yardenshoham Oct 25, 2022
afaa731
Update web_src/js/utils.test.js
yardenshoham Oct 26, 2022
d44a422
Revert locale attempt
yardenshoham Oct 26, 2022
e54d70d
Merge branch 'main' into localize-heatmap
yardenshoham Oct 26, 2022
55b2f28
Lint
yardenshoham Oct 26, 2022
8775a5a
Merge remote-tracking branch 'upstream/main' into localize-heatmap
yardenshoham Oct 26, 2022
2557f99
Merge branch 'main' into localize-heatmap
lunny Oct 27, 2022
51f400f
Merge branch 'main' into localize-heatmap
lunny Oct 27, 2022
caaee20
Trigger build
yardenshoham Oct 27, 2022
607473b
Merge branch 'main' into localize-heatmap
lunny Oct 28, 2022
a7a75d2
Merge branch 'main' into localize-heatmap
lunny Oct 28, 2022
1a4fe52
Merge branch 'main' into localize-heatmap
lunny Oct 28, 2022
2b416cc
Merge branch 'main' into localize-heatmap
yardenshoham Oct 28, 2022
6cd227c
Merge branch 'main' into localize-heatmap
techknowlogick Oct 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions web_src/js/components/ActivityHeatmap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default {
type: Array,
default: () => [],
},
locale: {
type: Object,
default: () => {},
}
},
data: () => ({
colorRange: [
Expand All @@ -36,10 +40,6 @@ export default {
'var(--color-primary-dark-4)',
],
endDate: new Date(),
locale: {
contributions: 'contributions',
no_contributions: 'No contributions',
},
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
}),
computed: {
sum() {
Expand Down
11 changes: 9 additions & 2 deletions web_src/js/features/heatmap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createApp} from 'vue';
import ActivityHeatmap from '../components/ActivityHeatmap.vue';

import {translateMonth, translateDay} from '../utils.js';
export default function initHeatmap() {
const el = document.getElementById('user-heatmap');
if (!el) return;
Expand All @@ -17,7 +17,14 @@ export default function initHeatmap() {
return {date: new Date(v), count: heatmap[v]};
});

const View = createApp(ActivityHeatmap, {values});
const locale = {
months: new Array(12).fill().map((_, idx) => translateMonth(idx)),
days: new Array(7).fill().map((_, idx) => translateDay(idx)),
contributions: 'contributions',
no_contributions: 'No contributions',
};

const View = createApp(ActivityHeatmap, {values, locale});

View.mount(el);
} catch (err) {
Expand Down
15 changes: 15 additions & 0 deletions web_src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
export 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'});
}
24 changes: 23 additions & 1 deletion web_src/js/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect, test} from 'vitest';
import {
basename, extname, isObject, uniq, stripTags, joinPaths, parseIssueHref,
prettyNumber, parseUrl,
prettyNumber, parseUrl, translateMonth, translateDay
} from './utils.js';

test('basename', () => {
Expand Down Expand Up @@ -109,3 +109,25 @@ test('parseUrl', () => {
expect(parseUrl('https://localhost/path?search').search).toEqual('?search');
expect(parseUrl('https://localhost/path?search#hash').hash).toEqual('#hash');
});

test('translateMonth', () => {
const originalLang = document.documentElement.lang;
document.documentElement.lang = 'en-US';
expect(translateMonth(0)).toEqual('Jan');
expect(translateMonth(4)).toEqual('May');
document.documentElement.lang = 'es-ES';
expect(translateMonth(5)).toEqual('jun');
expect(translateMonth(6)).toEqual('jul');
document.documentElement.lang = originalLang;
});

test('translateDay', () => {
const originalLang = document.documentElement.lang;
document.documentElement.lang = 'fr-FR';
expect(translateDay(1)).toEqual('lun.');
expect(translateDay(5)).toEqual('ven.');
document.documentElement.lang = 'pl-PL';
expect(translateDay(1)).toEqual('pon.');
expect(translateDay(5)).toEqual('pt.');
document.documentElement.lang = originalLang;
});