|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { I18nLocaleStatus } from '#shared/types' |
| 3 | +
|
| 4 | +const props = defineProps<{ |
| 5 | + status: I18nLocaleStatus |
| 6 | +}>() |
| 7 | +
|
| 8 | +// Show first N missing keys by default |
| 9 | +const INITIAL_SHOW_COUNT = 5 |
| 10 | +const showAll = ref(false) |
| 11 | +
|
| 12 | +const missingKeysToShow = computed(() => { |
| 13 | + if (showAll.value || props.status.missingKeys.length <= INITIAL_SHOW_COUNT) { |
| 14 | + return props.status.missingKeys |
| 15 | + } |
| 16 | + return props.status.missingKeys.slice(0, INITIAL_SHOW_COUNT) |
| 17 | +}) |
| 18 | +
|
| 19 | +const hasMoreKeys = computed( |
| 20 | + () => props.status.missingKeys.length > INITIAL_SHOW_COUNT && !showAll.value, |
| 21 | +) |
| 22 | +
|
| 23 | +const remainingCount = computed(() => props.status.missingKeys.length - INITIAL_SHOW_COUNT) |
| 24 | +
|
| 25 | +// Generate a GitHub URL that pre-fills the edit with guidance |
| 26 | +const contributionGuideUrl = |
| 27 | + 'https://github.com/npmx-dev/npmx.dev/blob/main/CONTRIBUTING.md#localization-i18n' |
| 28 | +
|
| 29 | +// Copy missing keys as JSON template to clipboard |
| 30 | +const { copy, copied } = useClipboard() |
| 31 | +
|
| 32 | +function copyMissingKeysTemplate() { |
| 33 | + // Create a template showing what needs to be added |
| 34 | + const template = props.status.missingKeys.map(key => ` "${key}": ""`).join(',\n') |
| 35 | +
|
| 36 | + const fullTemplate = `// Missing translations for ${props.status.label} (${props.status.lang}) |
| 37 | +// Add these keys to: i18n/locales/${props.status.lang}.json |
| 38 | +
|
| 39 | +${template}` |
| 40 | +
|
| 41 | + copy(fullTemplate) |
| 42 | +} |
| 43 | +</script> |
| 44 | + |
| 45 | +<template> |
| 46 | + <div class="space-y-3"> |
| 47 | + <!-- Progress section --> |
| 48 | + <div class="space-y-1.5"> |
| 49 | + <div class="flex items-center justify-between text-xs text-fg-muted"> |
| 50 | + <span>{{ $t('settings.translation_progress') }}</span> |
| 51 | + <span class="tabular-nums" |
| 52 | + >{{ status.completedKeys }}/{{ status.totalKeys }} ({{ status.percentComplete }}%)</span |
| 53 | + > |
| 54 | + </div> |
| 55 | + <div class="h-1.5 bg-bg rounded-full overflow-hidden"> |
| 56 | + <div |
| 57 | + class="h-full bg-accent transition-all duration-300 motion-reduce:transition-none" |
| 58 | + :style="{ width: `${status.percentComplete}%` }" |
| 59 | + /> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + |
| 63 | + <!-- Missing keys section --> |
| 64 | + <div v-if="status.missingKeys.length > 0" class="space-y-2"> |
| 65 | + <div class="flex items-center justify-between"> |
| 66 | + <h4 class="text-xs text-fg-muted font-medium"> |
| 67 | + {{ $t('i18n.missing_keys', { count: status.missingKeys.length }) }} |
| 68 | + </h4> |
| 69 | + <button |
| 70 | + type="button" |
| 71 | + class="text-xs text-accent hover:underline rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50" |
| 72 | + @click="copyMissingKeysTemplate" |
| 73 | + > |
| 74 | + {{ copied ? $t('common.copied') : $t('i18n.copy_keys') }} |
| 75 | + </button> |
| 76 | + </div> |
| 77 | + |
| 78 | + <ul class="space-y-1 text-xs font-mono bg-bg rounded-md p-2 max-h-32 overflow-y-auto"> |
| 79 | + <li v-for="key in missingKeysToShow" :key="key" class="text-fg-muted truncate" :title="key"> |
| 80 | + {{ key }} |
| 81 | + </li> |
| 82 | + </ul> |
| 83 | + |
| 84 | + <button |
| 85 | + v-if="hasMoreKeys" |
| 86 | + type="button" |
| 87 | + class="text-xs text-fg-muted hover:text-fg rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" |
| 88 | + @click="showAll = true" |
| 89 | + > |
| 90 | + {{ $t('i18n.show_more_keys', { count: remainingCount }) }} |
| 91 | + </button> |
| 92 | + </div> |
| 93 | + |
| 94 | + <!-- Contribution guidance --> |
| 95 | + <div class="pt-2 border-t border-border space-y-2"> |
| 96 | + <p class="text-xs text-fg-muted"> |
| 97 | + {{ $t('i18n.contribute_hint') }} |
| 98 | + </p> |
| 99 | + |
| 100 | + <div class="flex flex-wrap gap-2"> |
| 101 | + <a |
| 102 | + :href="status.githubEditUrl" |
| 103 | + target="_blank" |
| 104 | + rel="noopener noreferrer" |
| 105 | + class="inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs bg-bg hover:bg-bg-subtle border border-border rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" |
| 106 | + > |
| 107 | + <span class="i-carbon-edit w-3.5 h-3.5" aria-hidden="true" /> |
| 108 | + {{ $t('i18n.edit_on_github') }} |
| 109 | + </a> |
| 110 | + |
| 111 | + <a |
| 112 | + :href="contributionGuideUrl" |
| 113 | + target="_blank" |
| 114 | + rel="noopener noreferrer" |
| 115 | + class="inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-fg-muted hover:text-fg rounded transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" |
| 116 | + > |
| 117 | + <span class="i-carbon-document w-3.5 h-3.5" aria-hidden="true" /> |
| 118 | + {{ $t('i18n.view_guide') }} |
| 119 | + </a> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + </div> |
| 123 | +</template> |
0 commit comments