From 61ff193dc6f8560f79563e5f92a41c3dffb5efbd Mon Sep 17 00:00:00 2001 From: Gauthier Eholoum Date: Thu, 3 Dec 2026 00:33:11 +0000 Subject: [PATCH 1/2] feat: add a searchable glossary in French and English --- CONTRIBUTING.md | 8 + astro.config.mjs | 3 +- data/glossary/actors.json | 167 ++++++++++++ data/glossary/methods.json | 167 ++++++++++++ data/glossary/money.json | 209 +++++++++++++++ data/glossary/rules.json | 199 ++++++++++++++ data/glossary/technical.json | 247 ++++++++++++++++++ docs/architecture.md | 9 + src/components/glossary/GlossaryIcon.astro | 23 ++ src/components/glossary/GlossaryIndex.astro | 87 ++++++ src/components/glossary/GlossaryPage.astro | 124 +++++++++ .../glossary/GlossaryTermCard.astro | 73 ++++++ src/i18n/glossary-en.ts | 17 ++ src/i18n/glossary-fr.ts | 17 ++ src/i18n/glossary-types.ts | 17 ++ src/i18n/translate.ts | 9 + src/i18n/ui-en.ts | 1 + src/i18n/ui-fr.ts | 1 + src/lib/check-dataset.ts | 3 + src/lib/check-glossary.ts | 26 ++ src/lib/data-paths.ts | 1 + src/lib/dataset-types.ts | 9 + src/lib/glossary-anchor.ts | 4 + src/lib/glossary-entries.ts | 20 ++ src/lib/glossary-look.ts | 58 ++++ src/lib/glossary-search.ts | 82 ++++++ src/lib/glossary-types.ts | 15 ++ src/lib/glossary-view.ts | 117 +++++++++ src/lib/live-pages.ts | 2 +- src/lib/load-dataset.ts | 22 +- src/lib/share-cards.ts | 9 +- src/lib/site-data.ts | 1 + src/lib/site-types.ts | 3 + src/lib/sitemap-lastmod.ts | 14 +- src/lib/structured-data-types.ts | 9 + src/lib/structured-data.ts | 22 +- src/pages/[locale]/glossary.astro | 12 + src/pages/llms.txt.ts | 1 + src/schema/constants.ts | 43 +++ src/schema/glossary.ts | 43 +++ tests/fixtures/records.ts | 1 + tests/glossary.test.ts | 122 +++++++++ tests/live-pages.test.ts | 2 + tests/share-cards.test.ts | 2 +- 44 files changed, 2013 insertions(+), 8 deletions(-) create mode 100644 data/glossary/actors.json create mode 100644 data/glossary/methods.json create mode 100644 data/glossary/money.json create mode 100644 data/glossary/rules.json create mode 100644 data/glossary/technical.json create mode 100644 src/components/glossary/GlossaryIcon.astro create mode 100644 src/components/glossary/GlossaryIndex.astro create mode 100644 src/components/glossary/GlossaryPage.astro create mode 100644 src/components/glossary/GlossaryTermCard.astro create mode 100644 src/i18n/glossary-en.ts create mode 100644 src/i18n/glossary-fr.ts create mode 100644 src/i18n/glossary-types.ts create mode 100644 src/lib/check-glossary.ts create mode 100644 src/lib/glossary-anchor.ts create mode 100644 src/lib/glossary-entries.ts create mode 100644 src/lib/glossary-look.ts create mode 100644 src/lib/glossary-search.ts create mode 100644 src/lib/glossary-types.ts create mode 100644 src/lib/glossary-view.ts create mode 100644 src/pages/[locale]/glossary.astro create mode 100644 src/schema/glossary.ts create mode 100644 tests/glossary.test.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index feb5c6f..c6f07da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,6 +67,14 @@ Always give the exact URL and the date you looked at it. An archived copy press kit or official social media page, with the exact URL and date, never from a third-party logo site. Owners can have it removed at any time. +## Glossary terms + +Edit the section's file in [`data/glossary`](data/glossary), or add a file for +a new section. A term needs an `id`, an `icon` (or a provider `family`), an +English and a French text, and the date in `updated_at`. Write one or two plain +sentences, no jargon. Add `sources` when you state a fact about an institution +or a standard, and put other spellings people search for in `keywords`. + ## Experience reviews A review is an opinion, so it lives apart from the facts. Reviews are not shown diff --git a/astro.config.mjs b/astro.config.mjs index b07bd4b..4a7c442 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -16,7 +16,8 @@ const site = 'https://paymap.africa'; const isLanguagePicker = (page) => page === `${site}/`; /** Dates come from the records, never from the build time: a page without a record date has no lastmod. */ -const lastmods = lastmodByUrl(site, ['en', 'fr'], loadSite(currentDataRoot()).published); +const { published, glossary } = loadSite(currentDataRoot()); +const lastmods = lastmodByUrl(site, ['en', 'fr'], published, glossary); export default defineConfig({ site, diff --git a/data/glossary/actors.json b/data/glossary/actors.json new file mode 100644 index 0000000..699239d --- /dev/null +++ b/data/glossary/actors.json @@ -0,0 +1,167 @@ +{ + "id": "actors", + "order": 3, + "tone": "actors", + "name": { + "en": "Who does what", + "fr": "Les acteurs" + }, + "terms": [ + { + "id": "aggregator", + "family": "aggregator", + "en": { + "name": "Aggregator", + "definition": "A service that brings several payment methods together behind one account and one integration.", + "example": "accepting several mobile money brands and cards without signing with each operator." + }, + "fr": { + "name": "Agrégateur", + "definition": "Un service qui réunit plusieurs moyens de paiement derrière un seul compte et une seule intégration.", + "example": "accepter plusieurs mobile money et la carte bancaire sans signer avec chaque opérateur." + }, + "keywords": [ + "psp", + "gateway", + "passerelle" + ], + "updated_at": "2026-12-03" + }, + { + "id": "operator", + "family": "operator_api", + "en": { + "name": "Operator", + "definition": "On Paymap, an operator that runs a mobile money service and lets businesses connect to it directly.", + "example": "collecting through the interface Orange Money provides for its own network." + }, + "fr": { + "name": "Opérateur", + "definition": "Sur Paymap, l’opérateur qui gère un service de mobile money et propose aux entreprises de s’y connecter directement.", + "example": "encaisser avec l’interface fournie par Orange Money pour son propre réseau." + }, + "keywords": [ + "telecom" + ], + "updated_at": "2026-12-03" + }, + { + "id": "wallet", + "family": "wallet", + "en": { + "name": "Wallet", + "definition": "An app that holds money to pay or be paid.", + "example": "a customer pays a shop from the balance of their app." + }, + "fr": { + "name": "Portefeuille", + "alias": "wallet", + "definition": "Une application dans laquelle on garde de l’argent pour payer ou en recevoir.", + "example": "un client paie un commerçant depuis le solde de son application." + }, + "updated_at": "2026-12-03" + }, + { + "id": "orchestrator", + "family": "orchestrator", + "en": { + "name": "Orchestrator", + "definition": "A service that routes each payment to one of several providers, and can switch to another if it fails.", + "example": "if the first provider is unavailable, the payment goes through the second." + }, + "fr": { + "name": "Orchestrateur", + "definition": "Un service qui dirige chaque paiement vers l’un de plusieurs prestataires, et peut basculer vers un autre en cas d’échec.", + "example": "si le premier prestataire est indisponible, le paiement passe par le second." + }, + "keywords": [ + "routage", + "routing" + ], + "updated_at": "2026-12-03" + }, + { + "id": "merchant-of-record", + "family": "merchant_of_record", + "en": { + "name": "Merchant of record", + "alias": "MoR", + "definition": "A company that sells to the customer in your place: it appears as the seller, collects, handles sales taxes, then pays you your share.", + "example": "selling software abroad without declaring each country’s taxes yourself." + }, + "fr": { + "name": "Merchant of record", + "alias": "vendeur officiel", + "definition": "Une société qui vend au client à votre place : elle apparaît comme le vendeur, encaisse, gère les taxes de la vente, puis vous reverse votre part.", + "example": "vendre un logiciel à l’étranger sans déclarer soi-même les taxes de chaque pays." + }, + "keywords": [ + "mor" + ], + "updated_at": "2026-12-03" + }, + { + "id": "acquirer", + "family": "acquirer", + "en": { + "name": "Acquiring bank", + "alias": "acquirer", + "definition": "The merchant’s bank, or its card processor, which accepts card payments on the merchant’s behalf.", + "example": "a bank installs a card terminal in a shop." + }, + "fr": { + "name": "Banque acquéreuse", + "alias": "acquéreur", + "definition": "La banque du marchand, ou son processeur de cartes, qui accepte les paiements par carte en son nom.", + "example": "une banque installe un terminal de paiement dans une boutique." + }, + "keywords": [ + "tpe", + "pos", + "terminal" + ], + "updated_at": "2026-12-03" + }, + { + "id": "switch", + "family": "switch", + "en": { + "name": "Interbank switch", + "definition": "A network that passes payments between banks and other payment institutions.", + "example": "a card from one bank works in another bank’s machine." + }, + "fr": { + "name": "Switch interbancaire", + "definition": "Un réseau qui fait passer les paiements entre les banques et les autres établissements de paiement.", + "example": "la carte d’une banque fonctionne dans le distributeur d’une autre." + }, + "keywords": [ + "gimac", + "gim", + "interoperability", + "interopérabilité" + ], + "updated_at": "2026-12-03" + }, + { + "id": "merchant", + "icon": "shop", + "en": { + "name": "Merchant", + "definition": "The business or person who sells and receives the payment, and opens an account with a provider.", + "example": "an online shop, a school, a ticket office." + }, + "fr": { + "name": "Marchand", + "alias": "commerçant", + "definition": "L’entreprise ou la personne qui vend et reçoit le paiement, et qui ouvre un compte chez un prestataire.", + "example": "une boutique en ligne, une école, une billetterie." + }, + "keywords": [ + "vendeur", + "seller" + ], + "updated_at": "2026-12-03" + } + ] +} diff --git a/data/glossary/methods.json b/data/glossary/methods.json new file mode 100644 index 0000000..28155c9 --- /dev/null +++ b/data/glossary/methods.json @@ -0,0 +1,167 @@ +{ + "id": "methods", + "order": 2, + "tone": "methods", + "name": { + "en": "Payment methods", + "fr": "Les moyens de paiement" + }, + "terms": [ + { + "id": "mobile-money", + "icon": "phone", + "en": { + "name": "Mobile money", + "definition": "Money held on an account tied to a phone number. The customer approves the payment on their phone, often with a secret code.", + "example": "paying for a purchase with MTN MoMo, Moov Money or Orange Money." + }, + "fr": { + "name": "Mobile money", + "alias": "argent mobile", + "definition": "De l’argent gardé sur un compte lié à un numéro de téléphone. Le client approuve le paiement sur son téléphone, souvent avec un code secret.", + "example": "régler un achat avec MTN MoMo, Moov Money ou Orange Money." + }, + "keywords": [ + "momo", + "flooz", + "mixx", + "wave", + "tmoney" + ], + "updated_at": "2026-12-03" + }, + { + "id": "card", + "icon": "card", + "en": { + "name": "Local or international card", + "definition": "A card issued in the merchant’s country is called local, one issued elsewhere international. Some providers add a regional rate for cards of the same monetary union. The fee often changes with the origin.", + "example": "the same purchase costs the merchant more with a foreign Visa card." + }, + "fr": { + "name": "Carte locale ou internationale", + "definition": "Une carte émise dans le pays du marchand est dite locale, une carte émise ailleurs internationale. Certains prestataires ajoutent un tarif régional pour les cartes d’une même union monétaire. Les frais changent souvent selon l’origine.", + "example": "le même achat coûte plus cher au marchand avec une carte Visa étrangère." + }, + "keywords": [ + "visa", + "mastercard", + "credit", + "debit", + "bancaire", + "régionale", + "regional" + ], + "updated_at": "2026-12-03" + }, + { + "id": "bank-transfer", + "icon": "to-bank", + "en": { + "name": "Bank transfer", + "definition": "The customer sends money from their bank account to an account number given at the time of payment.", + "example": "a company pays an invoice from its bank." + }, + "fr": { + "name": "Virement bancaire", + "alias": "bank transfer", + "definition": "Le client envoie de l’argent depuis son compte bancaire vers un numéro de compte indiqué au moment de payer.", + "example": "une entreprise règle une facture depuis sa banque." + }, + "keywords": [ + "iban", + "rib" + ], + "updated_at": "2026-12-03" + }, + { + "id": "direct-debit", + "icon": "calendar", + "en": { + "name": "Direct debit", + "definition": "The customer authorises the merchant once to take payments from their account.", + "example": "a subscription taken every month without a new approval." + }, + "fr": { + "name": "Prélèvement", + "alias": "direct debit", + "definition": "Le client autorise une fois le marchand à prélever des paiements sur son compte.", + "example": "un abonnement prélevé chaque mois sans nouvelle validation." + }, + "keywords": [ + "abonnement", + "recurring", + "récurrent", + "mandat" + ], + "updated_at": "2026-12-03" + }, + { + "id": "virtual-account", + "icon": "hash", + "en": { + "name": "Virtual account", + "definition": "A bank account number created for one customer or one payment, so the merchant knows who paid.", + "example": "each order shows its own account number." + }, + "fr": { + "name": "Compte virtuel", + "alias": "virtual account", + "definition": "Un numéro de compte bancaire créé pour un client ou un paiement, pour que le marchand sache qui a payé.", + "example": "chaque commande affiche son propre numéro de compte." + }, + "updated_at": "2026-12-03" + }, + { + "id": "ussd", + "icon": "phone", + "en": { + "name": "USSD", + "alias": "short code", + "definition": "A menu opened by dialling a short code starting with * and ending with #, with no internet and no smartphone.", + "example": "dialling a code to approve a payment from a basic phone." + }, + "fr": { + "name": "USSD", + "alias": "code court", + "definition": "Un menu ouvert en composant un code court qui commence par * et finit par #, sans internet ni smartphone.", + "example": "composer un code pour approuver un paiement depuis un téléphone simple." + }, + "updated_at": "2026-12-03" + }, + { + "id": "qr-code", + "icon": "qr", + "en": { + "name": "QR code", + "definition": "A square image the customer scans with their app to pay without typing a number.", + "example": "a customer scans the code shown at a shop counter." + }, + "fr": { + "name": "QR code", + "definition": "Une image carrée que le client scanne avec son application pour payer sans saisir de numéro.", + "example": "un client scanne le code affiché au comptoir d’une boutique." + }, + "keywords": [ + "scan" + ], + "updated_at": "2026-12-03" + }, + { + "id": "payment-link", + "icon": "link", + "en": { + "name": "Payment link", + "definition": "A web address to share that opens a page ready to be paid, with no website needed.", + "example": "a seller sends the link on WhatsApp." + }, + "fr": { + "name": "Lien de paiement", + "alias": "payment link", + "definition": "Une adresse web à partager qui ouvre une page prête à payer, sans avoir de site.", + "example": "une vendeuse envoie le lien sur WhatsApp." + }, + "updated_at": "2026-12-03" + } + ] +} diff --git a/data/glossary/money.json b/data/glossary/money.json new file mode 100644 index 0000000..ee108f1 --- /dev/null +++ b/data/glossary/money.json @@ -0,0 +1,209 @@ +{ + "id": "money", + "order": 1, + "tone": "money", + "name": { + "en": "The money", + "fr": "L’argent" + }, + "terms": [ + { + "id": "collect", + "icon": "download", + "en": { + "name": "Collect", + "alias": "pay-in", + "definition": "Receive a payment from a customer. Some providers say “cash-in”, a word that also means depositing cash with an agent.", + "example": "a spectator buys a ticket online with mobile money." + }, + "fr": { + "name": "Encaisser", + "alias": "pay-in", + "definition": "Recevoir le paiement d’un client. Certains prestataires disent « cash-in », un mot qui désigne aussi le dépôt d’espèces chez un agent.", + "example": "un spectateur achète son billet en ligne avec son mobile money." + }, + "keywords": [ + "cash-in", + "cashin", + "payin", + "collection", + "collecte", + "encaissement" + ], + "updated_at": "2026-12-03" + }, + { + "id": "payout", + "icon": "upload", + "en": { + "name": "Send", + "alias": "payout, disbursement", + "definition": "Move money from your merchant account to someone else. Some providers say “cash-out”, a word that also means withdrawing cash from an agent.", + "example": "paying the salaries of 40 agents on their mobile money." + }, + "fr": { + "name": "Envoyer", + "alias": "payout, décaissement", + "definition": "Faire partir de l’argent de votre compte marchand vers une autre personne. Certains prestataires disent « cash-out », un mot qui désigne aussi le retrait d’espèces chez un agent.", + "example": "payer les salaires de 40 agents sur leur mobile money." + }, + "keywords": [ + "cash-out", + "cashout", + "transfer", + "transfert", + "pay-out", + "envoi" + ], + "updated_at": "2026-12-03" + }, + { + "id": "bulk-payout", + "icon": "stack", + "en": { + "name": "Bulk payout", + "alias": "mass payment", + "definition": "Send money to many recipients in one operation, usually from a file or a single request.", + "example": "paying 200 delivery riders at the end of the week." + }, + "fr": { + "name": "Envoi en masse", + "alias": "bulk payout", + "definition": "Envoyer de l’argent à de nombreux bénéficiaires en une seule opération, le plus souvent à partir d’un fichier ou d’une seule demande.", + "example": "payer 200 livreurs en fin de semaine." + }, + "keywords": [ + "mass payout", + "paiement de masse" + ], + "updated_at": "2026-12-03" + }, + { + "id": "settlement", + "icon": "to-bank", + "en": { + "name": "Settlement", + "definition": "The collected money moving from the provider to you. It can be automatic or on request, and take from a few minutes to several days.", + "example": "Monday’s sales reach your bank account on Thursday." + }, + "fr": { + "name": "Reversement", + "alias": "settlement", + "definition": "Le passage de l’argent encaissé par le prestataire jusqu’à vous. Il peut être automatique ou à votre demande, et prendre de quelques minutes à plusieurs jours.", + "example": "vos ventes du lundi arrivent sur votre compte bancaire le jeudi." + }, + "keywords": [ + "règlement", + "versement" + ], + "updated_at": "2026-12-03" + }, + { + "id": "withdrawal", + "icon": "cash", + "en": { + "name": "Withdrawal", + "definition": "A settlement you ask for yourself, from your balance with the provider.", + "example": "you move your balance to your own mobile money number." + }, + "fr": { + "name": "Retrait", + "alias": "withdrawal", + "definition": "Le reversement que vous demandez vous-même, depuis votre solde chez le prestataire.", + "example": "vous transférez votre solde vers votre propre numéro mobile money." + }, + "keywords": [ + "solde", + "balance" + ], + "updated_at": "2026-12-03" + }, + { + "id": "refund", + "icon": "undo", + "en": { + "name": "Refund", + "definition": "Give a customer back all or part of what they paid.", + "example": "a concert is cancelled, the tickets are refunded." + }, + "fr": { + "name": "Remboursement", + "alias": "refund", + "definition": "Rendre à un client tout ou partie de ce qu’il a payé.", + "example": "un concert est annulé, les billets sont remboursés." + }, + "updated_at": "2026-12-03" + }, + { + "id": "chargeback", + "icon": "dispute", + "en": { + "name": "Chargeback", + "alias": "dispute", + "definition": "A payment the customer contests with their bank. If the bank agrees, the amount is taken back from the merchant.", + "example": "a customer does not recognise a card payment on their statement." + }, + "fr": { + "name": "Contestation de paiement", + "alias": "chargeback, litige", + "definition": "Un paiement que le client conteste auprès de sa banque. Si la banque lui donne raison, le montant est repris au marchand.", + "example": "un client ne reconnaît pas un paiement par carte sur son relevé." + }, + "keywords": [ + "dispute", + "opposition", + "impayé", + "rétrofacturation" + ], + "updated_at": "2026-12-03" + }, + { + "id": "fee", + "icon": "percent", + "en": { + "name": "Fee", + "alias": "commission", + "definition": "What a provider takes on an operation: a percentage, a fixed amount, or both. Check who pays it, you or the customer, and whether VAT is included.", + "example": "a 2% fee on a 10,000 F sale is 200 F." + }, + "fr": { + "name": "Frais", + "alias": "commission", + "definition": "Ce qu’un prestataire prélève sur une opération : un pourcentage, un montant fixe, ou les deux. Vérifiez qui les paie, vous ou le client, et si la TVA est incluse.", + "example": "2 % de frais sur une vente de 10 000 F font 200 F." + }, + "keywords": [ + "tarif", + "price", + "pricing", + "rate", + "taux", + "tva", + "vat", + "ht", + "ttc" + ], + "updated_at": "2026-12-03" + }, + { + "id": "security-deposit", + "icon": "lock", + "en": { + "name": "Security deposit", + "definition": "Money some providers ask you to leave with them to open or keep an account, to cover possible losses.", + "example": "a deposit paid before the first sale, returned when the account closes." + }, + "fr": { + "name": "Dépôt de garantie", + "alias": "caution", + "definition": "La somme que certains prestataires demandent de laisser chez eux pour ouvrir ou garder un compte, afin de couvrir d’éventuelles pertes.", + "example": "un dépôt versé avant la première vente, rendu à la fermeture du compte." + }, + "keywords": [ + "reserve", + "réserve" + ], + "updated_at": "2026-12-03" + } + ] +} diff --git a/data/glossary/rules.json b/data/glossary/rules.json new file mode 100644 index 0000000..f867b09 --- /dev/null +++ b/data/glossary/rules.json @@ -0,0 +1,199 @@ +{ + "id": "rules", + "order": 4, + "tone": "rules", + "name": { + "en": "Rules and licences", + "fr": "Les règles et les agréments" + }, + "terms": [ + { + "id": "licence", + "icon": "seal", + "en": { + "name": "Licence", + "alias": "authorisation", + "definition": "The permission a regulator gives to a company to offer payment services in a country or a zone. Paymap shows the ones found in an official register, with the date.", + "example": "a payment institution licence number listed by a central bank." + }, + "fr": { + "name": "Agrément", + "alias": "licence", + "definition": "L’autorisation qu’un régulateur donne à une société pour proposer des services de paiement dans un pays ou une zone. Paymap affiche ceux trouvés dans un registre officiel, avec la date.", + "example": "un numéro d’agrément publié par une banque centrale." + }, + "keywords": [ + "license", + "regulator", + "régulateur", + "autorisation" + ], + "updated_at": "2026-12-03" + }, + { + "id": "payment-institution", + "icon": "bank", + "en": { + "name": "Payment institution", + "alias": "PI", + "definition": "A company a regulator has authorised to provide payment services. The conditions depend on the zone." + }, + "fr": { + "name": "Établissement de paiement", + "alias": "EP", + "definition": "Une société autorisée par un régulateur à fournir des services de paiement. Les conditions de l’autorisation dépendent de la zone." + }, + "keywords": [ + "agréé", + "licence" + ], + "updated_at": "2026-12-03" + }, + { + "id": "e-money-institution", + "icon": "coins", + "en": { + "name": "E-money institution", + "alias": "EMI", + "definition": "A company a regulator has authorised to issue electronic money, the money held in a mobile wallet. The conditions depend on the zone." + }, + "fr": { + "name": "Établissement de monnaie électronique", + "alias": "EME", + "definition": "Une société autorisée par un régulateur à émettre de la monnaie électronique, celle gardée dans un portefeuille mobile. Les conditions dépendent de la zone." + }, + "keywords": [ + "emoney" + ], + "updated_at": "2026-12-03" + }, + { + "id": "bceao", + "icon": "shield", + "en": { + "name": "BCEAO", + "alias": "Central Bank of West African States", + "definition": "The central bank shared by the eight countries of the West African Monetary Union: Benin, Burkina Faso, Côte d’Ivoire, Guinea-Bissau, Mali, Niger, Senegal and Togo. It publishes lists of licensed e-money and payment institutions." + }, + "fr": { + "name": "BCEAO", + "alias": "Banque Centrale des États de l’Afrique de l’Ouest", + "definition": "La banque centrale commune aux huit pays de l’Union monétaire ouest-africaine : Bénin, Burkina Faso, Côte d’Ivoire, Guinée-Bissau, Mali, Niger, Sénégal et Togo. Elle publie les listes d’établissements de monnaie électronique et de paiement agréés." + }, + "keywords": [ + "uemoa", + "umoa", + "waemu", + "xof", + "franc cfa" + ], + "sources": [ + { + "url": "https://www.bceao.int/fr/content/presentation-de-la-bceao", + "observed_at": "2026-12-03" + }, + { + "url": "https://www.bceao.int/fr/content/etablissements-de-monnaie-electronique", + "observed_at": "2026-12-03" + }, + { + "url": "https://www.bceao.int/sites/default/files/2026-10/LISTE_DES_ETABLISSEMENTS_DE_PAIEMENT_AGR%C3%89%C3%89S_DANS_L-UMOA_au_31_ao%C3%BBt_2026.pdf", + "observed_at": "2026-10-20" + } + ], + "updated_at": "2026-12-03" + }, + { + "id": "beac", + "icon": "shield", + "en": { + "name": "BEAC", + "alias": "Bank of Central African States", + "definition": "The central bank shared by the six CEMAC countries: Cameroon, Central African Republic, Chad, Congo, Equatorial Guinea and Gabon." + }, + "fr": { + "name": "BEAC", + "alias": "Banque des États de l’Afrique centrale", + "definition": "La banque centrale commune aux six pays de la CEMAC : Cameroun, Centrafrique, Congo, Gabon, Guinée équatoriale et Tchad." + }, + "keywords": [ + "cemac", + "xaf", + "franc cfa" + ], + "sources": [ + { + "url": "https://www.beac.int", + "observed_at": "2026-12-03" + } + ], + "updated_at": "2026-12-03" + }, + { + "id": "not-found-in-register", + "icon": "search", + "en": { + "name": "Not found in the register", + "definition": "We looked for the name in the official list on the date shown and did not find it. This does not say the service has no licence: it may work through a licensed partner or be listed under another name." + }, + "fr": { + "name": "Non trouvé dans le registre", + "definition": "Nous avons cherché le nom dans la liste officielle à la date indiquée, sans le trouver. Cela ne dit pas que le service est sans autorisation : il peut passer par un partenaire agréé ou être inscrit sous un autre nom." + }, + "keywords": [ + "registre", + "register", + "agréé" + ], + "updated_at": "2026-12-03" + }, + { + "id": "kyc", + "icon": "id-card", + "en": { + "name": "KYC", + "alias": "identity check", + "definition": "The checks a provider makes before opening or activating an account.", + "example": "company registration, the manager’s identity document." + }, + "fr": { + "name": "KYC", + "alias": "vérification d’identité", + "definition": "Les contrôles qu’un prestataire fait avant d’ouvrir ou d’activer un compte.", + "example": "registre du commerce, pièce d’identité du gérant." + }, + "keywords": [ + "kyb", + "know your customer", + "documents", + "pièces" + ], + "updated_at": "2026-12-03" + }, + { + "id": "pci-dss", + "icon": "lock", + "en": { + "name": "PCI DSS", + "definition": "The card industry’s security standard for anyone who stores, processes or transmits card data. With a hosted payment page, the customer types the card on the provider’s page, not on your site.", + "example": "a provider shows its compliance certificate." + }, + "fr": { + "name": "PCI DSS", + "definition": "La norme de sécurité du secteur des cartes pour ceux qui stockent, traitent ou transmettent des données de carte. Avec une page de paiement hébergée, le client saisit sa carte chez le prestataire, pas sur votre site.", + "example": "un prestataire présente son attestation de conformité." + }, + "keywords": [ + "security", + "sécurité" + ], + "sources": [ + { + "url": "https://www.pcisecuritystandards.org/standards/pci-dss/", + "observed_at": "2026-12-03" + } + ], + "updated_at": "2026-12-03" + } + ] +} diff --git a/data/glossary/technical.json b/data/glossary/technical.json new file mode 100644 index 0000000..7ffc273 --- /dev/null +++ b/data/glossary/technical.json @@ -0,0 +1,247 @@ +{ + "id": "technical", + "order": 5, + "tone": "technical", + "name": { + "en": "The technical side", + "fr": "La technique" + }, + "terms": [ + { + "id": "api", + "icon": "code", + "en": { + "name": "API", + "definition": "The door through which your software talks to the provider’s.", + "example": "your site requests a payment with no human involved." + }, + "fr": { + "name": "API", + "definition": "La porte par laquelle votre logiciel parle à celui du prestataire.", + "example": "votre site demande un paiement sans intervention humaine." + }, + "keywords": [ + "rest", + "endpoint" + ], + "updated_at": "2026-12-03" + }, + { + "id": "api-key", + "icon": "key", + "en": { + "name": "API key", + "definition": "The secret code that identifies your account with each request. It is never placed in an app or a public page.", + "example": "a test key to try, a live key to collect." + }, + "fr": { + "name": "Clé API", + "alias": "API key", + "definition": "Le code secret qui identifie votre compte à chaque demande. Il ne se met jamais dans une application ou une page publique.", + "example": "une clé de test pour essayer, une clé de production pour encaisser." + }, + "keywords": [ + "secret", + "token", + "jeton", + "live", + "production" + ], + "updated_at": "2026-12-03" + }, + { + "id": "sandbox", + "icon": "flask", + "en": { + "name": "Test mode", + "alias": "sandbox", + "definition": "A trial environment with fake money.", + "example": "checking a successful and a declined payment before opening to the public." + }, + "fr": { + "name": "Mode test", + "alias": "sandbox", + "definition": "Un environnement d’essai avec de l’argent fictif.", + "example": "vérifier un paiement réussi et un paiement refusé avant d’ouvrir au public." + }, + "keywords": [ + "bac à sable" + ], + "updated_at": "2026-12-03" + }, + { + "id": "webhook", + "icon": "bell", + "en": { + "name": "Payment notification", + "alias": "webhook", + "definition": "The message the provider sends to your system when the status of a payment changes.", + "example": "the order becomes “paid” as soon as the message arrives." + }, + "fr": { + "name": "Notification de paiement", + "alias": "webhook", + "definition": "Le message que le prestataire envoie à votre système quand le statut d’un paiement change.", + "example": "la commande passe à « payée » dès la réception du message." + }, + "keywords": [ + "callback", + "ipn" + ], + "updated_at": "2026-12-03" + }, + { + "id": "webhook-signature", + "icon": "pen", + "en": { + "name": "Notification signature", + "alias": "webhook signature", + "definition": "A proof attached to the notification that lets your system check it really comes from the provider.", + "example": "a message with a wrong signature is ignored." + }, + "fr": { + "name": "Signature de notification", + "alias": "signature de webhook", + "definition": "Une preuve jointe à la notification qui permet à votre système de vérifier qu’elle vient bien du prestataire.", + "example": "un message dont la signature est fausse est ignoré." + }, + "keywords": [ + "hmac" + ], + "updated_at": "2026-12-03" + }, + { + "id": "idempotency", + "icon": "repeat", + "en": { + "name": "Idempotency", + "definition": "A request sent twice with the same key counts only once, so a retry does not charge the customer again.", + "example": "the connection drops, your site tries again without paying twice." + }, + "fr": { + "name": "Idempotence", + "alias": "idempotency", + "definition": "Une demande envoyée deux fois avec la même clé ne compte qu’une fois, pour qu’une nouvelle tentative ne débite pas le client à nouveau.", + "example": "la connexion coupe, votre site réessaie sans payer deux fois." + }, + "keywords": [ + "double", + "retry" + ], + "updated_at": "2026-12-03" + }, + { + "id": "sdk", + "icon": "box", + "en": { + "name": "SDK", + "alias": "library", + "definition": "Ready-made code a provider publishes so developers connect faster in their language.", + "example": "a PHP or Flutter package." + }, + "fr": { + "name": "SDK", + "alias": "bibliothèque", + "definition": "Du code prêt à l’emploi que le prestataire publie pour que les développeurs se branchent plus vite dans leur langage.", + "example": "un paquet PHP ou Flutter." + }, + "keywords": [ + "library", + "plugin", + "extension" + ], + "updated_at": "2026-12-03" + }, + { + "id": "hosted-checkout", + "icon": "window", + "en": { + "name": "Hosted payment page", + "alias": "checkout", + "definition": "A payment page run by the provider. The customer pays there, then returns to your site.", + "example": "the “Pay” button opens the provider’s page." + }, + "fr": { + "name": "Page de paiement hébergée", + "alias": "checkout", + "definition": "Une page de paiement gérée par le prestataire. Le client y paie, puis revient sur votre site.", + "example": "le bouton « Payer » ouvre la page du prestataire." + }, + "keywords": [ + "redirect", + "redirection" + ], + "updated_at": "2026-12-03" + }, + { + "id": "3-d-secure", + "icon": "shield", + "en": { + "name": "3-D Secure", + "alias": "3DS", + "definition": "A step that lets the bank that issued the card check the customer during an online payment.", + "example": "the customer confirms with a code or in their bank’s app." + }, + "fr": { + "name": "3-D Secure", + "alias": "3DS", + "definition": "Une étape qui permet à la banque émettrice de la carte de vérifier le client pendant un paiement en ligne.", + "example": "le client confirme avec un code ou dans l’application de sa banque." + }, + "keywords": [ + "otp", + "authentication", + "authentification" + ], + "sources": [ + { + "url": "https://www.emvco.com/emv-technologies/3-d-secure/", + "observed_at": "2026-12-03" + } + ], + "updated_at": "2026-12-03" + }, + { + "id": "reconciliation", + "icon": "check", + "en": { + "name": "Reconciliation", + "definition": "Comparing your orders with what the provider collected and settled, to spot any difference.", + "example": "an order marked paid that does not appear in the provider’s statement." + }, + "fr": { + "name": "Rapprochement", + "alias": "réconciliation", + "definition": "Comparer vos commandes avec ce que le prestataire a encaissé et reversé, pour repérer les écarts.", + "example": "une commande notée payée qui n’apparaît pas dans le relevé du prestataire." + }, + "keywords": [ + "comptabilité", + "accounting" + ], + "updated_at": "2026-12-03" + }, + { + "id": "status-page", + "icon": "pulse", + "en": { + "name": "Status page", + "definition": "A public page where the provider says whether its service works and lists its incidents.", + "example": "checking whether an outage comes from the provider or from your site." + }, + "fr": { + "name": "Page d’état", + "alias": "status page", + "definition": "Une page publique où le prestataire indique si son service fonctionne et liste ses incidents.", + "example": "vérifier si une panne vient du prestataire ou de votre site." + }, + "keywords": [ + "uptime", + "incident", + "panne", + "outage" + ], + "updated_at": "2026-12-03" + } + ] +} diff --git a/docs/architecture.md b/docs/architecture.md index 12abaa4..d130541 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -8,6 +8,7 @@ Status: living document. Settled decisions are in `adr/`. data/ providers/.json one file per provider, every claim sourced reference/ countries, currencies, regulators, payment brands + glossary/ terms of the glossary page, one file per section registers/ official registers, extracted from the source PDF LICENSE CC BY-SA 4.0 src/ @@ -73,6 +74,14 @@ A provider belongs to one or more families: - **onboarding**: individuals allowed, documents, delay, deposit. - **incidents**: dated and sourced outages, breaches, sanctions. +## Glossary + +One file per section in `data/glossary/`, in English and French side by side. +A definition is editorial, but one that states facts about a named +institution or standard gives its `sources`. A term's `id` is its public +anchor: it never changes. Search reads names in both languages, `keywords`, +then definitions. + ## Transparency index Six points a provider can publish: public docs, self-serve test mode, signed diff --git a/src/components/glossary/GlossaryIcon.astro b/src/components/glossary/GlossaryIcon.astro new file mode 100644 index 0000000..bc974cd --- /dev/null +++ b/src/components/glossary/GlossaryIcon.astro @@ -0,0 +1,23 @@ +--- +import { glossaryLook } from '../../lib/glossary-look'; +import type { GlossaryTone } from '../../schema/constants'; +import type { GlossaryTerm } from '../../schema/glossary'; + +/** A term's drawing on its coloured disc. Decorative: the name is always next to it. */ +interface Props { + term: GlossaryTerm; + tone: GlossaryTone; +} + +const { term, tone } = Astro.props; +const look = glossaryLook(term, tone); +--- + + + + diff --git a/src/components/glossary/GlossaryIndex.astro b/src/components/glossary/GlossaryIndex.astro new file mode 100644 index 0000000..b338965 --- /dev/null +++ b/src/components/glossary/GlossaryIndex.astro @@ -0,0 +1,87 @@ +--- +import type { Locale } from '../../i18n/locales'; +import { glossaryStrings } from '../../i18n/translate'; +import type { GlossaryGroup } from '../../schema/glossary'; +import GlossaryIcon from './GlossaryIcon.astro'; + +/** Every term in one look, by section. Folded behind a button on small screens. */ +interface Props { + locale: Locale; + groups: readonly GlossaryGroup[]; +} + +const { locale, groups } = Astro.props; +const t = glossaryStrings(locale); +const total = groups.reduce((sum, group) => sum + group.terms.length, 0); +const counted = (count: number): string => t.count[count === 1 ? 'one' : 'other'].replace('{count}', String(count)); +--- + + + + + + diff --git a/src/components/glossary/GlossaryPage.astro b/src/components/glossary/GlossaryPage.astro new file mode 100644 index 0000000..6d83647 --- /dev/null +++ b/src/components/glossary/GlossaryPage.astro @@ -0,0 +1,124 @@ +--- +import type { Locale } from '../../i18n/locales'; +import { catalogueStrings, glossaryStrings, localePath } from '../../i18n/translate'; +import { sectionAnchor } from '../../lib/glossary-anchor'; +import { glossaryEntries } from '../../lib/glossary-entries'; +import { inlineJson } from '../../lib/inline-json'; +import { currentSite } from '../../lib/site-data'; +import { breadcrumbData, glossaryData } from '../../lib/structured-data'; +import Breadcrumb from '../Breadcrumb.astro'; +import Layout from '../Layout.astro'; +import GlossaryIndex from './GlossaryIndex.astro'; +import GlossaryTermCard from './GlossaryTermCard.astro'; + +/** The words of online payment, by section, with a search that works in the page. */ +interface Props { + locale: Locale; +} + +const { locale } = Astro.props; +const t = glossaryStrings(locale); +const trail = catalogueStrings(locale); +const groups = currentSite().glossary; +const total = groups.reduce((sum, group) => sum + group.terms.length, 0); + +const absolute = (path: string): string => new URL(localePath(locale, path), Astro.site).href; +const url = absolute('/glossary'); +const terms = groups.flatMap((group) => + group.terms.map((term) => ({ name: term[locale].name, aliases: term[locale].alias?.split(', ') ?? [], description: term[locale].definition, url: `${url}#${term.id}` })), +); +const structuredData = [breadcrumbData([{ name: trail.home, url: absolute('/') }, { name: t.heading, url }]), glossaryData(t.heading, url, locale, terms)]; +--- + + +
+ + +
+ {t.eyebrow} +

