import Foundation import Testing @Suite struct TranslationRegressionTests { private static let sources = URL(fileURLWithPath: #filePath) .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() .appending(path: "Sources") @Test(arguments: [ ("ja", "モード「missing-mode」", "「bindings」に"), ("ko", "모드 “missing-mode”", "“bindings”에"), ]) func modeDiagnosticKeepsArgumentMeaning(locale: String, mode: String, container: String) throws { let catalog = try load("ParcelConfig/Resources/Schema.xcstrings") let value = try #require( catalog.strings["Unknown mode “%@” in “%@”. Declare [mode.%@]."]? .localizations[locale]?.stringUnit?.value) let rendered = String(format: value, arguments: ["missing-mode", "bindings", "missing-mode"]) #expect(rendered.contains(mode)) #expect(rendered.contains(container)) #expect(rendered.contains("[mode.missing-mode]")) } @Test func chineseSpaceDiagnosticKeepsArgumentMeaning() throws { let catalog = try load("ParcelEngine/Resources/Localizable.xcstrings") let value = try #require( catalog.strings["Current space %@ is not listed for display %@."]? .localizations["zh-Hans"]?.stringUnit?.value) let rendered = String(format: value, arguments: ["space-id", "display-id"]) #expect(rendered.contains("显示器 display-id")) #expect(rendered.contains("空间 space-id")) } @Test func koreanMergeSubstitutionDoesNotRepeatTheAction() throws { let catalog = try load("ParcelApp/Resources/App.xcstrings") let translation = try #require( catalog.strings["Merged %lld tiles into stacks to fit the layout limit of %lld."]? .localizations["ko"]) let outer = try #require(translation.stringUnit?.value) let tiles = try #require(translation.substitutions?["tiles"]?.variations?.plural?["other"]?.stringUnit?.value) #expect(outer.contains("병합")) #expect(!tiles.contains("병합")) #expect(tiles.contains("%1$lld")) } private func load(_ path: String) throws -> Catalog { try JSONDecoder().decode(Catalog.self, from: Data(contentsOf: Self.sources.appending(path: path))) } private struct Catalog: Decodable { let strings: [String: Entry] struct Entry: Decodable { let localizations: [String: Localization] } struct Localization: Decodable { let stringUnit: StringUnit? let substitutions: [String: Substitution]? } struct StringUnit: Decodable { let value: String } struct Substitution: Decodable { let variations: Variations? } struct Variations: Decodable { let plural: [String: Variant]? } struct Variant: Decodable { let stringUnit: StringUnit? } } }