From dffc14f8e4cd5a1727930264c181013397b4a9a8 Mon Sep 17 00:00:00 2001 From: SuperY Date: Wed, 25 Sep 2024 21:56:20 +0900 Subject: [PATCH] feat: #215 The generated Swift code, using public access (#216) --- .../DefaultLocalizedSwiftCodeOutputStringBuilder.swift | 4 ++-- .../Generator/LocalizedSwiftCodeGenerator.swift | 4 ++-- .../DefaultLocalizedSwiftCodeOutputStringBuilderTests.swift | 6 +++--- .../Generator/LocalizedSwiftCodeGeneratorTests.swift | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilder.swift b/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilder.swift index fab6125..d1cb645 100644 --- a/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilder.swift +++ b/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilder.swift @@ -16,7 +16,7 @@ struct DefaultLocalizedSwiftCodeOutputStringBuilder: LocalizedSwiftCodeOutputStr import Foundation - enum \(String.packageName) { + public enum \(String.packageName) { \(sectionsOutput) \tprivate static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { @@ -50,7 +50,7 @@ private extension DefaultLocalizedSwiftCodeOutputStringBuilder { .map { section in guard let keys = sections[section] else { return "" } let keysOutput = buildKeysOutput(section: section, keys: keys, translations: translations) - return "\tenum \(section.formatSheetSection()) {\n\(keysOutput)\n\t}" + return "\tpublic enum \(section.formatSheetSection()) {\n\(keysOutput)\n\t}" } .joined(separator: "\n\n") } diff --git a/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGenerator.swift b/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGenerator.swift index e75c28b..b8ae49c 100644 --- a/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGenerator.swift +++ b/Sources/LinguaLib/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGenerator.swift @@ -20,11 +20,11 @@ struct LocalizedSwiftCodeGenerator: LocalizedSwiftCodeGenerating { private extension LocalizedSwiftCodeGenerator { func generateStaticPropertyCode(section: String, key: String, translation: String) -> String { - translation.commented() + "\n\t\tstatic let \(key.formatKey()) = tr(\"\(section)\", \"\(key)\")" + translation.commented() + "\n\t\tpublic static let \(key.formatKey()) = tr(\"\(section)\", \"\(key)\")" } func generateFunctionCode(section: String, key: String, translation: String, placeholders: [Placeholder]) -> String { - var function = translation.commented() + "\n\t\tstatic func \(key.formatKey())(" + var function = translation.commented() + "\n\t\tpublic static func \(key.formatKey())(" for (index, placeholder) in placeholders.enumerated() { if index > 0 { function += ", " } diff --git a/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilderTests.swift b/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilderTests.swift index 108cad7..9ba0793 100644 --- a/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilderTests.swift +++ b/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Builder/DefaultLocalizedSwiftCodeOutputStringBuilderTests.swift @@ -29,12 +29,12 @@ final class DefaultLocalizedSwiftCodeOutputStringBuilderTests: XCTestCase { import Foundation - enum Lingua { - \tenum section1 { + public enum Lingua { + \tpublic enum section1 { \t\tgeneratedCode(section1, key1, value1) \t\tgeneratedCode(section1, key2, value2) \t}\n - \tenum section2 { + \tpublic enum section2 { \t\tgeneratedCode(section2, key3, value3) \t} diff --git a/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGeneratorTests.swift b/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGeneratorTests.swift index 33da6ad..953d4c7 100644 --- a/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGeneratorTests.swift +++ b/Tests/LinguaTests/Infrastructure/SwiftLocalizeGenerator/Generator/LocalizedSwiftCodeGeneratorTests.swift @@ -7,7 +7,7 @@ final class LocalizedSwiftCodeGeneratorTests: XCTestCase { let code = sut.generateCode(section: "section", key: "key", translation: "translation \n\r%d %@") let expectedCode = """ /// translation \\n\\r%d %@ - \t\tstatic func key(_ param1: Int, _ param2: String) -> String { + \t\tpublic static func key(_ param1: Int, _ param2: String) -> String { \t\t\treturn tr("section", "key", param1, param2) \t\t} """ @@ -17,7 +17,7 @@ final class LocalizedSwiftCodeGeneratorTests: XCTestCase { func test_generateCode_createsStaticPropertyCode_forNoStringFormatSpecifiers() { let sut = makeSUT() let code = sut.generateCode(section: "section", key: "key", translation: "translation") - XCTAssertEqual(code, "/// translation\n\t\tstatic let key = tr(\"section\", \"key\")") + XCTAssertEqual(code, "/// translation\n\t\tpublic static let key = tr(\"section\", \"key\")") } }