isFile() && $file->getExtension() === 'php') { $content = file_get_contents($file->getPathname()); // Search for each pattern foreach ($patterns as $pattern) { if (preg_match_all($pattern, $content, $matches)) { foreach ($matches[1] as $string) { // Clean up the string $string = trim($string); // Skip empty strings if (empty($string)) { continue; } // Store unique strings $strings[$string] = true; } } } } } } // Scan all directories foreach ($scan_dirs as $dir) { scanDirectory($dir, $strings, $patterns); } // Sort strings alphabetically $strings = array_keys($strings); sort($strings); // Generate POT file content $pot_content = <<<'EOT' # Copyright (C) 2025 AI eShop Optimizer # This file is distributed under the same license as the AI eShop Optimizer plugin. msgid "" msgstr "" "Project-Id-Version: AI eShop Optimizer\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ai-eshop-optimizer\n" "POT-Creation-Date: 2025-01-27 12:00+0000\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "X-Generator: Custom PHP Script\n" EOT; // Add each string as a msgid entry foreach ($strings as $string) { // Escape special characters $escaped = addcslashes($string, "\0..\37\"\\"); $pot_content .= "msgid \"$escaped\"\n"; $pot_content .= "msgstr \"\"\n\n"; } // Write to POT file $pot_file = $languages_dir . '/ai-eshop-optimizer.pot'; file_put_contents($pot_file, $pot_content); // Output results echo "POT file generated successfully!\n"; echo "Location: " . esc_html($pot_file) . "\n"; echo "Extracted " . count($strings) . " unique translatable strings\n"; echo "File size: " . number_format(filesize($pot_file)) . " bytes\n";