Plugin Directory


Ignore:
Timestamp:
10/12/2026 10:54:31 PM (2 weeks ago)
Author:
avakodeforge
Message:

Release 1.2.9 (trunk + tag; see readme changelog)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • langforge/trunk/admin/class-admin.php

    r3739707 r3742586  
    16471647        }
    16481648
     1649        // Languages that just went away and still have posts. Counted here, stored
     1650        // at the very end of the method (see "Orphaned translations" below).
     1651        $pending = [];
    16491652        if ($save_languages) {
    16501653            // Tester feedback 2026-04-18: removing a language from the active
    … …  
    16581661            $new_codes = array_keys($active);
    16591662            $removed   = array_diff($old_codes, $new_codes);
    1660             $pending   = [];
    16611663            foreach ($removed as $code) {
    16621664                if ($code === $default) continue;
    … …  
    16751677                }
    16761678            }
    1677             if (!empty($pending)) {
    1678                 set_transient('langforge_removed_lang_pending_' . get_current_user_id(), $pending, HOUR_IN_SECONDS);
    1679             }
    16801679        }
    16811680
    … …  
    17001699        // Flush rewrite rules
    17011700        flush_rewrite_rules();
     1701
     1702        // Orphaned translations: hand the list to the next admin screen LAST,
     1703        // after every purge above. With a persistent object cache (Redis,
     1704        // Memcached) a transient lives in that cache only, and wp_cache_flush
     1705        // (and the cache plugins' "purge all") empties it: written before the
     1706        // purge, the list was gone in the same request and the owner who removed
     1707        // a language was never told about its posts. Without a persistent cache
     1708        // the transient is an options row and nothing changes.
     1709        if (!empty($pending)) {
     1710            set_transient('langforge_removed_lang_pending_' . get_current_user_id(), $pending, HOUR_IN_SECONDS);
     1711        }
    17021712        // phpcs:enable WordPress.Security.NonceVerification.Missing
    17031713    }
    … …  
    17391749        }
    17401750       
    1741         // Build unique strings. For source_lang, use the record with the lowest id
    1742         // (= the first language registered for this string name).
    1743         $unique = [];
    1744         foreach ($all_strings as $string) {
    1745             $name = $string->string_name;
    1746             if (!isset($unique[$name])) {
    1747                 $unique[$name] = [
    1748                     'source_lang' => $string->string_language,
    1749                     'source_id' => (int) $string->id,
    1750                     'domain' => $string->string_domain,
    1751                     'translations' => []
    1752                 ];
    1753             } elseif ((int) $string->id < $unique[$name]['source_id']) {
    1754                 // Earlier record = real source
    1755                 $unique[$name]['source_lang'] = $string->string_language;
    1756                 $unique[$name]['source_id'] = (int) $string->id;
    1757             }
    1758             $unique[$name]['translations'][$string->string_language] = $string->string_value;
    1759         }
    1760        
    1761         return $unique;
     1751        // One entry per name (source language = the earliest record; two domains with one name are not mixed).
     1752        return LANGFORGE_Strings_Screen::group_rows((array) $all_strings);
    17621753    }
    17631754   
    … …  
    18191810        $strings = LANGFORGE_String_Translation::instance()->get_strings($current_domain ?: null, $default_lang);
    18201811        $domain_counts = $this->get_domain_counts();
     1812        $woo_active = class_exists('WooCommerce');
    18211813        ?>
    18221814        <div class="wrap">
    18231815            <?php LANGFORGE_Admin_Tabs::render('langforge-strings'); ?>
    18241816            <?php do_action('langforge/admin_screen_top', 'langforge-strings'); ?>
    1825             <h1><?php esc_html_e('String Translation', 'langforge'); ?><?php Forge_Docs_Link::render('langforge', 'translating-theme-text-string-translation', __('String translation', 'langforge'), __('Translate theme & plugin text strings scanned from your code.', 'langforge')); ?></h1>
    1826            
     1817            <h1><?php esc_html_e('String Translation', 'langforge'); ?><?php Forge_Docs_Link::render('langforge', 'translating-theme-text-string-translation', __('String translation', 'langforge'), LANGFORGE_Strings_Screen::help_text()); ?></h1>
     1818
     1819            <?php
     1820            // How a string gets into the list, and (for a shop) the button that lists the WooCommerce ones without a page being shown.
     1821            LANGFORGE_Strings_Screen::render_intro($woo_active);
     1822            if ($woo_active) {
     1823                LANGFORGE_Strings_Screen::render_find_box();
     1824                wp_add_inline_script('lf-admin', LANGFORGE_Strings_Screen::find_script());
     1825            }
     1826            ?>
     1827
    18271828            <div class="lf-string-filters">
    18281829                <form method="get" action="">
    … …  
    19051906                    </div>
    19061907                <?php else: ?>
    1907                     <p><?php esc_html_e('No strings found. Add strings using the form above or register them in your theme/plugin code.', 'langforge'); ?></p>
     1908                    <p><?php echo esc_html(LANGFORGE_Strings_Screen::empty_text($woo_active)); ?></p>
    19081909                <?php endif; ?>
    19091910            <?php else:
    … …  
    20242025                                        <span class="dashicons dashicons-clipboard"></span>
    20252026                                    </button>
     2027                                    <?php
     2028                                    // The texts of the emails are listed under keys: show the text behind the key.
     2029                                    $name_excerpt = LANGFORGE_Strings_Screen::source_excerpt(
     2030                                        $string_data['domain'],
     2031                                        isset($string_data['translations'][$string_data['source_lang']]) ? $string_data['translations'][$string_data['source_lang']] : ''
     2032                                    );
     2033                                    if ($name_excerpt !== '') {
     2034                                        echo '<br><small class="lf-name-excerpt" style="color:#64748b;">' . esc_html($name_excerpt) . '</small>';
     2035                                    }
     2036                                    LANGFORGE_Strings_Screen::render_other_domains_note(isset($string_data['also_in']) ? $string_data['also_in'] : []);
     2037                                    ?>
    20262038                                </td>
    20272039                                <?php if (!$current_domain): ?>
    … …  
    20522064                                    ?>
    20532065                                    <td>
    2054                                         <textarea name="strings[<?php echo esc_attr($string_name); ?>][<?php echo esc_attr($code); ?>]"
    2055                                                   class="widefat" rows="2" <?php echo $is_source ? 'style="background:#f0f0f0;"' : ''; ?>><?php echo esc_textarea($trans_value); ?></textarea>
    2056                                         <?php if ($is_source): ?>
    2057                                             <small style="color:#666;"><?php esc_html_e('(source)', 'langforge'); ?></small>
    2058                                         <?php endif; ?>
     2066                                        <?php LANGFORGE_Strings_Screen::render_translation_cell($string_name, $code, $string_data['domain'], $is_source, $trans_value); ?>
    20592067                                    </td>
    20602068                                <?php endforeach; ?>
    … …  
    24772485            .lf-domain-badge { background: #f0f0f0; color: #555; padding: 2px 8px; border-radius: 4px; font-size: 14px; }
    24782486            .lf-add-string-form { background: #f9f9f9; padding: 15px; margin: 20px 0; }
     2487            .lf-find-woo { margin: 12px 0; }
     2488            .lf-find-woo .lf-find-woo-status { margin-left: 10px; font-size: 14px; color: #475569; }
     2489            .lf-find-woo .description { margin-top: 6px; max-width: 820px; }
    24792490        <?php } finally { $lf_inline_css = (string) ob_get_clean(); } wp_add_inline_style('lf-admin', $lf_inline_css); ?>
    24802491        <?php
    … …  
    25102521            foreach ($translations as $lang => $value) {
    25112522                $lang = sanitize_text_field($lang);
    2512                 $value = sanitize_textarea_field($value);
     2523                $value = LANGFORGE_Strings_Screen::sanitize_translation($domain, $value);
    25132524
    25142525                if (!empty($value)) {
    … …  
    39924003            });
    39934004        });
    3994         <?php } finally { $lf_inline_js = (string) ob_get_clean(); } wp_add_inline_script('lf-admin', $lf_inline_js); ?>
     4005        <?php } finally { $lf_inline_js = (string) ob_get_clean(); }
     4006        // This notice is printed on every admin screen (admin_notices), but lf-admin.js is queued only on the Lang Forge
     4007        // pages, the post lists/editors and the taxonomy screens (its click handlers are global; see
     4008        // enqueue_admin_scripts). An inline script handed to a handle that is not queued is dropped, so on the
     4009        // Dashboard, Plugins or Media the buttons were drawn and did nothing. Own handle, jQuery only, and only here:
     4010        // the method has returned already when no list is waiting.
     4011        wp_register_script('lf-removed-lang-notice', false, ['jquery'], LANGFORGE_VERSION, true);
     4012        wp_enqueue_script('lf-removed-lang-notice');
     4013        wp_add_inline_script('lf-removed-lang-notice', $lf_inline_js); ?>
    39954014        <?php
    39964015    }
Note: See TracChangeset for help on using the changeset viewer.