Repository Public
1// SP Wallet iOS2// File: Tests/LocalizationTests.swift3// Description: The English localization is shipped and is really English: the app bundle carries an en.lproj compiled from4// Resources/Localizable.xcstrings (source language: French), and a sample of strings a user must not misread5// (sign-in, emergency halt, review screen, PAPER / LIVE badges, offline notices, risk statements) resolves in6// that bundle to a non-empty value that is not the French key and carries no French. The full catalog is7// checked at build time by Scripts/sync-strings.sh (every key translated, none stale).8//9// Author: Simon-Pierre Boucher10// Contact: contact@spboucher.ai11import Foundation12import Testing13@testable import SPWallet1415@Suite struct LocalizationTests {16 /// The English strings of the app, read straight from en.lproj whatever the language the tests run in.17 private static let english: Bundle? = Bundle.main.path(forResource: "en", ofType: "lproj").flatMap { Bundle(path: $0) }1819 /// French source keys that must be translated (the key is the French text, as written in the views).20 private static let sample: [String] = [21 // sign-in and session22 "Se connecter avec une clé d’accès",23 "Se déconnecter",24 "Déverrouiller SP Wallet",25 // emergency halt and trading halt26 "Arrêt d’urgence",27 "Arrêt d’urgence actif : aucun envoi.",28 "Engager l’arrêt d’urgence",29 "Le serveur n’a PAS confirmé l’arrêt d’urgence",30 "Arrêt du trading (kill switch)",31 // review screen32 "Vérifier et approuver",33 "Approuver avec la clé d’accès",34 "Destinataire",35 "Frais de réseau",36 "Minimum reçu garanti",37 "Empreinte de l’intention",38 "Rien n’a été signé.",39 // modes40 "PAPIER",41 "RÉEL",42 "Mandat RÉEL",43 // offline44 "Hors ligne : aucune action possible.",45 "Consulter hors ligne (lecture seule)",46 // sections47 "Portefeuille",48 "Échanger",49 "Pont",50 "Contrats à terme",51 "Risque et limites",52 "Signataire isolé",53 // risk statements54 "Un transfert de NFT est irréversible",55 "Un ordre envoyé n’est pas un ordre exécuté",56 "Aucune projection n’est une garantie de résultat.",57 ]5859 /// Letters and words that only French text carries.60 private static func looksFrench(_ s: String) -> Bool {61 if s.rangeOfCharacter(from: CharacterSet(charactersIn: "àâçéèêëîïôùûœÀÂÇÉÈÊËÎÏÔÙÛŒ")) != nil { return true }62 if s.contains(" : ") { return true } // French spacing before a colon63 let words = Set(s.lowercased().components(separatedBy: CharacterSet.letters.inverted))64 return !words.isDisjoint(with: ["le", "la", "les", "des", "une", "avec", "sur", "est", "pas", "aucun", "aucune", "et"])65 }6667 @Test func englishBundleExists() throws {68 let path = try #require(Bundle.main.path(forResource: "en", ofType: "lproj"), "en.lproj is missing from the app bundle")69 #expect(Bundle(path: path) != nil)70 }7172 @Test(arguments: sample) func importantStringIsTranslated(key: String) throws {73 let en = try #require(Self.english, "en.lproj is missing from the app bundle")74 let missing = "\u{1}missing"75 let value = en.localizedString(forKey: key, value: missing, table: nil)76 #expect(value != missing, "no English entry for « \(key) »")77 #expect(!value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)78 #expect(value != key, "« \(key) » is still French")79 #expect(!Self.looksFrench(value), "« \(value) » does not read as English")80 }8182 @Test func badgesAndProductTermsAreExact() throws {83 let en = try #require(Self.english, "en.lproj is missing from the app bundle")84 func t(_ key: String) -> String { en.localizedString(forKey: key, value: nil, table: nil) }85 #expect(t("PAPIER") == "PAPER")86 #expect(t("RÉEL") == "LIVE")87 #expect(t("SIMULATION") == "SIMULATION")88 #expect(t("Arrêt d’urgence") == "Emergency halt")89 #expect(t("Signataire isolé") == "Isolated signer")90 #expect(t("Contrats à terme") == "Futures")91 #expect(t("Se connecter avec une clé d’accès").localizedCaseInsensitiveContains("passkey"))92 }9394 @Test func formatSpecifiersSurviveTranslation() throws {95 let en = try #require(Self.english, "en.lproj is missing from the app bundle")96 // The key of "Solde : \(x)"-style literals carries the specifiers; the English value must keep them.97 let one = en.localizedString(forKey: "Adresse %@ invalide", value: nil, table: nil)98 #expect(one.components(separatedBy: "%@").count == 2)99 let two = en.localizedString(forKey: "Budget %@ · par ordre %@ · levier %@ × · expire le %@", value: nil, table: nil)100 #expect(String(format: two, "A", "B", "C", "D") == "Budget A · per order B · leverage C× · expires on D")101 }102}103