Skip to content

Commit 02dde23

Browse files
authored
Merge pull request #136 from vuejs-jp/feature/sponsor-section-localization
fix: Localize the duration in sponsor section
2 parents 121c902 + 165747c commit 02dde23

File tree

10 files changed

+203
-66
lines changed

10 files changed

+203
-66
lines changed

.github/workflows/chromatic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
with:
3434
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
3535
workingDir: ./packages/ui
36+
storybookBaseDir: ./packages/ui
3637
exitZeroOnChanges: true
3738
exitOnceUploaded: true
3839
onlyChanged: true

apps/web/app/components/SponsorPageSection.vue

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
<script setup lang="ts">
2-
import { useRuntimeConfig } from '#imports'
32
import { useI18n } from '#i18n'
3+
import { useRuntimeConfig } from '#imports'
44
import { useColor, useTypography } from '@vuejs-jp/composable'
5+
import { useLocaleCurrent } from '@/composables/useLocaleCurrent'
56
67
const config = useRuntimeConfig()
7-
const { locale } = useI18n()
88
const { fontWeight, fontSize } = useTypography()
99
const { color } = useColor()
10+
11+
const { t, te } = useI18n()
12+
const { locale } = useLocaleCurrent()
13+
/**
14+
* Get translation or return empty string
15+
* @param key - translation key
16+
* @returns translation or empty string
17+
*/
18+
function getTranslationOrDefault(key: string): string {
19+
return te(key, locale.value) ? t(key) : ''
20+
}
21+
22+
const periodStart = {
23+
prefixYear: t('prefix_year'),
24+
date: t('start_date'),
25+
dayOfWeek: getTranslationOrDefault('day_of_week.monday'),
26+
}
27+
28+
const periodEnd = {
29+
suffixYear: t('suffix_year'),
30+
date: t('end_date'),
31+
dayOfWeek: getTranslationOrDefault('day_of_week.thursday'),
32+
}
1033
</script>
1134

1235
<template>
@@ -37,10 +60,7 @@ const { color } = useColor()
3760
>
3861
{{ $t('sponsor.apply_period') }}
3962
</h3>
40-
<VFDatePeriod
41-
:start="{ year: 2024, date: '4.8', dayOfWeek: locale === 'ja' ? $t('day_of_week.monday') : '' }"
42-
:end="{ date: '4.25', dayOfWeek: locale === 'ja' ? $t('day_of_week.thursday') : '' }"
43-
/>
63+
<VFDatePeriod :start="periodStart" :end="periodEnd" />
4464
</template>
4565

4666
<div class="sponsor-buttons">
@@ -69,8 +89,7 @@ const { color } = useColor()
6989
</template>
7090

