Search texts and states, help tooltip, wider field (F4)

materio_sapi: result messages with real plurals; without any exact
match the results are called close (the neighbour search always finds
some). Former help sentence of the base page kept, French corrected.
Messages in SearchMessage, unit tested; French added by update 11002.

materiotheme: placeholder "Describe the material you are looking for",
wider search field, "?" button with a help tooltip and clickable
examples, "Loading…", "End of results"; texts in vuejs/i18n/search.js.
Page title "Base" restored without a search (keys is an array, test its
length).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
This commit is contained in:
2026-11-23 16:44:28 +01:00
co-authored by Claude Opus 5.5
parent f7eb6518e7
commit 1e882d5bda
25 changed files with 372 additions and 48 deletions
@@ -7,6 +7,8 @@
declare(strict_types=1);
use Drupal\Component\Gettext\PoItem;
/**
* Source of the search message (H6) and its French translation.
*
@@ -42,3 +44,52 @@ function materio_sapi_update_11001(): string {
_locale_refresh_translations(['fr'], [$source->lid]);
return 'French translation of the search message added.';
}
/**
* Sources of the search messages of F4 and their French translation.
*
* A plural is stored as singular and plural joined by PoItem::DELIMITER, for
* the source and for the translation.
*/
function materio_sapi_search_messages_strings(): array {
$plural = fn (string $one, string $many): string => $one . PoItem::DELIMITER . $many;
return [
'No results for “@keys”. Try other words or a broader description.'
=> 'Aucun résultat pour « @keys ». Essayez d’autres mots ou une description plus générale.',
$plural('No exact result, @n close result for “@keys”', 'No exact result, @n close results for “@keys”')
=> $plural('Aucun résultat exact, @n résultat proche pour « @keys »', 'Aucun résultat exact, @n résultats proches pour « @keys »'),
'1 exact result for “@keys”'
=> '1 résultat exact pour « @keys »',
$plural('@n exact result out of @total relevant results for “@keys”', '@n exact results out of @total relevant results for “@keys”')
=> $plural('@n résultat exact sur @total résultats pertinents pour « @keys »', '@n résultats exacts sur @total résultats pertinents pour « @keys »'),
// Former text, French corrected ("le champs").
'Please use the search form to search from our @count materials.'
=> 'Utilisez le champ de recherche pour naviguer dans nos @count matériaux référencés.',
];
}
/**
* Adds the French translation of the search messages (F4).
*/
function materio_sapi_update_11002(): string {
if (!\Drupal::moduleHandler()->moduleExists('locale')) {
return 'locale is off: nothing to translate.';
}
$storage = \Drupal::service('locale.storage');
$lids = [];
foreach (materio_sapi_search_messages_strings() as $source_text => $fr) {
$source = $storage->findString(['source' => $source_text, 'context' => '']);
if (!$source) {
$source = $storage->createString(['source' => $source_text, 'context' => ''])->save();
}
$storage->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => $fr,
'customized' => LOCALE_CUSTOMIZED,
])->save();
$lids[] = $source->lid;
}
_locale_refresh_translations(['fr'], $lids);
return 'French translation of the search messages added.';
}