get_results( "SELECT context, COUNT(*) AS n FROM {$wpdb->prefix}icl_strings GROUP BY context ORDER BY n DESC" ); echo "Strings registered (icl_strings) by context :\n"; foreach ($rows as $r) echo sprintf(" %-40s %d strings\n", $r->context, $r->n); // 1b) Sample strings whose VALUE matches our content (find which context Bricks uses for page content) echo "\nSearching for our content strings :\n"; foreach (['PROSERVE', 'Police training', 'Built for those', 'mini-case', 'Industries', 'Solutions'] as $needle) { $found = $wpdb->get_results($wpdb->prepare( "SELECT context, name, LEFT(value, 70) AS preview FROM {$wpdb->prefix}icl_strings WHERE value LIKE %s LIMIT 3", '%' . $wpdb->esc_like($needle) . '%' )); echo " needle '$needle' : " . count($found) . " match(es)\n"; foreach ($found as $f) echo " context='{$f->context}' name='{$f->name}' value='{$f->preview}'\n"; } // 2) Sample a few Bricks strings + their FR (context is just 'bricks', not per-page) echo "\nSample Bricks strings (10 of 156) :\n"; $strings = $wpdb->get_results( "SELECT id, name, LEFT(value, 80) AS preview, status FROM {$wpdb->prefix}icl_strings WHERE context='bricks' LIMIT 10" ); foreach ($strings as $s) { echo " id={$s->id} name={$s->name} status={$s->status}\n EN: {$s->preview}\n"; $fr = $wpdb->get_var($wpdb->prepare( "SELECT LEFT(value, 80) FROM {$wpdb->prefix}icl_string_translations WHERE string_id=%d AND language='fr' LIMIT 1", $s->id )); echo " FR: " . ($fr !== null ? $fr : '(no translation)') . "\n"; } // 3) Count translations by language and status $tr_rows = $wpdb->get_results( "SELECT language, status, COUNT(*) AS n FROM {$wpdb->prefix}icl_string_translations GROUP BY language, status" ); echo "\nString translations summary :\n"; foreach ($tr_rows as $r) echo " lang={$r->language} status={$r->status} : {$r->n}\n"; exit; } function av_wpml_strings_push() { global $wpdb; header('Content-Type: text/plain; charset=utf-8'); if (! function_exists('icl_add_string_translation')) { echo "FAIL : icl_add_string_translation() not available\n"; exit; } // Trigger the dict to load (with all filter contributions from generators) $dict = av_fr_translation_dictionary(); echo "Loaded FR dictionary : " . count($dict) . " EN→FR mappings\n\n"; // All Bricks page-content strings (per-page contexts : bricks-{POST_ID}) $strings = $wpdb->get_results( "SELECT id, value, context FROM {$wpdb->prefix}icl_strings WHERE context LIKE 'bricks-%'" ); echo "Found " . count($strings) . " EN strings registered for Bricks pages\n\n"; $matched = 0; $unmatched = 0; $written = 0; foreach ($strings as $s) { if (! isset($dict[$s->value])) { $unmatched++; continue; } $matched++; $fr = $dict[$s->value]; // ICL_TM_COMPLETE = 10 $result = icl_add_string_translation((int) $s->id, 'fr', $fr, 10); if ($result) $written++; } echo "Matched in dict : $matched\n"; echo "Written to icl_string_translations : $written\n"; echo "Unmatched (no FR in dict, will stay EN in ATE) : $unmatched\n"; if ($unmatched > 0 && $unmatched < 100) { echo "\nSample unmatched EN strings (extend the dict to translate these) :\n"; $shown = 0; foreach ($strings as $s) { if (! isset($dict[$s->value]) && $shown < 15) { echo " - " . substr($s->value, 0, 120) . (strlen($s->value) > 120 ? '...' : '') . "\n"; $shown++; } } } echo "\nDONE. Refresh ATE — FR strings should be pre-filled.\n"; exit; }