@@ -115,21 +115,93 @@ public struct UIConfig: Codable, Equatable, Sendable {
115115 public var app : AppConfig
116116 public var localizations : [ String : [ String : String ] ]
117117 public var variableConfig : VariableConfig
118+
119+ @DefaultDecodable . EmptyDictionary
120+ var priceFormattingRuleSets : [
121+ // storefront country code -> ruleset
122+ String : PriceFormattingRuleSet
123+ ]
118124
119125 public init ( app: AppConfig ,
120126 localizations: [ String : [ String : String ] ] ,
121- variableConfig: VariableConfig ) {
127+ variableConfig: VariableConfig ,
128+ priceFormattingRuleSets: [ String : PriceFormattingRuleSet ] ) {
122129 self . app = app
123130 self . localizations = localizations
124131 self . variableConfig = variableConfig
132+ self . priceFormattingRuleSets = priceFormattingRuleSets
125133 }
126134
127135}
128136
129137#else
130138
131139public struct UIConfig : Codable , Equatable , Sendable {
132-
140+ @DefaultDecodable . EmptyDictionary
141+ var priceFormattingRuleSets : [
142+ // storefront country code -> ruleset
143+ String : PriceFormattingRuleSet
144+ ]
145+
146+ public init ( priceFormattingRuleSets: [ String : PriceFormattingRuleSet ] ) {
147+ self . priceFormattingRuleSets = priceFormattingRuleSets
148+ }
133149}
134150
135151#endif
152+
153+ /*
154+ Contains a set of rules that will be used when formatting a price
155+ Currrently only supports overriding the currencySymbol per currency
156+ */
157+ public struct PriceFormattingRuleSet : Sendable {
158+
159+ // currencyCode: CurrencySymbolOverride
160+ private var currencySymbolOverrides : [ String : CurrencySymbolOverride ]
161+
162+ init ( currencySymbolOverrides: [ String : CurrencySymbolOverride ] ) {
163+ self . currencySymbolOverrides = currencySymbolOverrides
164+ }
165+
166+ func currencySymbolOverride(
167+ currencyCode: String
168+ ) -> CurrencySymbolOverride ? {
169+ return self . currencySymbolOverrides [ currencyCode]
170+ }
171+
172+ /*
173+ Contains a set of currencySymbol overrides for different pluralization rules
174+ */
175+ struct CurrencySymbolOverride : Sendable {
176+ let zero : String
177+ let one : String
178+ let two : String
179+ let few : String
180+ let many : String
181+ let other : String
182+
183+ func value( for rule: PluralRule ) -> String {
184+ switch rule {
185+ case . zero:
186+ return self . zero
187+ case . one:
188+ return self . one
189+ case . two:
190+ return self . two
191+ case . few:
192+ return self . few
193+ case . many:
194+ return self . many
195+ case . other:
196+ return self . other
197+ }
198+ }
199+
200+ public enum PluralRule {
201+ case zero, one, two, few, many, other
202+ }
203+ }
204+ }
205+
206+ extension PriceFormattingRuleSet : Codable , Equatable { }
207+ extension PriceFormattingRuleSet . CurrencySymbolOverride : Codable , Equatable { }
0 commit comments