Files
materio-d9/web/modules/custom/materio_sapi/materio_sapi.install
T
bachirandClaude Opus 5.5 91d03b44ce Search: autocomplete terms add up as labels, all their records exact (Q7)
A chosen suggestion becomes a removable label in the field; the search
starts with Enter or the button, so several terms and free text combine.
The request sends the whole phrase (titles, model) and the term IDs.
Terms are ANDed in the same filter as the countries of Q6; every record
of the chosen terms is exact, ordered by the other words then by the
model, then close results from the whole catalogue. The message names
what makes a result exact (terms, countries as typed). Wider field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 11:34:25 +01:00

110 lines
4.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* @file
* Install, update and uninstall functions for materio_sapi.
*/
declare(strict_types=1);
use Drupal\Component\Gettext\PoItem;
/**
* Source of the search message (H6) and its French translation.
*
* Interface translations live in the database, not in the repository: the
* update brings the French text to every site.
*/
function materio_sapi_search_infos_strings(): array {
return [
'source' => '@exactmatchcount exact result(s) out of @count relevant result(s) for “@keys”',
'fr' => '@exactmatchcount résultat(s) exact(s) sur @count résultat(s) pertinent(s) pour « @keys »',
];
}
/**
* Adds the French translation of the new search message (H6).
*/
function materio_sapi_update_11001(): string {
if (!\Drupal::moduleHandler()->moduleExists('locale')) {
return 'locale is off: nothing to translate.';
}
$strings = materio_sapi_search_infos_strings();
$storage = \Drupal::service('locale.storage');
$source = $storage->findString(['source' => $strings['source'], 'context' => '']);
if (!$source) {
$source = $storage->createString(['source' => $strings['source'], 'context' => ''])->save();
}
$storage->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => $strings['fr'],
'customized' => LOCALE_CUSTOMIZED,
])->save();
_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 »'),
// What makes a result exact, named (Q6, Q7).
$plural('No exact result for @filters, @n close result for “@keys”', 'No exact result for @filters, @n close results for “@keys”')
=> $plural('Aucun résultat exact pour @filters, @n résultat proche pour « @keys »', 'Aucun résultat exact pour @filters, @n résultats proches pour « @keys »'),
'1 exact result for @filters: “@keys”'
=> '1 résultat exact pour @filters : « @keys »',
$plural('@n exact result for @filters, out of @total relevant results for “@keys”', '@n exact results for @filters, out of @total relevant results for “@keys”')
=> $plural('@n résultat exact pour @filters, sur @total résultats pertinents pour « @keys »', '@n résultats exacts pour @filters, 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.';
}
/**
* Adds the French translation of the messages naming the filters (Q6, Q7).
*/
function materio_sapi_update_11003(): string {
return materio_sapi_update_11002();
}