feat(i18n): display only active language in translation fields

Update TranslationFields to render a single input for the current locale
Ensure entity base names fallback to the active locale translation on save
This commit is contained in:
2026-05-01 14:11:31 +08:00
parent 62406bdc84
commit ca3ca35dfc
5 changed files with 63 additions and 20 deletions

View File

@@ -248,6 +248,14 @@ function configBaseNameForSave() {
return configForm.value.translations[currentConfigLocale.value]?.name ?? '';
}
function checklistTitleForSave() {
if (checklistForm.value.title.trim() !== '') {
return checklistForm.value.title;
}
return checklistForm.value.translations[currentConfigLocale.value]?.title ?? '';
}
function previewChecklistOrder(rows: DailyChecklistItem[]) {
checklistRows.value = rows;
}
@@ -391,7 +399,7 @@ async function loadChecklist() {
async function saveChecklistItem() {
await run(async () => {
const payload = {
title: checklistForm.value.title,
title: checklistTitleForSave(),
translations: checklistForm.value.translations
};

View File

@@ -30,7 +30,7 @@ type HabitatAppearanceForm = {
const route = useRoute();
const router = useRouter();
const { t } = useI18n();
const { locale, t } = useI18n();
const options = ref<Options | null>(null);
const itemRows = ref<Item[]>([]);
const pokemonRows = ref<Pokemon[]>([]);
@@ -127,6 +127,15 @@ function closeEditor() {
void router.push(cancelTo.value);
}
function habitatNameForSave() {
const baseName = habitatForm.value.name.trim();
if (baseName !== '') {
return habitatForm.value.name;
}
return habitatForm.value.translations[String(locale.value || '')]?.name ?? '';
}
async function loadEditor() {
loading.value = true;
message.value = '';
@@ -189,7 +198,7 @@ async function saveHabitat() {
try {
const payload: HabitatPayload = {
name: habitatForm.value.name,
name: habitatNameForSave(),
translations: habitatForm.value.translations,
recipeItems: toQuantityRows(habitatForm.value.recipeItems),
pokemonAppearances: habitatForm.value.pokemonAppearances

View File

@@ -11,7 +11,7 @@ import { api, type ConfigType, type ItemPayload, type Language, type Options, ty
const route = useRoute();
const router = useRouter();
const { t } = useI18n();
const { locale, t } = useI18n();
const options = ref<Options | null>(null);
const languages = ref<Language[]>([]);
const loading = ref(true);
@@ -53,6 +53,15 @@ function closeEditor() {
void router.push(cancelTo.value);
}
function itemNameForSave() {
const baseName = itemForm.value.name.trim();
if (baseName !== '') {
return itemForm.value.name;
}
return itemForm.value.translations[String(locale.value || '')]?.name ?? '';
}
async function loadOptions() {
const [loadedOptions, loadedLanguages] = await Promise.all([api.options(), api.languages()]);
options.value = loadedOptions;
@@ -131,7 +140,7 @@ async function saveItem() {
try {
const payload: ItemPayload = {
name: itemForm.value.name,
name: itemNameForSave(),
translations: itemForm.value.translations,
categoryId: Number(itemForm.value.categoryId),
usageId: itemForm.value.usageId ? Number(itemForm.value.usageId) : null,

View File

@@ -16,7 +16,7 @@ type SkillItemDropForm = {
const route = useRoute();
const router = useRouter();
const { t } = useI18n();
const { locale, t } = useI18n();
const options = ref<Options | null>(null);
const itemOptions = ref<NamedEntity[]>([]);
const languages = ref<Language[]>([]);
@@ -87,6 +87,15 @@ function skillDropLabel(skillId: string) {
return name ? t('pages.pokemon.skillDrop', { name }) : t('pages.pokemon.dropItem');
}
function pokemonNameForSave() {
const baseName = pokemonForm.value.name.trim();
if (baseName !== '') {
return pokemonForm.value.name;
}
return pokemonForm.value.translations[String(locale.value || '')]?.name ?? '';
}
function closeEditor() {
void router.push(cancelTo.value);
}
@@ -164,7 +173,7 @@ async function savePokemon() {
try {
const payload: PokemonPayload = {
id: Number(isEditing.value ? routeId.value : pokemonForm.value.id),
name: pokemonForm.value.name,
name: pokemonNameForSave(),
translations: pokemonForm.value.translations,
environmentId: Number(pokemonForm.value.environmentId),
skillIds: toIds(pokemonForm.value.skillIds.slice(0, 2)),