Repository Public BSD-3-Clause
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Maps9// File : Apps/ORIXMaps/Tests/ORIXMapsTests/LocalizationTests.swift10// Module : ORIXMapsTests11// Repository : https://git.spboucher.ai/orix-maps12// Created : 2026-11-2513// Last Modified : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import Testing90@testable import ORIXMaps9192/// The compiled French resources of the application, read directly from its bundle (whatever language the tests run in).93struct LocalizationTests {94 private var french: Bundle? { Bundle.main.url(forResource: "fr", withExtension: "lproj").flatMap(Bundle.init(url:)) }9596 private func plural(_ key: String, _ n: Int, in bundle: Bundle) -> String {97 String(format: bundle.localizedString(forKey: key, value: nil, table: nil), locale: Locale(identifier: "fr_CA"), n)98 }99100 @Test func theApplicationShipsFrenchAndEnglish() {101 #expect(Set(Bundle.main.localizations).isSuperset(of: ["en", "fr"]))102 #expect(french != nil)103 }104105 @Test func commonFrenchTerms() throws {106 let fr = try #require(french)107 #expect(fr.localizedString(forKey: "Settings", value: nil, table: nil) == "Réglages")108 #expect(fr.localizedString(forKey: "Done", value: nil, table: nil) == "Terminé")109 #expect(fr.localizedString(forKey: "Cancel", value: nil, table: nil) == "Annuler")110 #expect(fr.localizedString(forKey: "Directions", value: nil, table: nil) == "Itinéraire")111 #expect(fr.localizedString(forKey: "Download", value: nil, table: nil) == "Télécharger")112 #expect(fr.localizedString(forKey: "Pin", value: nil, table: nil) == "Repère")113 }114115 @Test func frenchPlurals() throws {116 let fr = try #require(french)117 #expect(plural("%lld steps", 0, in: fr) == "0 étape")118 #expect(plural("%lld steps", 1, in: fr) == "1 étape")119 #expect(plural("%lld steps", 2, in: fr) == "2 étapes")120 #expect(plural("%lld places added.", 1, in: fr) == "1 lieu ajouté.")121 #expect(plural("%lld places added.", 12, in: fr) == "12 lieux ajoutés.")122 #expect(plural("%lld tracks imported.", 1, in: fr) == "1 tracé importé.")123 #expect(plural("%lld tracks imported.", 3, in: fr) == "3 tracés importés.")124 #expect(plural("Backup restored: %lld places.", 1, in: fr) == "Sauvegarde restaurée : 1 lieu.")125 #expect(plural("%lld features", 5, in: fr) == "5 éléments")126 }127128 @Test func englishPlurals() throws {129 let en = try #require(Bundle.main.url(forResource: "en", withExtension: "lproj").flatMap(Bundle.init(url:)))130 func form(_ key: String, _ n: Int) -> String { String(format: en.localizedString(forKey: key, value: nil, table: nil), locale: Locale(identifier: "en_CA"), n) }131 #expect(form("%lld steps", 1) == "1 step")132 #expect(form("%lld steps", 14) == "14 steps")133 #expect(form("%lld places added.", 1) == "1 place added.")134 #expect(form("%lld tracks imported.", 2) == "2 tracks imported.")135 }136137 @Test func reorderedArgumentsAndPercentSigns() throws {138 let fr = try #require(french)139 let downloading = String(format: fr.localizedString(forKey: "Downloading %@ of %@", value: nil, table: nil), "10 Mo", "222 Mo")140 #expect(downloading == "Téléchargement : 10 Mo sur 222 Mo")141 let estimate = String(format: fr.localizedString(forKey: "Duration is an estimate: %lld %% of the route has no posted speed in the data.", value: nil, table: nil), 40)142 #expect(estimate.contains("40\u{a0}% de l’itinéraire"))143 }144145 @Test func theLocationPurposeStringIsTranslated() throws {146 let fr = try #require(french)147 let text = fr.localizedString(forKey: "NSLocationWhenInUseUsageDescription", value: "", table: "InfoPlist")148 #expect(text.contains("votre position") && text.contains("cet appareil"))149 }150}151