Skip to content

fix: Localize the duration in sponsor section #136

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

Merged
merged 6 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
workingDir: ./packages/ui
storybookBaseDir: ./packages/ui
exitZeroOnChanges: true
exitOnceUploaded: true
onlyChanged: true
Expand Down
38 changes: 29 additions & 9 deletions apps/web/app/components/SponsorPageSection.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
import { useI18n } from '#i18n'
import { useRuntimeConfig } from '#imports'
import { useColor, useTypography } from '@vuejs-jp/composable'
import { useLocaleCurrent } from '@/composables/useLocaleCurrent'

const config = useRuntimeConfig()
const { locale } = useI18n()
const { fontWeight, fontSize } = useTypography()
const { color } = useColor()

const { t, te } = useI18n()
const { locale } = useLocaleCurrent()
/**
* Get translation or return empty string
* @param key - translation key
* @returns translation or empty string
*/
function getTranslationOrDefault(key: string): string {
return te(key, locale.value) ? t(key) : ''
}
Comment on lines +10 to +20
Copy link
Contributor Author

@genj11 genj11 May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiyuujin @toshick @ryuhei373
[Ask]
この部分、tsファイルで管理した方が汎用性あると思いつつ
本プロジェクトでどのディレクトリで管理すべきか判断つかなかったのでコンポーネントに直接実装しています。

外出しする場合、どのディレクトリで管理するのが良いでしょうか?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

外出しする場合、どのディレクトリで管理するのが良いでしょうか?

apps/web/app/composables で良いかと思います

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTranslationOrDefault ではなく composable なので、useTranslation にしておくとよいかと思います。


const periodStart = {
prefixYear: t('prefix_year'),
date: t('start_date'),
dayOfWeek: getTranslationOrDefault('day_of_week.monday'),
}

const periodEnd = {
suffixYear: t('suffix_year'),
date: t('end_date'),
dayOfWeek: getTranslationOrDefault('day_of_week.thursday'),
}
</script>

<template>
Expand Down Expand Up @@ -37,10 +60,7 @@ const { color } = useColor()
>
{{ $t('sponsor.apply_period') }}
</h3>
<VFDatePeriod
:start="{ year: 2024, date: '4.8', dayOfWeek: locale === 'ja' ? $t('day_of_week.monday') : '' }"
:end="{ date: '4.25', dayOfWeek: locale === 'ja' ? $t('day_of_week.thursday') : '' }"
/>
<VFDatePeriod :start="periodStart" :end="periodEnd" />
</template>

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

<style scoped>
@import url("~/assets/media.css");
@import url("~/assets/sample.css");
@import url('~/assets/media.css');

.sponsor {
--sponsor-padding: calc(var(--unit) * 5.25) 0;
Expand All @@ -95,6 +114,7 @@ const { color } = useColor()
margin: 0 1.5%;
background-color: white;
max-width: 960px;
text-align: center;
}

