Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Apps/GlassStudio/Kit/Model/StudioL10n.swift8// Module : GlassStudio9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation4243/// Localised strings of the Studio (English and French). Keys are the English text.44public enum StudioL10n {45 /// Tables searched for a key: the interface table first, then one table per descriptor category.46 public static let tables = ["Studio", "FieldsNavigation", "FieldsButtons", "FieldsForms", "FieldsSelection", "FieldsContainers", "FieldsFeedback", "FieldsData", "FieldsMedia", "FieldsMaps", "FieldsAI"]4748 /// Language override chosen in Settings ("en", "fr"), or nil to follow the system.49 nonisolated(unsafe) private static var overrideBundle: Bundle?50 private static let lock = NSLock()5152 public static func setLanguage(_ code: String?) {53 lock.lock(); defer { lock.unlock() }54 if let code, let path = Bundle.module.path(forResource: code, ofType: "lproj") {55 overrideBundle = Bundle(path: path)56 } else {57 overrideBundle = nil58 }59 }6061 private static var bundle: Bundle {62 lock.lock(); defer { lock.unlock() }63 return overrideBundle ?? .module64 }6566 public static func string(_ key: String) -> String {67 let bundle = bundle68 let missing = "\u{1}"69 for table in tables {70 let value = bundle.localizedString(forKey: key, value: missing, table: table)71 if value != missing { return value }72 }73 return key74 }7576 public static func string(_ key: String, _ arguments: any CVarArg...) -> String {77 String(format: string(key), locale: .current, arguments: arguments)78 }7980 /// The translation in a given language, for tests.81 public static func string(_ key: String, language: String, table: String = "Studio") -> String? {82 guard let path = Bundle.module.path(forResource: language, ofType: "lproj"), let bundle = Bundle(path: path) else { return nil }83 let missing = "\u{1}"84 let value = bundle.localizedString(forKey: key, value: missing, table: table)85 return value == missing ? nil : value86 }87}8889/// Shorthand used throughout the Studio's views.90public func L(_ key: String) -> String { StudioL10n.string(key) }91