updateById('products', 'name', $translations['products']); $categoryCount = $this->updateById('categories', 'name', $translations['categories']); $unitCount = $this->updateById('units', 'actual_name', $translations['units']); $unitShortCount = $this->updateById('units', 'short_name', $translations['unit_short_names']); $templateCount = $this->updateById('variation_templates', 'name', $translations['variation_templates']); $productVariationCount = $this->updateByName('product_variations', 'name', $translations['product_variations']); $variationValueCount = $this->updateByName('variation_value_templates', 'name', $translations['variation_values']); $variationCount = $this->updateByName('variations', 'name', $translations['variation_values']); DB::commit(); $this->info("فارسی‌سازی با موفقیت انجام شد:"); $this->line(" محصولات: {$productCount}"); $this->line(" دسته‌بندی‌ها: {$categoryCount}"); $this->line(" واحدها: {$unitCount} (+ {$unitShortCount} نام کوتاه)"); $this->line(" قالب تنوع: {$templateCount}"); $this->line(" تنوع محصول: {$productVariationCount}"); $this->line(" مقادیر تنوع: {$variationValueCount}"); $this->line(" variations: {$variationCount}"); return self::SUCCESS; } catch (\Throwable $e) { DB::rollBack(); $this->error('خطا در فارسی‌سازی: '.$e->getMessage()); return self::FAILURE; } } private function updateById(string $table, string $column, array $map): int { $count = 0; foreach ($map as $id => $persianName) { $updated = DB::table($table) ->where('id', $id) ->update([$column => $persianName]); $count += $updated; } return $count; } private function updateByName(string $table, string $column, array $map): int { $count = 0; foreach ($map as $englishName => $persianName) { $updated = DB::table($table) ->where($column, $englishName) ->update([$column => $persianName]); $count += $updated; } return $count; } }