feat(import): apply translation to successful bulk items
The interactive batch ignored the client's Translate option, so translated names never landed in the language files during a bulk run. Patch each successful item through patchLocalizedFurniDataEntries (mutex-guarded, best-effort) when translation is requested, surfacing failures as item warnings instead of failing the import.
This commit is contained in:
1 parent
ffcd4232d6
commit
fb68df3ba9
1 file changed
+39
-6
@@ -12,7 +12,10 @@ import {
|
||||
reconcileFurniDataWithItemsBase,
|
||||
verifyAndFixSpriteIds,
|
||||
} from "@/lib/services/furni-data";
|
||||
import { buildLocalizedFurniDataFiles } from "@/lib/services/furni-data-i18n";
|
||||
import {
|
||||
buildLocalizedFurniDataFiles,
|
||||
patchLocalizedFurniDataEntries,
|
||||
} from "@/lib/services/furni-data-i18n";
|
||||
import {
|
||||
ensureDirectories,
|
||||
ensureFurniOwnership,
|
||||
@@ -247,15 +250,46 @@ export const POST = withAdmin(
|
||||
|
||||
if (result.ok) {
|
||||
succeeded++;
|
||||
if (result.warnings.length > 0) withWarnings++;
|
||||
const warnings = [...result.warnings];
|
||||
if (result.furniDataEntry)
|
||||
furniDataEntries.push(result.furniDataEntry);
|
||||
|
||||
// Translation is best-effort, same as the queue worker:
|
||||
// a failure warns but never fails the import.
|
||||
if (body.translate === true) {
|
||||
try {
|
||||
send({
|
||||
type: "item_progress",
|
||||
classname: item.classname,
|
||||
status: "translating",
|
||||
index,
|
||||
});
|
||||
await patchLocalizedFurniDataEntries(
|
||||
[
|
||||
{
|
||||
classname: item.classname,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
},
|
||||
],
|
||||
true,
|
||||
Array.isArray(body.langs) && body.langs.length > 0
|
||||
? body.langs
|
||||
: undefined,
|
||||
);
|
||||
} catch {
|
||||
warnings.push(
|
||||
"Translation failed; furniture imported successfully",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (warnings.length > 0) withWarnings++;
|
||||
|
||||
if (entry) {
|
||||
entry.state = "done";
|
||||
entry.itemId = result.itemId;
|
||||
entry.warnings =
|
||||
result.warnings.length > 0 ? result.warnings : undefined;
|
||||
entry.warnings = warnings.length > 0 ? warnings : undefined;
|
||||
checkpoint();
|
||||
}
|
||||
|
||||
@@ -265,8 +299,7 @@ export const POST = withAdmin(
|
||||
status: "done",
|
||||
index,
|
||||
itemId: result.itemId,
|
||||
warnings:
|
||||
result.warnings.length > 0 ? result.warnings : undefined,
|
||||
warnings: warnings.length > 0 ? warnings : undefined,
|
||||
});
|
||||
|
||||
logAudit({
|
||||
|
||||
Reference in new issue
Block a user