Skip to content

Commit

Permalink
feat: #215 The generated Swift code, using public access (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperY authored Sep 25, 2024
1 parent 265b8ce commit dffc14f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ", " }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""
Expand All @@ -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\")")
}
}

Expand Down

0 comments on commit dffc14f

Please sign in to comment.