.sponsor-text {
Expand All @@ -108,7 +128,7 @@ const { color } = useColor()

&::v-deep a:hover {
opacity: 0.4;
transition: .2s;
transition: 0.2s;
}

&:deep(p) {
Expand Down
9 changes: 4 additions & 5 deletions apps/web/app/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"about": "about",
"back_to_top": "Back o Top",
"not_found": "The page you are looking for cannot be found.",
"day_of_week": {
"monday": "Mon",
"tuesday": "Tue",
"thursday": "Thu"
},
"prefix_year": "",
"suffix_year": "2024",
"start_date": "April 8",
"end_date": "25,",
"top_page": {
"latest_information": "Get the latest information on our official social media",
"date": "Octover 19th, 2024",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/app/lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"about": "このサイトについて",
"back_to_top": "トップに戻る",
"not_found": "お探しのページが見つかりません。",
"prefix_year": "2024",
"suffix_year": "",
"start_date": "4.8",
"end_date": "4.25",
"day_of_week": {
"monday": "月",
"tuesday": "火",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'@storybook/addon-essentials',
'@storybook/addon-links',
'@storybook/addon-viewport',
'@storybook/addon-toolbars',
],
framework: {
name: '@storybook/vue3-vite',
Expand Down
56 changes: 56 additions & 0 deletions packages/ui/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import { setup } from '@storybook/vue3'
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport'
import { createI18n } from 'vue-i18n'

import './global.css'

const i18n = createI18n({
locale: 'ja',
fallbackLocale: 'ja',
messages: {
ja: {
prefix_year: '2024',
suffix_year: '',
start_date: '4.8',
end_date: '4.25',
day_of_week: {
monday: '月',
tuesday: '火',
thursday: '木',
},
},
en: {
prefix_year: '',
suffix_year: '2024',
start_date: 'April 8',
end_date: '25,',
// dummy
day_of_week: {
monday: '',
tuesday: '',
thursday: '',
},
// end dummy
},
},
})

setup((app) => {
app.use(i18n)
})

export const parameters = {
controls: {
matchers: {
Expand All @@ -14,3 +51,22 @@ export const parameters = {
defaultViewport: 'responsive',
},
}

export const decorators = [
(story, context) => {
i18n.global.locale = context.globals.locale
return { template: '<story />' }
},
]

export const globalTypes = {
locale: {
name: 'Locale',
description: '多言語設定',
defaultValue: 'ja',
toolbar: {
icon: 'globe',
items: ['ja', 'en'],
},
},
}
62 changes: 42 additions & 20 deletions packages/ui/components/date/Date.stories.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { StoryFn } from '@storybook/vue3'
import { Meta, StoryObj } from '@storybook/vue3'
import Date from './Date.vue'

export default {
const meta: Meta<typeof Date> = {
title: 'date/Date',
tags: ['autodocs'],
component: Date,
args: {
date: '4.1',
dayOfWeek: '月',
},
argTypes: {
year: {
description: 'The year property',
prefixYear: {
description: 'The prefixYear property',
control: {
type: 'text',
},
},
suffixYear: {
description: 'The suffixYear property',
control: {
type: 'text',
},
Expand All @@ -30,18 +33,37 @@ export default {
},
}

const Template: StoryFn<unknown> = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { Date },
setup() {
return { args }
},
template: '<Date v-bind="args" />',
})
export default meta

type Story = StoryObj<typeof Date>

export const Default = Template.bind({})
/**
* Controlでpropsを切り替えると、日付と曜日表記が変わる
*/
export const PropsControls: Story = {
name: 'propsControls',
args: {
prefixYear: '2024',
suffixYear: '',
date: '5.8',
dayOfWeek: '月',
},
render: (args) => ({
components: { Date },
setup() {
return { args }
},
template: '<Date :="args" />',
})
}

export const WithYear = Template.bind({})
WithYear.args = {
year: 2024,
/**
* ツールバーで言語を切り替えると、日付と曜日表記が変わる
*/
export const I18n: Story = {
name: 'i18n',
render: () => ({
components: { Date },
template: '<Date :prefix-year="$t(`prefix_year`)" :suffix-year="$t(`suffix_year`)" :date="$t(`start_date`)" :dayOfWeek="$t(`day_of_week.monday`)" />'
})
}
33 changes: 24 additions & 9 deletions packages/ui/components/date/Date.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
import { useColor, useTypography } from '@vuejs-jp/composable'

export type DateProps = {
year?: number
prefixYear?: string
suffixYear?: string
date: string
dayOfWeek?: string
}

// eslint-disable-next-line no-unused-vars
const props = defineProps<DateProps>()
defineProps<DateProps>()

const { fontWeight, fontSize } = useTypography()
const { color } = useColor()
</script>

<template>
<div class="datewrapper">
<!-- year -->
<!-- prefix year -->
<span
v-if="year"
v-if="prefixYear"
:style="{
fontSize: fontSize('heading/300'),
color: color('vue-blue'),
}"
class="year"
class="year prefix-year"
>
{{ year }}
{{ prefixYear }}
</span>
<!-- date -->
<span
Expand All @@ -50,6 +50,17 @@ const { color } = useColor()
>
{{ dayOfWeek }}
</span>
<!-- suffix year -->
<span
v-if="suffixYear"
:style="{
fontSize: fontSize('heading/300'),
color: color('vue-blue'),
}"
class="year suffix-year"
>
{{ suffixYear }}
</span>
</div>
</template>

Expand All @@ -61,9 +72,14 @@ const { color } = useColor()

.year {
display: inline-block;
margin-right: 6px;
font-size: 24px;
}
.prefix-year {
margin-right: 6px;
}
.suffix-year {
margin-left: 6px;
}

.date {
display: inline-block;
Expand All @@ -80,6 +96,5 @@ const { color } = useColor()
height: 20px;
border-radius: 2px;
margin-left: 4px;

}
</style>
Loading