Changeset 3764005 for langforge/trunk/admin/class-strings-screen.php
- Timestamp:
- 10/25/2026 06:29:16 AM (22 hours ago)
- File:
-
- 1 edited
-
langforge/trunk/admin/class-strings-screen.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
langforge/trunk/admin/class-strings-screen.php
r3742801 r3764005 291 291 } 292 292 293 /** 294 * The glossary check of a save of translated strings (BUG-LANG-GLOSS-02). 295 * 296 * Each saved text of a language other than the source is checked against the source text of its string 297 * (LANGFORGE_Glossary::validate_translation); the terms of a language pair are read once. A string whose source 298 * text was not posted (the source cell of an email text is read-only on the screen) takes it from the table. It 299 * only reports: the texts are saved before this runs. 300 * 301 * @param array<int,array{name:string,domain:string,lang:string,value:string,source:?string}> $saved 302 * @param string $source_lang The language the strings are written in. 303 * @return array<int,array{name:string,domain:string,lang:string,warnings:string}> 304 */ 305 public static function glossary_report(array $saved, $source_lang) { 306 if (!$saved || !class_exists('LANGFORGE_Glossary')) { 307 return []; 308 } 309 $glossary = LANGFORGE_Glossary::instance(); 310 $terms = []; 311 $sources = []; 312 $report = []; 313 foreach ($saved as $row) { 314 $lang = $row['lang']; 315 if (!isset($terms[$lang])) { 316 $terms[$lang] = (array) $glossary->get_terms($source_lang, $lang); 317 } 318 if (!$terms[$lang]) { 319 continue; // no term for this pair: nothing to follow 320 } 321 $source = $row['source']; 322 if ($source === null || $source === '') { 323 $domain = $row['domain']; 324 if (!isset($sources[$domain])) { 325 $sources[$domain] = []; 326 foreach ((array) LANGFORGE_String_Translation::instance()->get_strings($domain, $source_lang) as $source_row) { 327 $sources[$domain][$source_row->string_name] = (string) $source_row->string_value; 328 } 329 } 330 $source = $sources[$domain][$row['name']] ?? ''; 331 } 332 if ($source === '') { 333 continue; 334 } 335 $warnings = $glossary->validate_translation($source, $row['value'], $source_lang, $lang, $terms[$lang]); 336 if ($warnings) { 337 $report[] = ['name' => $row['name'], 'domain' => $row['domain'], 'lang' => $lang, 'warnings' => $warnings]; 338 } 339 } 340 return $report; 341 } 342 343 /** The notice after a save: which saved translations do not follow the glossary, and which terms. Nothing when none. */ 344 public static function render_glossary_report(array $report) { 345 if (!$report) { 346 return; 347 } 348 echo '<div class="notice notice-warning"><p><strong>' . esc_html__('Glossary: saved, but these translations do not follow the glossary.', 'langforge') . '</strong></p><ul style="list-style:disc;margin-left:18px;">'; 349 foreach ($report as $item) { 350 echo '<li><strong>' . esc_html($item['name']) . '</strong> (' . esc_html(strtoupper($item['lang'])) . '): ' . esc_html(implode(' ', $item['warnings'])) . '</li>'; 351 } 352 echo '</ul></div>'; 353 } 354 293 355 /** The note under a name that other domains use too. */ 294 356 public static function render_other_domains_note(array $domains) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)