|
56 | 56 | <td |
57 | 57 | class="whitespace-nowrap text-ellipsis break-all overflow-hidden px-3 py-2 text-xs text-$ud-text-secondary" |
58 | 58 | > |
59 | | - {{ formatTimeAgo(new Date(item.code_updated_at)) }} |
| 59 | + {{ formatTimeAgoWithI18n(new Date(item.code_updated_at)) }} |
60 | 60 | </td> |
61 | 61 | <td |
62 | 62 | class="relative whitespace-nowrap py-2 pl-3 pr-4 text-right text-xs font-medium" |
|
119 | 119 | </template> |
120 | 120 |
|
121 | 121 | <script setup lang="ts"> |
122 | | - import { formatTimeAgo } from '@vueuse/core'; |
| 122 | + import { formatTimeAgo, UseTimeAgoUnitNamesDefault } from '@vueuse/core'; |
123 | 123 | import { GreasyforkScript } from '../composables/data'; |
124 | 124 |
|
125 | 125 | const props = defineProps<{ data: GreasyforkScript[] }>(); |
|
135 | 135 | }; |
136 | 136 |
|
137 | 137 | const { t } = useI18n(); |
| 138 | +
|
| 139 | + const formatTimeAgoWithI18n = (from: Date) => { |
| 140 | + return formatTimeAgo<UseTimeAgoUnitNamesDefault>(from, { |
| 141 | + messages: { |
| 142 | + justNow: t('time-ago.just-now'), |
| 143 | + past: (n) => (n.match(/\d/) ? t('time-ago.past', { n }) : n), |
| 144 | + future: (n) => (n.match(/\d/) ? t('time-ago.future', { n }) : n), |
| 145 | + month: (n, past) => |
| 146 | + n === 1 |
| 147 | + ? past |
| 148 | + ? t('time-ago.month.past') |
| 149 | + : t('time-ago.month.future') |
| 150 | + : t('time-ago.month.n', { n }), |
| 151 | + year: (n, past) => |
| 152 | + n === 1 |
| 153 | + ? past |
| 154 | + ? t('time-ago.year.past') |
| 155 | + : t('time-ago.year.future') |
| 156 | + : t('time-ago.year.n', { n }), |
| 157 | + day: (n, past) => |
| 158 | + n === 1 |
| 159 | + ? past |
| 160 | + ? t('time-ago.day.past') |
| 161 | + : t('time-ago.day.future') |
| 162 | + : t('time-ago.day.n', { n }), |
| 163 | + week: (n, past) => |
| 164 | + n === 1 |
| 165 | + ? past |
| 166 | + ? t('time-ago.week.past') |
| 167 | + : t('time-ago.week.future') |
| 168 | + : t('time-ago.week.n', { n }), |
| 169 | + hour: (n) => t('time-ago.hour', { n }), |
| 170 | + minute: (n) => t('time-ago.minute', { n }), |
| 171 | + second: (n) => t('time-ago.second', { n }), |
| 172 | + invalid: 'invalid' |
| 173 | + } |
| 174 | + }); |
| 175 | + }; |
138 | 176 | </script> |
0 commit comments