Files
materio-d9/web/modules/custom/materio_sapi/materio_sapi.install
T
bachirandClaude Opus 5.5 1e882d5bda 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
2026-11-23 16:44:28 +01:00

96 lines
3.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 »'),
// 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.';
}