Tools and techniques for diagnosing common translation problems.
Debug Output in Footer
php
// Add this temporarily to your theme's functions.php
add_action('wp_footer', function () {
if (!current_user_can('manage_options')) return;
$lang = lf_get_current_language();
$default = lf_get_default_language();
$languages = lf_get_languages();
echo '<!-- Lang Forge Debug -->';
echo '<!-- Current Language: ' . esc_html($lang) . ' -->';
echo '<!-- Default Language: ' . esc_html($default) . ' -->';
echo '<!-- URL Format: ' . esc_html(get_option('lf_url_format', 'directory')) . ' -->';
echo '<!-- Active Languages: ' . esc_html(implode(', ', array_keys($languages))) . ' -->';
if (is_singular()) {
$post_id = get_the_ID();
echo '<!-- Post ID: ' . $post_id . ' -->';
echo '<!-- Post Language: ' . esc_html(lf_get_post_language($post_id)) . ' -->';
echo '<!-- Translations: ' . esc_html(wp_json_encode(lf_get_post_translations($post_id))) . ' -->';
}
global $wpdb;
echo '<!-- Total DB Queries: ' . $wpdb->num_queries . ' -->';
echo '<!-- End Lang Forge Debug -->';
});Checking Translation Table Integrity
php
/**
* Verify that the translations table is consistent with postmeta.
* Run via WP-CLI eval or a custom admin tool.
*/
function lf_check_translation_integrity() {
global $wpdb;
$issues = [];
// Find posts with _lf_language meta but no entry in wp_lf_translations
$orphaned_meta = $wpdb->get_results("
SELECT pm.post_id, pm.meta_value as lang
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->prefix}lf_translations t
ON pm.post_id = t.element_id
WHERE pm.meta_key = '_lf_language'
AND t.id IS NULL
AND pm.post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_status != 'trash')
");
if ($orphaned_meta) {
$issues['orphaned_meta'] = count($orphaned_meta);
}
// Find entries in wp_lf_translations that reference deleted posts
$orphaned_translations = $wpdb->get_results("
SELECT t.element_id, t.language_code
FROM {$wpdb->prefix}lf_translations t
LEFT JOIN {$wpdb->posts} p ON t.element_id = p.ID
WHERE p.ID IS NULL
");
if ($orphaned_translations) {
$issues['orphaned_translations'] = count($orphaned_translations);
}
// Find translation groups with only one member
$single_groups = $wpdb->get_var("
SELECT COUNT(*)
FROM (
SELECT translation_group, COUNT(*) as cnt
FROM {$wpdb->prefix}lf_translations
GROUP BY translation_group
HAVING cnt = 1
) as singles
");
if ($single_groups > 0) {
$issues['single_member_groups'] = intval($single_groups);
}
return $issues;
}
// Usage
// $issues = lf_check_translation_integrity();
// print_r($issues);Query Monitor Integration
php
// If using the Query Monitor plugin, Lang Forge queries are tagged
// for easy identification. Look for queries containing:
// - wp_lf_translations
// - wp_lf_strings
// - meta_key = '_lf_language'
//
// In Query Monitor > Queries, filter by "langforge" to see all
// Lang Forge-related database queries.Common Issues and Solutions
php
// Issue: Language switcher not showing
// Check 1: Are multiple languages active?
$languages = lf_get_languages();
if (count($languages) <= 1) {
// Only one language is configured - add more in Lang Forge > Settings
}
// Issue: Posts not filtered by language
// Check 2: Does the post have a _lf_language meta?
$post_lang = get_post_meta($post_id, '_lf_language', true);
if (empty($post_lang)) {
// Post has no language assigned - run:
// wp langforge set-language {post_id} {lang}
}
// Issue: Translation links broken after migration
// Check 3: Are rewrite rules flushed?
// wp langforge flush
// Or visit Settings > Permalinks and click Save.
// Issue: String translations not appearing
// Check 4: Is the string registered for the correct domain?
// Go to Lang Forge > String Translation and verify the domain filter.—