7191
<style scoped>
72-
@import url("~/assets/media.css");
73-
@import url("~/assets/sample.css");
92+
@import url('~/assets/media.css');
7493
7594
.sponsor {
7695
--sponsor-padding: calc(var(--unit) * 5.25) 0;
@@ -95,6 +114,7 @@ const { color } = useColor()
95114
margin: 0 1.5%;
96115
background-color: white;
97116
max-width: 960px;
117+
text-align: center;
98118
}
99119
100120
.sponsor-text {
@@ -108,7 +128,7 @@ const { color } = useColor()
108128
109129
&::v-deep a:hover {
110130
opacity: 0.4;
111-
transition: .2s;
131+
transition: 0.2s;
112132
}
113133
114134
&:deep(p) {

apps/web/app/lang/en.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"about": "about",
55
"back_to_top": "Back o Top",
66
"not_found": "The page you are looking for cannot be found.",
7-
"day_of_week": {
8-
"monday": "Mon",
9-
"tuesday": "Tue",
10-
"thursday": "Thu"
11-
},
7+
"prefix_year": "",
8+
"suffix_year": "2024",
9+
"start_date": "April 8",
10+
"end_date": "25,",
1211
"top_page": {
1312
"latest_information": "Get the latest information on our official social media",
1413
"date": "Octover 19th, 2024",

apps/web/app/lang/ja.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"about": "このサイトについて",
55
"back_to_top": "トップに戻る",
66
"not_found": "お探しのページが見つかりません。",
7+
"prefix_year": "2024",
8+
"suffix_year": "",
9+
"start_date": "4.8",
10+
"end_date": "4.25",
711
"day_of_week": {
812
"monday": "",
913
"tuesday": "",

packages/ui/.storybook/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
'@storybook/addon-essentials',
1313
'@storybook/addon-links',
1414
'@storybook/addon-viewport',
15+
'@storybook/addon-toolbars',
1516
],
1617
framework: {
1718
name: '@storybook/vue3-vite',

packages/ui/.storybook/preview.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1+
import { setup } from '@storybook/vue3'
12
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport'
3+
import { createI18n } from 'vue-i18n'
24

35
import './global.css'
46

7+
const i18n = createI18n({
8+
locale: 'ja',
9+
fallbackLocale: 'ja',
10+
messages: {
11+
ja: {
12+
prefix_year: '2024',
13+
suffix_year: '',
14+
start_date: '4.8',
15+
end_date: '4.25',
16+
day_of_week: {
17+
monday: '月',
18+
tuesday: '火',
19+
thursday: '木',
20+
},
21+
},
22+
en: {
23+
prefix_year: '',
24+
suffix_year: '2024',
25+
start_date: 'April 8',
26+
end_date: '25,',
27+
// dummy
28+
day_of_week: {
29+
monday: '',
30+
tuesday: '',
31+
thursday: '',
32+
},
33+
// end dummy
34+
},
35+
},
36+
})
37+
38+
setup((app) => {
39+
app.use(i18n)
40+
})
41+
542
export const parameters = {
643
controls: {
744
matchers: {
@@ -14,3 +51,22 @@ export const parameters = {
1451
defaultViewport: 'responsive',
1552
},
1653
}
54+
55+
export const decorators = [
56+
(story, context) => {
57+
i18n.global.locale = context.globals.locale
58+
return { template: '<story />' }
59+
},
60+
]
61+
62+
export const globalTypes = {
63+
locale: {
64+
name: 'Locale',
65+
description: '多言語設定',
66+
defaultValue: 'ja',
67+
toolbar: {
68+
icon: 'globe',
69+
items: ['ja', 'en'],
70+
},
71+
},
72+
}
Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { StoryFn } from '@storybook/vue3'
1+
import { Meta, StoryObj } from '@storybook/vue3'
22
import Date from './Date.vue'
33

4-
export default {
4+
const meta: Meta<typeof Date> = {
55
title: 'date/Date',
6+
tags: ['autodocs'],
67
component: Date,
7-
args: {
8-
date: '4.1',
9-
dayOfWeek: '月',
10-
},
118
argTypes: {
12-
year: {
13-
description: 'The year property',
9+
prefixYear: {
10+
description: 'The prefixYear property',
11+
control: {
12+
type: 'text',
13+
},
14+
},
15+
suffixYear: {
16+
description: 'The suffixYear property',
1417
control: {
1518
type: 'text',
1619
},
@@ -30,18 +33,37 @@ export default {
3033
},
3134
}
3235

33-
const Template: StoryFn<unknown> = (args, { argTypes }) => ({
34-
props: Object.keys(argTypes),
35-
components: { Date },
36-
setup() {
37-
return { args }
38-
},
39-
template: '<Date v-bind="args" />',
40-
})
36+
export default meta
37+
38+
type Story = StoryObj<typeof Date>
4139

42-
export const Default = Template.bind({})
40+
/**
41+
* Controlでpropsを切り替えると、日付と曜日表記が変わる
42+
*/
43+
export const PropsControls: Story = {
44+
name: 'propsControls',
45+
args: {
46+
prefixYear: '2024',
47+
suffixYear: '',
48+
date: '5.8',
49+
dayOfWeek: '月',
50+
},
51+
render: (args) => ({
52+
components: { Date },
53+
setup() {
54+
return { args }
55+
},
56+
template: '<Date :="args" />',
57+
})
58+
}
4359

44-
export const WithYear = Template.bind({})
45-
WithYear.args = {
46-
year: 2024,
60+
/**
61+
* ツールバーで言語を切り替えると、日付と曜日表記が変わる
62+
*/
63+
export const I18n: Story = {
64+
name: 'i18n',
65+
render: () => ({
66+
components: { Date },
67+
template: '<Date :prefix-year="$t(`prefix_year`)" :suffix-year="$t(`suffix_year`)" :date="$t(`start_date`)" :dayOfWeek="$t(`day_of_week.monday`)" />'
68+
})
4769
}

packages/ui/components/date/Date.vue

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
import { useColor, useTypography } from '@vuejs-jp/composable'
33
44
export type DateProps = {
5-
year?: number
5+
prefixYear?: string
6+
suffixYear?: string
67
date: string
78
dayOfWeek?: string
89
}
910
10-
// eslint-disable-next-line no-unused-vars
11-
const props = defineProps<DateProps>()
11+
defineProps<DateProps>()
1212
1313
const { fontWeight, fontSize } = useTypography()
1414
const { color } = useColor()
1515
</script>
1616

1717
<template>
1818
<div class="datewrapper">
19-
<!-- year -->
19+
<!-- prefix year -->
2020
<span
21-
v-if="year"
21+
v-if="prefixYear"
2222
:style="{
2323
fontSize: fontSize('heading/300'),
2424
color: color('vue-blue'),
2525
}"
26-
class="year"
26+
class="year prefix-year"
2727
>
28-
{{ year }}
28+
{{ prefixYear }}
2929
</span>
3030
<!-- date -->
3131
<span
@@ -50,6 +50,17 @@ const { color } = useColor()
5050
>
5151
{{ dayOfWeek }}
5252
</span>
53+
<!-- suffix year -->
54+
<span
55+
v-if="suffixYear"
56+
:style="{
57+
fontSize: fontSize('heading/300'),
58+
color: color('vue-blue'),
59+
}"
60+
class="year suffix-year"
61+
>
62+
{{ suffixYear }}
63+
</span>
5364
</div>
5465
</template>
5566

@@ -61,9 +72,14 @@ const { color } = useColor()
6172
6273
.year {
6374
display: inline-block;
64-
margin-right: 6px;
6575
font-size: 24px;
6676
}
77+
.prefix-year {
78+
margin-right: 6px;
79+
}
80+
.suffix-year {
81+
margin-left: 6px;
82+
}
6783
6884
.date {
6985
display: inline-block;
@@ -80,6 +96,5 @@ const { color } = useColor()
8096
height: 20px;
8197
border-radius: 2px;
8298
margin-left: 4px;
83-
8499
}
85100
</style>

0 commit comments

Comments
 (0)