commit 54a3b44c4792c1765ccf93316c3bcdbe92f745a1
parent e9a6e2d19d0b94154173994fcd1407042f77f931
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 19 Oct 2025 16:31:08 +0200
fix remaining i18n issue
Diffstat:
3 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -110,6 +110,5 @@ AGPLv3-or-later, see COPYING for the full license terms.
- actually *TEST* subscriptions (and everything else)
- support in-line QR code with long-polling in payment request!
-- some i18n missing
- LATER: use order expiration from merchant backend (with new v1.1 implementation)
instead of hard-coding 1 day!
diff --git a/src/Entity/TurnstilePriceCategory.php b/src/Entity/TurnstilePriceCategory.php
@@ -144,6 +144,8 @@ class TurnstilePriceCategory extends ConfigEntityBase {
];
$description = $this->t('Pay in @currency with subscription', [
'@currency' => $currencyCode,
+ ], [
+ 'langcode' => 'en', // force English version here!
]);
$description_i18n = $this->buildTranslationMap (
'Pay in @currency with subscription',
diff --git a/src/TalerMerchantApiService.php b/src/TalerMerchantApiService.php
@@ -14,6 +14,7 @@ use Drupal\node\NodeInterface;
use Psr\Log\LoggerInterface;
use Drupal\turnstile\Entity\TurnstilePriceCategory;
use GuzzleHttp\Exception\RequestException;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
@@ -34,6 +35,11 @@ enum TalerErrorCode: int {
class TalerMerchantApiService {
/**
+ * For i18n, gives us the t() function.
+ */
+ use StringTranslationTrait;
+
+ /**
* How long are orders valid by default? 24h.
*/
const ORDER_VALIDITY_SECONDS = 86400;
@@ -175,12 +181,16 @@ class TalerMerchantApiService {
// Per default, we always have "no subscription" as an option.
$result = [];
- // FIXME: implement i18n here!
+ $description = $this->t('No subscription', [], [
+ 'langcode' => 'en', // force English version here!
+ ]);
+ $description_i18n = $this->buildTranslationMap (
+ 'No subscription');
$result['%none%'] = [
'name' => 'none',
'label' => 'No reduction',
- 'description' => 'No subscription',
- 'description_i18n' => [],
+ 'description' => $description,
+ 'description_i18n' => $description_i18n,
];
$config = \Drupal::config('turnstile.settings');
$backend_url = $config->get('payment_backend_url');
@@ -628,4 +638,28 @@ class TalerMerchantApiService {
}
+ /**
+ * Build a translation map for all enabled languages.
+ *
+ * @param string $string
+ * The translatable string.
+ * @param array $args
+ * Placeholder replacements.
+ *
+ * @return array
+ * Map of language codes to translated strings.
+ */
+ private function buildTranslationMap(string $string, array $args = []): array {
+ $translations = [];
+ $language_manager = \Drupal::languageManager();
+
+ foreach ($language_manager->getLanguages() as $langcode => $language) {
+ $translation = $this->t($string, $args, [
+ 'langcode' => $langcode,
+ ]);
+ $translations[$langcode] = (string) $translation;
+ }
+ return $translations;
+ }
+
}
\ No newline at end of file