{t.heading}

+

{t.intro}

+
+ + + + + +
+ { + groups.map((group) => ( +
+

{group.name[locale]}

+
+ {group.terms.map((term, i) => ( + + ))} +
+
+ )) + } + +
+ + diff --git a/src/components/glossary/GlossaryTermCard.astro b/src/components/glossary/GlossaryTermCard.astro new file mode 100644 index 0000000..f84e453 --- /dev/null +++ b/src/components/glossary/GlossaryTermCard.astro @@ -0,0 +1,73 @@ +--- +import type { Locale } from '../../i18n/locales'; +import { glossaryStrings, providerStrings } from '../../i18n/translate'; +import type { GlossaryTone } from '../../schema/constants'; +import type { GlossaryTerm } from '../../schema/glossary'; +import { formatDate } from '../../lib/site-format'; +import GlossaryIcon from './GlossaryIcon.astro'; + +/** One definition. Its id is the anchor the list of terms leads to. */ +interface Props { + locale: Locale; + term: GlossaryTerm; + tone: GlossaryTone; + wide: boolean; +} + +const { locale, term, tone, wide } = Astro.props; +const t = glossaryStrings(locale); +const text = term[locale]; +const heading = `${term.id}-name`; +--- + + + + diff --git a/src/i18n/glossary-en.ts b/src/i18n/glossary-en.ts new file mode 100644 index 0000000..83ba67f --- /dev/null +++ b/src/i18n/glossary-en.ts @@ -0,0 +1,17 @@ +import type { GlossaryStrings } from './glossary-types'; + +export const GLOSSARY_EN: GlossaryStrings = { + title: 'Online payment glossary for Africa · Paymap', + description: 'Collection, settlement, aggregator, webhook, KYC, licence: the words of online payment in Africa, in plain language, with examples.', + eyebrow: 'Method', + heading: 'Glossary', + intro: 'The words of online payment you read on our sheets, in plain language, with examples.', + searchLabel: 'Search for a term', + clear: 'Clear the search', + indexLabel: 'List of terms', + showIndex: (count) => `Show the list of ${count} terms`, + count: { one: '{count} term', other: '{count} terms' }, + forExample: 'For example,', + none: 'No term matches. Try another word.', + source: 'Source', +}; diff --git a/src/i18n/glossary-fr.ts b/src/i18n/glossary-fr.ts new file mode 100644 index 0000000..6e3efdb --- /dev/null +++ b/src/i18n/glossary-fr.ts @@ -0,0 +1,17 @@ +import type { GlossaryStrings } from './glossary-types'; + +export const GLOSSARY_FR: GlossaryStrings = { + title: 'Glossaire du paiement en ligne en Afrique · Paymap', + description: 'Encaissement, reversement, agrégateur, webhook, KYC, agrément : les mots du paiement en ligne en Afrique, expliqués simplement, avec des exemples.', + eyebrow: 'Méthode', + heading: 'Glossaire', + intro: 'Les mots du paiement en ligne que vous lisez sur nos fiches, expliqués simplement, avec des exemples.', + searchLabel: 'Chercher un terme', + clear: 'Effacer la recherche', + indexLabel: 'Liste des termes', + showIndex: (count) => `Voir la liste des ${count} termes`, + count: { one: '{count} terme', other: '{count} termes' }, + forExample: 'Par exemple,', + none: 'Aucun terme ne correspond. Essayez un autre mot.', + source: 'Source', +}; diff --git a/src/i18n/glossary-types.ts b/src/i18n/glossary-types.ts new file mode 100644 index 0000000..58106df --- /dev/null +++ b/src/i18n/glossary-types.ts @@ -0,0 +1,17 @@ +/** Texts of the glossary page around the terms, which live in `data/glossary/`. */ +export interface GlossaryStrings { + readonly title: string; + readonly description: string; + readonly eyebrow: string; + readonly heading: string; + readonly intro: string; + readonly searchLabel: string; + readonly clear: string; + readonly indexLabel: string; + readonly showIndex: (count: number) => string; + /** `{count}` is replaced in the browser too. */ + readonly count: { readonly one: string; readonly other: string }; + readonly forExample: string; + readonly none: string; + readonly source: string; +} diff --git a/src/i18n/translate.ts b/src/i18n/translate.ts index 3ec5963..74affaa 100644 --- a/src/i18n/translate.ts +++ b/src/i18n/translate.ts @@ -2,6 +2,9 @@ import { CATALOGUE_EN } from './catalogue-en'; import { CATALOGUE_FR } from './catalogue-fr'; import type { CatalogueStrings } from './catalogue-types'; import { DATA_FR } from './data-fr'; +import { GLOSSARY_EN } from './glossary-en'; +import { GLOSSARY_FR } from './glossary-fr'; +import type { GlossaryStrings } from './glossary-types'; import { HOME_EN } from './home-en'; import { HOME_FR } from './home-fr'; import type { HomeStrings } from './home-types'; @@ -16,6 +19,7 @@ import type { UiStrings } from './ui-types'; const DICTIONARIES: Record = { en: UI_EN, fr: UI_FR }; const HOME: Record = { en: HOME_EN, fr: HOME_FR }; const CATALOGUE: Record = { en: CATALOGUE_EN, fr: CATALOGUE_FR }; +const GLOSSARY: Record = { en: GLOSSARY_EN, fr: GLOSSARY_FR }; const PROVIDER: Record = { en: PROVIDER_EN, fr: PROVIDER_FR }; /** Interface strings for a locale. */ @@ -33,6 +37,11 @@ export function catalogueStrings(locale: Locale): CatalogueStrings { return CATALOGUE[locale]; } +/** Glossary page strings for a locale. */ +export function glossaryStrings(locale: Locale): GlossaryStrings { + return GLOSSARY[locale]; +} + /** Provider sheet strings for a locale. */ export function providerStrings(locale: Locale): ProviderStrings { return PROVIDER[locale]; diff --git a/src/i18n/ui-en.ts b/src/i18n/ui-en.ts index 53f085b..6b773c0 100644 --- a/src/i18n/ui-en.ts +++ b/src/i18n/ui-en.ts @@ -60,6 +60,7 @@ export const UI_EN: UiStrings = { { label: 'Our method', href: '/method' }, { label: 'Transparency index', href: '/method#transparency-index', highlight: true }, { label: 'Sources and updates', href: '/method#sources' }, + { label: 'Glossary', href: '/glossary' }, ], }, contribute: { diff --git a/src/i18n/ui-fr.ts b/src/i18n/ui-fr.ts index 23cbff1..b1a662d 100644 --- a/src/i18n/ui-fr.ts +++ b/src/i18n/ui-fr.ts @@ -60,6 +60,7 @@ export const UI_FR: UiStrings = { { label: 'Notre méthode', href: '/method' }, { label: 'Indice de transparence', href: '/method#transparency-index', highlight: true }, { label: 'Sources et mises à jour', href: '/method#sources' }, + { label: 'Glossaire', href: '/glossary' }, ], }, contribute: { diff --git a/src/lib/check-dataset.ts b/src/lib/check-dataset.ts index e668974..63f82cb 100644 --- a/src/lib/check-dataset.ts +++ b/src/lib/check-dataset.ts @@ -1,4 +1,5 @@ import type { Provider } from '../schema/provider'; +import { checkGlossary } from './check-glossary'; import { checkLicencesAgainstRegisters } from './check-licences'; import { checkBrandLogos, checkLogos, checkMethodLogos } from './check-logos'; import { checkReferenceData, reporter } from './check-reference-data'; @@ -16,6 +17,8 @@ export function checkDataset(dataset: Dataset): Issue[] { checkBrandLogos(dataset.brandLogos, known, issues); checkMethodLogos(dataset.methodLogos, issues); + checkGlossary(dataset.glossary, (file) => reporter(issues, file)); + for (const { file, provider } of dataset.providers) { const report = reporter(issues, file); diff --git a/src/lib/check-glossary.ts b/src/lib/check-glossary.ts new file mode 100644 index 0000000..76f6dc9 --- /dev/null +++ b/src/lib/check-glossary.ts @@ -0,0 +1,26 @@ +import type { GlossaryFile, Report } from './dataset-types'; +import { sectionAnchor } from './glossary-anchor'; + +/** Section files named after their id, and no anchor or position used twice across the whole glossary. */ +export function checkGlossary(files: readonly GlossaryFile[], reportIn: (file: string) => Report): void { + const anchors = new Set(); + const orders = new Set(); + + for (const { file, group } of files) { + const report = reportIn(file); + + if (!file.endsWith(`/${group.id}.json`)) report('id', `Section id "${group.id}" must match the file name`); + if (orders.has(group.order)) report('order', `Position ${group.order} is already taken`); + + orders.add(group.order); + claimAnchor(anchors, sectionAnchor(group.id), () => report('id', `Duplicate anchor "${sectionAnchor(group.id)}"`)); + + group.terms.forEach((term, i) => claimAnchor(anchors, term.id, () => report(`terms.${i}.id`, `Duplicate anchor "${term.id}"`))); + } +} + +function claimAnchor(anchors: Set, anchor: string, onDuplicate: () => void): void { + if (anchors.has(anchor)) onDuplicate(); + + anchors.add(anchor); +} diff --git a/src/lib/data-paths.ts b/src/lib/data-paths.ts index c4e41fb..dade3e3 100644 --- a/src/lib/data-paths.ts +++ b/src/lib/data-paths.ts @@ -15,4 +15,5 @@ export const BRAND_LOGOS_DIR = 'logos/brands'; /** Logo files of payment methods without brand, relative to `PUBLIC_DIR`. */ export const METHOD_LOGOS_DIR = 'logos/methods'; export const PROVIDERS_DIR = 'data/providers'; +export const GLOSSARY_DIR = 'data/glossary'; export const REGISTERS_DIR = 'data/registers'; diff --git a/src/lib/dataset-types.ts b/src/lib/dataset-types.ts index b187652..eb72213 100644 --- a/src/lib/dataset-types.ts +++ b/src/lib/dataset-types.ts @@ -1,3 +1,4 @@ +import type { GlossaryGroup } from '../schema/glossary'; import type { BrandLogo, Logo, MethodLogo } from '../schema/logo'; import type { Brand, Country, Currency, Regulator } from '../schema/reference'; import type { Register } from '../schema/register'; @@ -14,6 +15,12 @@ export interface RegisterFile { register: Register; } +/** A section of the glossary and the file it was read from. */ +export interface GlossaryFile { + file: string; + group: GlossaryGroup; +} + export interface Dataset { providers: ProviderFile[]; countries: Country[]; @@ -24,6 +31,8 @@ export interface Dataset { logos: Logo[]; brandLogos: BrandLogo[]; methodLogos: MethodLogo[]; + /** Sections of the glossary, in page order. */ + glossary: GlossaryFile[]; } export interface Issue { diff --git a/src/lib/glossary-anchor.ts b/src/lib/glossary-anchor.ts new file mode 100644 index 0000000..9a6bffa --- /dev/null +++ b/src/lib/glossary-anchor.ts @@ -0,0 +1,4 @@ +/** Anchor of a section, apart from the anchors of its terms. */ +export function sectionAnchor(id: string): string { + return `section-${id}`; +} diff --git a/src/lib/glossary-entries.ts b/src/lib/glossary-entries.ts new file mode 100644 index 0000000..ef010b8 --- /dev/null +++ b/src/lib/glossary-entries.ts @@ -0,0 +1,20 @@ +import { LOCALES, type Locale } from '../i18n/locales'; +import type { GlossaryGroup, GlossaryTerm } from '../schema/glossary'; +import { searchable } from './glossary-search'; +import type { GlossaryEntry } from './glossary-types'; + +/** What the page searches in. Names of every language count, so "refund" finds "Remboursement". */ +export function glossaryEntries(groups: readonly GlossaryGroup[], locale: Locale): GlossaryEntry[] { + return groups.flatMap((group) => group.terms.map((term) => entry(term, locale))); +} + +function entry(term: GlossaryTerm, locale: Locale): GlossaryEntry { + const names = LOCALES.flatMap((code) => [term[code].name, term[code].alias ?? '']); + const { definition, example = '' } = term[locale]; + + return { + id: term.id, + names: searchable([...names, ...(term.keywords ?? [])].join(' ')), + body: searchable(`${definition} ${example}`), + }; +} diff --git a/src/lib/glossary-look.ts b/src/lib/glossary-look.ts new file mode 100644 index 0000000..68fd356 --- /dev/null +++ b/src/lib/glossary-look.ts @@ -0,0 +1,58 @@ +import type { GlossaryTerm } from '../schema/glossary'; +import type { GlossaryIcon, GlossaryTone } from '../schema/constants'; +import { FAMILY_LOOK } from './family-look'; +import type { GlossaryLook } from './glossary-types'; + +/** Colours of each section of the glossary. */ +const TONES: Readonly> = { + money: { background: '#e3eed8', foreground: '#2e6b1f' }, + methods: { background: '#fbe7b4', foreground: '#6e4600' }, + actors: { background: '#d5ebe6', foreground: '#0a4a46' }, + rules: { background: '#dae6f8', foreground: '#1d458a' }, + technical: { background: '#e6e2d6', foreground: '#453f33' }, +}; + +/** Drawings on an 18 by 18 grid, stroked in the current colour. */ +const ICONS: Readonly> = { + bank: '', + bell: '', + box: '', + calendar: '', + card: '', + cash: '', + check: '', + code: '', + coins: '', + dispute: '', + download: '', + flask: '', + hash: '', + 'id-card': '', + key: '', + link: '', + lock: '', + pen: '', + percent: '', + phone: '', + pulse: '', + qr: '', + repeat: '', + seal: '', + search: '', + shield: '', + shop: '', + stack: '', + 'to-bank': '', + undo: '', + upload: '', + window: '', +}; + +/** Icon and colours of a term: those of its provider family, or its own icon in the colours of its section. */ +export function glossaryLook(term: Pick, tone: GlossaryTone): GlossaryLook { + if (term.family !== undefined) return FAMILY_LOOK[term.family]; + + if (term.icon === undefined) throw new Error('A glossary term has neither icon nor family'); + + return { ...TONES[tone], icon: ICONS[term.icon] }; +} diff --git a/src/lib/glossary-search.ts b/src/lib/glossary-search.ts new file mode 100644 index 0000000..bb5422f --- /dev/null +++ b/src/lib/glossary-search.ts @@ -0,0 +1,82 @@ +import type { GlossaryEntry } from './glossary-types'; +import { normalise } from './search-match'; + +/** Words of a question that say nothing about the term asked for, in both languages. */ +const IGNORED = new Set( + 'a an and are can do does for how i in is it mean means of on or the to what whats which au aux avec ce c cest comment d dans de des du en est et il j je l la le les ma mes mon pour qu que quel quelle quest quoi s se ses ta un une veut dire signifie'.split(' '), +); + +/** Shortest word a typo is accepted in: below, one letter changes too much. */ +const TYPO_MIN_LENGTH = 5; + +/** + * Ids of the terms a text asks for. Names come first: the definitions are read only when no + * name matches, and typos are accepted only when nothing else does. An empty text keeps every term. + */ +export function searchGlossary(entries: readonly GlossaryEntry[], text: string): string[] { + const words = queryWords(text); + + if (words.length === 0) return entries.map((entry) => entry.id); + + const passes: Array<(entry: GlossaryEntry) => boolean> = [ + (entry) => words.every((word) => startsAny(tokens(entry.names), word)), + (entry) => words.every((word) => startsAny(tokens(`${entry.names} ${entry.body}`), word)), + (entry) => words.every((word) => startsAny(tokens(entry.names), word) || nearAny(tokens(entry.names), word)), + ]; + + for (const pass of passes) { + const found = entries.filter(pass); + + if (found.length > 0) return found.map((entry) => entry.id); + } + + return []; +} + +/** Text as the search reads it: no case, accent or punctuation. */ +export function searchable(text: string): string { + return tokens(normalise(text)).join(' '); +} + +/** The words that carry the question; all of them when the text only holds small words. */ +function queryWords(text: string): string[] { + const words = tokens(normalise(text)); + const telling = words.filter((word) => !IGNORED.has(word)); + + return telling.length > 0 ? telling : words; +} + +function tokens(text: string): string[] { + return text.split(/[^\p{L}\p{N}]+/u).filter(Boolean); +} + +function startsAny(terms: readonly string[], word: string): boolean { + return terms.some((term) => term.startsWith(word)); +} + +function nearAny(terms: readonly string[], word: string): boolean { + return word.length >= TYPO_MIN_LENGTH && terms.some((term) => term.length >= TYPO_MIN_LENGTH && isOneEditAway(term, word)); +} + +/** Whether one added, missing, changed or swapped letter turns one word into the other. */ +function isOneEditAway(a: string, b: string): boolean { + if (Math.abs(a.length - b.length) > 1) return false; + + const start = commonPrefix(a, b); + const restA = a.slice(start); + const restB = b.slice(start); + + if (a.length !== b.length) return restA.slice(1) === restB || restA === restB.slice(1); + + const swapped = restA.length > 1 && restA[0] === restB[1] && restA[1] === restB[0] && restA.slice(2) === restB.slice(2); + + return swapped || restA.slice(1) === restB.slice(1); +} + +function commonPrefix(a: string, b: string): number { + let i = 0; + + while (i < a.length && i < b.length && a[i] === b[i]) i += 1; + + return i; +} diff --git a/src/lib/glossary-types.ts b/src/lib/glossary-types.ts new file mode 100644 index 0000000..9257dfa --- /dev/null +++ b/src/lib/glossary-types.ts @@ -0,0 +1,15 @@ +/** How a term is drawn: its icon on a coloured disc. */ +export interface GlossaryLook { + readonly background: string; + readonly foreground: string; + readonly icon: string; +} + +/** What the search knows of a term. Every text is already normalised. */ +export interface GlossaryEntry { + readonly id: string; + /** Name, other names and keywords. */ + readonly names: string; + /** Definition and example. */ + readonly body: string; +} diff --git a/src/lib/glossary-view.ts b/src/lib/glossary-view.ts new file mode 100644 index 0000000..25cf8b9 --- /dev/null +++ b/src/lib/glossary-view.ts @@ -0,0 +1,117 @@ +import { searchGlossary } from './glossary-search'; +import type { GlossaryEntry } from './glossary-types'; + +/** Address parameter holding the text searched, so a search can be shared. */ +const PARAMETER = 'q'; + +/** The glossary in the browser: search as you type, and the list of terms that folds on small screens. */ +export class GlossaryView { + private readonly entries: GlossaryEntry[]; + private readonly search: HTMLInputElement; + private readonly clear: HTMLButtonElement; + private readonly index: HTMLElement; + private readonly plurals = new Intl.PluralRules(document.documentElement.lang || 'en'); + + constructor(private readonly root: HTMLElement) { + this.entries = JSON.parse(this.find('[data-glossary-entries]').textContent ?? '[]') as GlossaryEntry[]; + this.search = this.find('[data-glossary-search]'); + this.clear = this.find('[data-glossary-clear]'); + this.index = this.find('[data-glossary-index]'); + + this.find('[data-glossary-tools]').hidden = false; + this.search.value = new URLSearchParams(window.location.search).get(PARAMETER) ?? ''; + this.bind(); + this.render(); + this.revealAnchor(); + } + + private find(selector: string): T { + const element = this.root.querySelector(selector); + + if (!element) throw new Error(`Glossary is missing ${selector}`); + + return element; + } + + private bind(): void { + this.search.addEventListener('input', () => this.change()); + this.search.addEventListener('keydown', (event) => { + if (event.key === 'Escape' && this.search.value !== '') { + event.preventDefault(); + this.reset(); + } + }); + this.clear.addEventListener('click', () => this.reset()); + + const toggle = this.find('[data-glossary-toggle]'); + toggle.addEventListener('click', () => { + const open = toggle.getAttribute('aria-expanded') === 'true'; + toggle.setAttribute('aria-expanded', String(!open)); + }); + + window.addEventListener('hashchange', () => this.revealAnchor()); + } + + private render(): void { + const text = this.search.value.trim(); + const found = new Set(searchGlossary(this.entries, text)); + + this.clear.hidden = text === ''; + this.index.hidden = text !== ''; + this.root.querySelectorAll('[data-glossary-group]').forEach((group) => this.renderGroup(group, found)); + this.find('[data-glossary-none]').hidden = found.size > 0; + this.renderCount(found.size); + } + + /** Shows the matching terms. A last one left alone on its row takes the full width. */ + private renderGroup(group: HTMLElement, found: ReadonlySet): void { + const terms = [...group.querySelectorAll('[data-glossary-term]')]; + terms.forEach((term) => (term.hidden = !found.has(term.id))); + + const shown = terms.filter((term) => !term.hidden); + terms.forEach((term) => term.classList.toggle('wide', shown.length % 2 === 1 && term === shown.at(-1))); + group.hidden = shown.length === 0; + } + + private renderCount(count: number): void { + const element = this.find('[data-glossary-count]'); + const template = (this.plurals.select(count) === 'one' ? element.dataset['one'] : element.dataset['other']) ?? ''; + const text = template.replace('{count}', String(count)); + + if (element.textContent !== text) element.textContent = text; + } + + private change(): void { + const url = new URL(window.location.href); + const text = this.search.value.trim(); + + if (text === '') url.searchParams.delete(PARAMETER); + else url.searchParams.set(PARAMETER, text); + + url.hash = ''; + window.history.replaceState(null, '', url); + this.render(); + } + + private reset(): void { + this.search.value = ''; + this.change(); + this.search.focus(); + } + + /** A link to a term the search hides clears the search, then goes to it. */ + private revealAnchor(): void { + const id = window.location.hash.slice(1); + const target = id === '' ? null : document.getElementById(id); + + if (target === null || !this.root.contains(target) || target.closest('[hidden]') === null) return; + + this.search.value = ''; + const url = new URL(window.location.href); + url.searchParams.delete(PARAMETER); + window.history.replaceState(null, '', url); + this.render(); + target.scrollIntoView(); + target.focus({ preventScroll: true }); + } +} diff --git a/src/lib/live-pages.ts b/src/lib/live-pages.ts index ef9d0e8..33294ac 100644 --- a/src/lib/live-pages.ts +++ b/src/lib/live-pages.ts @@ -5,7 +5,7 @@ import { LOCALES } from '../i18n/locales'; * out is shown as "Soon" text instead of a link; adding it here turns every link to * it back on. */ -const LIVE_PATHS: ReadonlySet = new Set(['/', '/providers']); +const LIVE_PATHS: ReadonlySet = new Set(['/', '/providers', '/countries', '/glossary']); /** Pages built from a pattern, matched on the path without locale: one sheet per provider. */ const LIVE_PATTERNS: readonly RegExp[] = [/^\/providers\/[a-z0-9-]+$/]; diff --git a/src/lib/load-dataset.ts b/src/lib/load-dataset.ts index 25c6b19..70a7efe 100644 --- a/src/lib/load-dataset.ts +++ b/src/lib/load-dataset.ts @@ -3,6 +3,7 @@ import { join, relative } from 'node:path'; import type { z } from 'zod'; +import { glossaryGroupSchema } from '../schema/glossary'; import { brandLogosFileSchema, logosFileSchema, methodLogosFileSchema } from '../schema/logo'; import { providerSchema } from '../schema/provider'; import { brandsFileSchema, countriesFileSchema, currenciesFileSchema, regulatorsFileSchema } from '../schema/reference'; @@ -13,6 +14,7 @@ import { BRANDS_FILE, COUNTRIES_FILE, CURRENCIES_FILE, + GLOSSARY_DIR, LOGOS_DIR, LOGOS_FILE, METHOD_LOGOS_DIR, @@ -22,7 +24,7 @@ import { REGISTERS_DIR, REGULATORS_FILE, } from './data-paths'; -import type { LoadResult, ProviderFile, RegisterFile } from './dataset-types'; +import type { GlossaryFile, LoadResult, ProviderFile, RegisterFile } from './dataset-types'; import type { LoadContext, LogoList } from './load-types'; /** Reads and parses every data file. Unreadable files and schema errors are returned, never thrown. */ @@ -38,9 +40,10 @@ export function loadDataset(root: string): LoadResult { const logos = loadLogos(ctx, { file: LOGOS_FILE, dir: LOGOS_DIR, schema: logosFileSchema }); const brandLogos = loadLogos(ctx, { file: BRAND_LOGOS_FILE, dir: BRAND_LOGOS_DIR, schema: brandLogosFileSchema }); const methodLogos = loadLogos(ctx, { file: METHOD_LOGOS_FILE, dir: METHOD_LOGOS_DIR, schema: methodLogosFileSchema }); + const glossary = loadGlossary(ctx); return { - dataset: { providers, countries, currencies, brands, regulators, registers, logos, brandLogos, methodLogos }, + dataset: { providers, countries, currencies, brands, regulators, registers, logos, brandLogos, methodLogos, glossary }, issues: ctx.issues, }; } @@ -106,6 +109,21 @@ function loadRegisters(ctx: LoadContext): RegisterFile[] { return registers; } +/** Sections of the glossary, in the order they are shown. */ +function loadGlossary(ctx: LoadContext): GlossaryFile[] { + const files: GlossaryFile[] = []; + + for (const file of listJson(ctx, GLOSSARY_DIR, false)) { + const group = parseFile(ctx, file, glossaryGroupSchema); + + if (group !== undefined) { + files.push({ file, group }); + } + } + + return files.sort((a, b) => a.group.order - b.group.order); +} + /** Logo entries of one list, each pointing to a file that exists under `public/`. */ function loadLogos(ctx: LoadContext, list: LogoList): T[] { const logos: T[] = parseFile(ctx, list.file, list.schema) ?? []; diff --git a/src/lib/share-cards.ts b/src/lib/share-cards.ts index b337da3..18ee2b4 100644 --- a/src/lib/share-cards.ts +++ b/src/lib/share-cards.ts @@ -1,5 +1,5 @@ import { LOCALES, type Locale } from '../i18n/locales'; -import { catalogueStrings, dataText, homeStrings, providerStrings, ui } from '../i18n/translate'; +import { catalogueStrings, dataText, glossaryStrings, homeStrings, providerStrings, ui } from '../i18n/translate'; import type { Provider } from '../schema/provider'; import type { ShareCardPage } from './share-card-types'; import { shorten } from './shorten'; @@ -23,6 +23,7 @@ export function shareCardPages(site: SiteData): ShareCardPage[] { return LOCALES.flatMap((locale) => [ catalogueCard(locale, site.published.length), countriesCard(locale, countryCount), + glossaryCard(locale), ...site.published.map((provider) => providerCard(locale, provider, site)), ]); } @@ -50,6 +51,12 @@ function countriesCard(locale: Locale, count: number): ShareCardPage { }; } +function glossaryCard(locale: Locale): ShareCardPage { + const t = glossaryStrings(locale); + + return { path: `${locale}/glossary`, card: { locale, eyebrow: t.eyebrow, title: t.heading, detail: shorten(t.intro, DETAIL_MAX) } }; +} + function providerCard(locale: Locale, provider: Provider, site: SiteData): ShareCardPage { const countries = new Set(provider.coverage.map((entry) => entry.country)).size; const summary = provider.summary === undefined ? providerStrings(locale).descriptionFallback(provider.name) : dataText(locale, provider.summary); diff --git a/src/lib/site-data.ts b/src/lib/site-data.ts index c21d8d6..169771c 100644 --- a/src/lib/site-data.ts +++ b/src/lib/site-data.ts @@ -47,6 +47,7 @@ export function selectSite(dataset: Dataset): SiteData { countriesInScope: dataset.countries.length, scope: dataset.countries.map((country) => country.code), lookups: lookups(dataset), + glossary: dataset.glossary.map(({ group }) => group), }; } diff --git a/src/lib/site-types.ts b/src/lib/site-types.ts index c5f77ab..30883cc 100644 --- a/src/lib/site-types.ts +++ b/src/lib/site-types.ts @@ -1,3 +1,4 @@ +import type { GlossaryGroup } from '../schema/glossary'; import type { Provider } from '../schema/provider'; import type { Country } from '../schema/reference'; import type { MethodKind } from './offer-types'; @@ -35,6 +36,8 @@ export interface SiteData { /** Country codes the directory covers, for the map of flags. */ scope: string[]; lookups: Lookups; + /** Sections of the glossary, in page order. */ + glossary: readonly GlossaryGroup[]; } /** A source as shown next to a value. */ diff --git a/src/lib/sitemap-lastmod.ts b/src/lib/sitemap-lastmod.ts index 44ea8d1..28785a8 100644 --- a/src/lib/sitemap-lastmod.ts +++ b/src/lib/sitemap-lastmod.ts @@ -1,3 +1,4 @@ +import type { GlossaryGroup } from '../schema/glossary'; import type { Provider } from '../schema/provider'; /** Pages that list every published provider, so they change when any record does. */ @@ -11,7 +12,7 @@ export function recordDate(provider: Provider): string { } /** Date to publish as `lastmod` for each site address, taken from record dates only, never from the build time. */ -export function lastmodByUrl(site: string, locales: readonly string[], providers: readonly Provider[]): Map { +export function lastmodByUrl(site: string, locales: readonly string[], providers: readonly Provider[], glossary: readonly GlossaryGroup[] = []): Map { const dates = new Map(); for (const locale of locales) { @@ -23,6 +24,12 @@ export function lastmodByUrl(site: string, locales: readonly string[], providers } } + const glossaryDate = latestTermDate(glossary); + + if (glossaryDate !== '') { + dates.set(`${site}/${locale}/glossary`, glossaryDate); + } + const latest = providers.map(recordDate).reduce((a, b) => (a > b ? a : b), ''); if (latest !== '') { @@ -34,3 +41,8 @@ export function lastmodByUrl(site: string, locales: readonly string[], providers return dates; } + +/** Date of the last change to any term of the glossary. Empty when it has none. */ +function latestTermDate(glossary: readonly GlossaryGroup[]): string { + return glossary.flatMap((group) => group.terms.map((term) => term.updated_at)).reduce((a, b) => (a > b ? a : b), ''); +} diff --git a/src/lib/structured-data-types.ts b/src/lib/structured-data-types.ts index b697be4..d1be8e1 100644 --- a/src/lib/structured-data-types.ts +++ b/src/lib/structured-data-types.ts @@ -17,6 +17,15 @@ export interface ListEntry { url: string; } +/** One defined term, with its absolute address. */ +export interface TermEntry { + name: string; + /** Other names of the term. */ + aliases: readonly string[]; + description: string; + url: string; +} + /** What a provider sheet states about the provider. Optional fields are left out of the output when absent. */ export interface ProviderEntity { name: string; diff --git a/src/lib/structured-data.ts b/src/lib/structured-data.ts index 0b5c71c..3e14112 100644 --- a/src/lib/structured-data.ts +++ b/src/lib/structured-data.ts @@ -1,5 +1,5 @@ import type { Locale } from '../i18n/locales'; -import type { ListEntry, ProviderEntity, StructuredData, TrailStep } from './structured-data-types'; +import type { ListEntry, ProviderEntity, StructuredData, TermEntry, TrailStep } from './structured-data-types'; /** Name the site is known by in search results. */ const SITE_NAME = 'Paymap'; @@ -63,3 +63,23 @@ export function itemListData(entries: readonly ListEntry[]): StructuredData { itemListElement: entries.map((entry, index) => ({ '@type': 'ListItem', position: index + 1, name: entry.name, url: entry.url })), }; } + +/** The glossary and its definitions, so a search engine can quote one term. */ +export function glossaryData(name: string, url: string, locale: Locale, terms: readonly TermEntry[]): StructuredData { + return { + '@context': 'https://schema.org', + '@type': 'DefinedTermSet', + '@id': `${url}#glossary`, + name, + url, + inLanguage: locale, + hasDefinedTerm: terms.map((term) => ({ + '@type': 'DefinedTerm', + name: term.name, + ...(term.aliases.length === 0 ? {} : { alternateName: term.aliases }), + description: term.description, + url: term.url, + inDefinedTermSet: `${url}#glossary`, + })), + }; +} diff --git a/src/pages/[locale]/glossary.astro b/src/pages/[locale]/glossary.astro new file mode 100644 index 0000000..e6e4af9 --- /dev/null +++ b/src/pages/[locale]/glossary.astro @@ -0,0 +1,12 @@ +--- +import GlossaryPage from '../../components/glossary/GlossaryPage.astro'; +import { LOCALES, type Locale } from '../../i18n/locales'; + +export function getStaticPaths() { + return LOCALES.map((locale) => ({ params: { locale } })); +} + +const locale = Astro.params.locale as Locale; +--- + + diff --git a/src/pages/llms.txt.ts b/src/pages/llms.txt.ts index da48850..9621981 100644 --- a/src/pages/llms.txt.ts +++ b/src/pages/llms.txt.ts @@ -24,6 +24,7 @@ export const GET: APIRoute = ({ site }) => { '## Directory', '', `- [All providers](${url('/providers')}): the verified providers, with countries covered and payment methods`, + `- [Glossary](${url('/glossary')}): the words of online payment in Africa, in plain language`, '', '## Provider sheets', '', diff --git a/src/schema/constants.ts b/src/schema/constants.ts index e7b5c74..3ed4c4b 100644 --- a/src/schema/constants.ts +++ b/src/schema/constants.ts @@ -115,3 +115,46 @@ export const BRAND_LOGO_FILE = /^logos\/brands\/[a-z0-9]+(?:-[a-z0-9]+)*\.(?:svg /** `logos/methods/-.`, the kind spelt with hyphens, same formats. */ export const METHOD_LOGO_FILE = /^logos\/methods\/[a-z0-9]+(?:-[a-z0-9]+)*\.(?:svg|png|webp|jpg)$/; + +/** Icons a glossary term can show, drawn in `src/lib/glossary-look.ts`. */ +export const GLOSSARY_ICONS = [ + 'bank', + 'bell', + 'box', + 'calendar', + 'card', + 'cash', + 'check', + 'code', + 'coins', + 'dispute', + 'download', + 'flask', + 'hash', + 'id-card', + 'key', + 'link', + 'lock', + 'pen', + 'percent', + 'phone', + 'pulse', + 'qr', + 'repeat', + 'seal', + 'search', + 'shield', + 'shop', + 'stack', + 'to-bank', + 'undo', + 'upload', + 'window', +] as const; + +export type GlossaryIcon = (typeof GLOSSARY_ICONS)[number]; + +/** Colours of a glossary section. */ +export const GLOSSARY_TONES = ['money', 'methods', 'actors', 'rules', 'technical'] as const; + +export type GlossaryTone = (typeof GLOSSARY_TONES)[number]; diff --git a/src/schema/glossary.ts b/src/schema/glossary.ts new file mode 100644 index 0000000..ce1acc0 --- /dev/null +++ b/src/schema/glossary.ts @@ -0,0 +1,43 @@ +import { z } from 'zod'; + +import { FAMILIES, GLOSSARY_ICONS, GLOSSARY_TONES } from './constants'; +import { isoDateSchema, slugSchema, webUrlSchema } from './primitives'; + +/** What a term says in one language. */ +const glossaryTextSchema = z.strictObject({ + name: z.string().min(1), + /** Other names readers meet for the same thing, shown under the name. */ + alias: z.string().min(1).optional(), + definition: z.string().min(1), + /** Completes "For example," so it starts in lower case. */ + example: z.string().min(1).optional(), +}); + +/** One term. `family` borrows the icon and colours of a provider family; the other terms name an `icon`. */ +export const glossaryTermSchema = z + .strictObject({ + /** Anchor of the term on the page, the same in every language. Never renamed once published. */ + id: slugSchema, + icon: z.enum(GLOSSARY_ICONS).optional(), + family: z.enum(FAMILIES).optional(), + en: glossaryTextSchema, + fr: glossaryTextSchema, + /** Words the search accepts for this term, in any language, without being shown. */ + keywords: z.array(z.string().min(1)).optional(), + /** Expected when the definition states facts about a named institution or standard. */ + sources: z.array(z.strictObject({ url: webUrlSchema, observed_at: isoDateSchema })).min(1).optional(), + updated_at: isoDateSchema, + }) + .refine((term) => (term.icon === undefined) !== (term.family === undefined), { message: 'Give either an icon or a family' }); + +/** A section of the glossary: `data/glossary/.json`. */ +export const glossaryGroupSchema = z.strictObject({ + id: slugSchema, + order: z.int().positive(), + tone: z.enum(GLOSSARY_TONES), + name: z.strictObject({ en: z.string().min(1), fr: z.string().min(1) }), + terms: z.array(glossaryTermSchema).min(1), +}); + +export type GlossaryTerm = z.infer; +export type GlossaryGroup = z.infer; diff --git a/tests/fixtures/records.ts b/tests/fixtures/records.ts index c2a971d..ac093b0 100644 --- a/tests/fixtures/records.ts +++ b/tests/fixtures/records.ts @@ -67,6 +67,7 @@ export const REFERENCE_DATA: Omit = { logos: [], brandLogos: [], methodLogos: [], + glossary: [], }; export const REGISTER: RegisterFile = { diff --git a/tests/glossary.test.ts b/tests/glossary.test.ts new file mode 100644 index 0000000..1321f74 --- /dev/null +++ b/tests/glossary.test.ts @@ -0,0 +1,122 @@ +import { describe, expect, it } from 'vitest'; + +import { LOCALES } from '../src/i18n/locales'; +import { checkGlossary } from '../src/lib/check-glossary'; +import { reporter } from '../src/lib/check-reference-data'; +import type { GlossaryFile, Issue } from '../src/lib/dataset-types'; +import { glossaryEntries } from '../src/lib/glossary-entries'; +import { glossaryLook } from '../src/lib/glossary-look'; +import { searchGlossary } from '../src/lib/glossary-search'; +import { loadSite } from '../src/lib/site-data'; +import { lastmodByUrl } from '../src/lib/sitemap-lastmod'; +import { glossaryData } from '../src/lib/structured-data'; +import { glossaryGroupSchema, glossaryTermSchema } from '../src/schema/glossary'; + +const { glossary } = loadSite(process.cwd()); +const terms = glossary.flatMap((group) => group.terms); +const search = (text: string, locale: 'en' | 'fr' = 'fr'): string[] => searchGlossary(glossaryEntries(glossary, locale), text); + +const TERM = { id: 'refund', icon: 'undo', en: { name: 'Refund', definition: 'x' }, fr: { name: 'Remboursement', definition: 'x' }, updated_at: '2026-12-03' }; +const GROUP = { id: 'money', order: 1, tone: 'money', name: { en: 'Money', fr: 'Argent' }, terms: [TERM] }; + +function issuesOf(files: Array<{ file: string; group: unknown }>): string[] { + const issues: Issue[] = []; + const parsed: GlossaryFile[] = files.map(({ file, group }) => ({ file, group: glossaryGroupSchema.parse(group) })); + checkGlossary(parsed, (file) => reporter(issues, file)); + + return issues.map((issue) => issue.message); +} + +describe('glossary data', () => { + it('keeps the technical section last', () => { + expect(glossary.map((group) => group.id)).toEqual(['money', 'methods', 'actors', 'rules', 'technical']); + }); + + it('draws every term', () => { + for (const group of glossary) { + for (const term of group.terms) expect(glossaryLook(term, group.tone).icon).toMatch(/^<(path|rect|circle)/); + } + }); + + it('asks for an icon or a family, never both', () => { + expect(glossaryTermSchema.safeParse(TERM).success).toBe(true); + expect(glossaryTermSchema.safeParse({ ...TERM, family: 'wallet' }).success).toBe(false); + expect(glossaryTermSchema.safeParse({ ...TERM, icon: undefined }).success).toBe(false); + }); + + it('asks for both languages', () => { + const { fr: _fr, ...english } = TERM; + + expect(glossaryTermSchema.safeParse(english).success).toBe(false); + }); + + it('rejects a repeated anchor, a repeated position and a misnamed file', () => { + expect(issuesOf([{ file: 'data/glossary/money.json', group: GROUP }])).toEqual([]); + expect(issuesOf([{ file: 'data/glossary/other.json', group: GROUP }])).toHaveLength(1); + expect(issuesOf([{ file: 'data/glossary/money.json', group: GROUP }, { file: 'data/glossary/rules.json', group: { ...GROUP, id: 'rules' } }])).toEqual([ + 'Position 1 is already taken', + 'Duplicate anchor "refund"', + ]); + }); +}); + +describe('searchGlossary', () => { + it('keeps every term for an empty text or spaces', () => { + expect(search('')).toHaveLength(terms.length); + expect(search(' ')).toHaveLength(terms.length); + }); + + it('finds every term by its name and alias in both languages', () => { + for (const locale of LOCALES) { + for (const term of terms) { + for (const code of LOCALES) { + expect(search(term[code].name, locale), term[code].name).toContain(term.id); + if (term[code].alias) expect(search(term[code].alias, locale), term[code].alias).toContain(term.id); + } + } + } + }); + + it('ignores case, accents and punctuation', () => { + expect(search('AGREGATEUR')).toEqual(['aggregator']); + expect(search('cle api')).toContain('api-key'); + expect(search('3-d secure')).toEqual(['3-d-secure']); + expect(search("page d'état")).toContain('status-page'); + }); + + it('understands a question', () => { + expect(search("c'est quoi un webhook ?")).toEqual(['webhook', 'webhook-signature']); + expect(search('que veut dire KYC')).toEqual(['kyc']); + expect(search('what is a chargeback?', 'en')).toEqual(['chargeback']); + }); + + it('forgives one wrong letter when nothing else matches', () => { + expect(search('agregatuer')).toEqual(['aggregator']); + expect(search('rembourssement')).toEqual(['refund']); + expect(search('weebhook')).toEqual(['webhook', 'webhook-signature']); + }); + + it('reads definitions when no name matches', () => { + expect(search('livreurs')).toEqual(['bulk-payout']); + expect(search('whatsapp', 'en')).toEqual(['payment-link']); + }); + + it('finds nothing for an unrelated word', () => { + expect(search('xylophone')).toEqual([]); + }); +}); + +describe('glossary for search engines', () => { + it('publishes each definition with its own address', () => { + const data = glossaryData('Glossary', 'https://paymap.africa/en/glossary', 'en', [{ name: 'API', aliases: [], description: 'A door.', url: 'https://paymap.africa/en/glossary#api' }]); + + expect(data).toMatchObject({ '@type': 'DefinedTermSet', inLanguage: 'en' }); + expect(data['hasDefinedTerm']).toEqual([{ '@type': 'DefinedTerm', name: 'API', description: 'A door.', url: 'https://paymap.africa/en/glossary#api', inDefinedTermSet: 'https://paymap.africa/en/glossary#glossary' }]); + }); + + it('dates the page from its latest term', () => { + const latest = terms.map((term) => term.updated_at).sort().at(-1); + + expect(lastmodByUrl('https://paymap.africa', ['fr'], [], glossary).get('https://paymap.africa/fr/glossary')).toBe(latest); + }); +}); diff --git a/tests/live-pages.test.ts b/tests/live-pages.test.ts index 79405d0..9bc7d86 100644 --- a/tests/live-pages.test.ts +++ b/tests/live-pages.test.ts @@ -7,6 +7,8 @@ describe('isLive', () => { expect(isLive('/fr')).toBe(true); expect(isLive('/providers')).toBe(true); expect(isLive('/fr/providers/')).toBe(true); + expect(isLive('/fr/countries')).toBe(true); + expect(isLive('/en/glossary#webhook')).toBe(true); expect(isLive('/en/providers/some-provider')).toBe(true); expect(isLive('/fr/providers/some-provider')).toBe(true); }); diff --git a/tests/share-cards.test.ts b/tests/share-cards.test.ts index fd8f260..9a63098 100644 --- a/tests/share-cards.test.ts +++ b/tests/share-cards.test.ts @@ -10,7 +10,7 @@ const site = loadSite(process.cwd()); describe('shareCardPages', () => { it('draws one image per indexed page except the homes, in every language', () => { const paths = shareCardPages(site).map((page) => page.path); - const expected = ['en', 'fr'].flatMap((locale) => [`${locale}/providers`, `${locale}/countries`, ...site.published.map((provider) => `${locale}/providers/${provider.slug}`)]); + const expected = ['en', 'fr'].flatMap((locale) => [`${locale}/providers`, `${locale}/countries`, `${locale}/glossary`, ...site.published.map((provider) => `${locale}/providers/${provider.slug}`)]); expect(paths).toEqual(expected); }); From 318d95e31f9faa1b585208a949f6b83967be630b Mon Sep 17 00:00:00 2001 From: Gauthier Eholoum Date: Thu, 3 Dec 2026 00:33:11 +0000 Subject: [PATCH 2/2] fix: announce the language switch as it is written --- src/components/LanguageSwitch.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/LanguageSwitch.astro b/src/components/LanguageSwitch.astro index fef9b9e..ed603d2 100644 --- a/src/components/LanguageSwitch.astro +++ b/src/components/LanguageSwitch.astro @@ -29,11 +29,11 @@ const options = SWITCH_ORDER.map((code) => { { options.map((option) => ( option.live ? ( - + {option.code.toUpperCase()} ) : ( - + {option.code.toUpperCase()} )