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,
|
reconcileFurniDataWithItemsBase,
|
||||||
verifyAndFixSpriteIds,
|
verifyAndFixSpriteIds,
|
||||||
} from "@/lib/services/furni-data";
|
} from "@/lib/services/furni-data";
|
||||||
import { buildLocalizedFurniDataFiles } from "@/lib/services/furni-data-i18n";
|
import {
|
||||||
|
buildLocalizedFurniDataFiles,
|
||||||
|
patchLocalizedFurniDataEntries,
|
||||||
|
} from "@/lib/services/furni-data-i18n";
|
||||||
import {
|
import {
|
||||||
ensureDirectories,
|
ensureDirectories,
|
||||||
ensureFurniOwnership,
|
ensureFurniOwnership,
|
||||||
@@ -247,15 +250,46 @@ export const POST = withAdmin(
|
|||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
succeeded++;
|
succeeded++;
|
||||||
if (result.warnings.length > 0) withWarnings++;
|
const warnings = [...result.warnings];
|
||||||
if (result.furniDataEntry)
|
if (result.furniDataEntry)
|
||||||
furniDataEntries.push(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) {
|
if (entry) {
|
||||||
entry.state = "done";
|
entry.state = "done";
|
||||||
entry.itemId = result.itemId;
|
entry.itemId = result.itemId;
|
||||||
entry.warnings =
|
entry.warnings = warnings.length > 0 ? warnings : undefined;
|
||||||
result.warnings.length > 0 ? result.warnings : undefined;
|
|
||||||
checkpoint();
|
checkpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,8 +299,7 @@ export const POST = withAdmin(
|
|||||||
status: "done",
|
status: "done",
|
||||||
index,
|
index,
|
||||||
itemId: result.itemId,
|
itemId: result.itemId,
|
||||||
warnings:
|
warnings: warnings.length > 0 ? warnings : undefined,
|
||||||
result.warnings.length > 0 ? result.warnings : undefined,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logAudit({
|
logAudit({
|
||||||
|
|||||||
Reference in new issue
Block a user