feat(RES-58): Add new parameter "bundle" (#19)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good

Add bundle parameter to define if resource should be load from Bundle.main (app) or Bundle.module (SPM package)

Reviewed-on: #19
This commit is contained in:
2025-07-25 16:14:36 +02:00
parent 5ad219ae89
commit f329386ccf
37 changed files with 866 additions and 403 deletions

View File

@@ -94,9 +94,24 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .public)
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .public)
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us", visibility: .public)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: false,
visibility: .public,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: false,
visibility: .public,
assetBundle: .main
)
let propertyEnUs = definition.getNSLocalizedStringProperty(
forLang: "en-us",
isStatic: false,
visibility: .public,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -149,9 +164,24 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .private)
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .private)
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us", visibility: .private)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: false,
visibility: .private,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: false,
visibility: .private,
assetBundle: .main
)
let propertyEnUs = definition.getNSLocalizedStringProperty(
forLang: "en-us",
isStatic: false,
visibility: .private,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -203,9 +233,24 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .public)
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .public)
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us", visibility: .public)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: false,
visibility: .public,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: false,
visibility: .public,
assetBundle: .main
)
let propertyEnUs = definition.getNSLocalizedStringProperty(
forLang: "en-us",
isStatic: false,
visibility: .public,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -246,7 +291,7 @@ final class DefinitionTests: XCTestCase {
XCTAssertEqual(propertyEnUs.adaptForXCTest(), expectEnUs.adaptForXCTest())
}
// MARK: - getNSLocalizedStringStaticProperty
// MARK: - getNSLocalizedStringProperty - static
func testGeneratedNSLocalizedStringStaticProperty() {
// Given
@@ -260,9 +305,24 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr", visibility: .public)
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en", visibility: .public)
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us", visibility: .public)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: true,
visibility: .public,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: true,
visibility: .public,
assetBundle: .main
)
let propertyEnUs = definition.getNSLocalizedStringProperty(
forLang: "en-us",
isStatic: true,
visibility: .public,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -315,9 +375,24 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr", visibility: .internal)
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en", visibility: .internal)
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us", visibility: .internal)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: true,
visibility: .internal,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: true,
visibility: .internal,
assetBundle: .main
)
let propertyEnUs = definition.getNSLocalizedStringProperty(
forLang: "en-us",
isStatic: true,
visibility: .internal,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -369,9 +444,24 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr", visibility: .internal)
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en", visibility: .internal)
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us", visibility: .internal)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: true,
visibility: .internal,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: true,
visibility: .internal,
assetBundle: .main
)
let propertyEnUs = definition.getNSLocalizedStringProperty(
forLang: "en-us",
isStatic: true,
visibility: .internal,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -422,7 +512,12 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .internal)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: false,
visibility: .internal,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -458,7 +553,12 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .private)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: false,
visibility: .private,
assetBundle: .main
)
// Expect
let expectFr = """
@@ -495,8 +595,18 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .public)
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .public)
let propertyFr = definition.getNSLocalizedStringProperty(
forLang: "fr",
isStatic: false,
visibility: .public,
assetBundle: .main
)
let propertyEn = definition.getNSLocalizedStringProperty(
forLang: "en",
isStatic: false,
visibility: .public,
assetBundle: .main
)
let expectFr = """
/// Translation in fr :
@@ -556,9 +666,21 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getProperty(forLang: "fr", visibility: .public)
let propertyEn = definition.getProperty(forLang: "en", visibility: .public)
let propertyEnUs = definition.getProperty(forLang: "en-us", visibility: .public)
let propertyFr = definition.getProperty(
forLang: "fr",
visibility: .public,
isStatic: false
)
let propertyEn = definition.getProperty(
forLang: "en",
visibility: .public,
isStatic: false
)
let propertyEnUs = definition.getProperty(
forLang: "en-us",
visibility: .public,
isStatic: false
)
// Expect
let expectFr = """
@@ -611,9 +733,21 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getProperty(forLang: "fr", visibility: .package)
let propertyEn = definition.getProperty(forLang: "en", visibility: .package)
let propertyEnUs = definition.getProperty(forLang: "en-us", visibility: .package)
let propertyFr = definition.getProperty(
forLang: "fr",
visibility: .package,
isStatic: false
)
let propertyEn = definition.getProperty(
forLang: "en",
visibility: .package,
isStatic: false
)
let propertyEnUs = definition.getProperty(
forLang: "en-us",
visibility: .package,
isStatic: false
)
// Expect
let expectFr = """
@@ -665,9 +799,21 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getProperty(forLang: "fr", visibility: .private)
let propertyEn = definition.getProperty(forLang: "en", visibility: .private)
let propertyEnUs = definition.getProperty(forLang: "en-us", visibility: .private)
let propertyFr = definition.getProperty(
forLang: "fr",
visibility: .private,
isStatic: false
)
let propertyEn = definition.getProperty(
forLang: "en",
visibility: .private,
isStatic: false
)
let propertyEnUs = definition.getProperty(
forLang: "en-us",
visibility: .private,
isStatic: false
)
// Expect
let expectFr = """
@@ -722,9 +868,21 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getStaticProperty(forLang: "fr", visibility: .internal)
let propertyEn = definition.getStaticProperty(forLang: "en", visibility: .internal)
let propertyEnUs = definition.getStaticProperty(forLang: "en-us", visibility: .internal)
let propertyFr = definition.getProperty(
forLang: "fr",
visibility: .internal,
isStatic: true
)
let propertyEn = definition.getProperty(
forLang: "en",
visibility: .internal,
isStatic: true
)
let propertyEnUs = definition.getProperty(
forLang: "en-us",
visibility: .internal,
isStatic: true
)
// Expect
let expectFr = """
@@ -777,9 +935,21 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getStaticProperty(forLang: "fr", visibility: .internal)
let propertyEn = definition.getStaticProperty(forLang: "en", visibility: .internal)
let propertyEnUs = definition.getStaticProperty(forLang: "en-us", visibility: .internal)
let propertyFr = definition.getProperty(
forLang: "fr",
visibility: .internal,
isStatic: true
)
let propertyEn = definition.getProperty(
forLang: "en",
visibility: .internal,
isStatic: true
)
let propertyEnUs = definition.getProperty(
forLang: "en-us",
visibility: .internal,
isStatic: true
)
// Expect
let expectFr = """
@@ -831,9 +1001,21 @@ final class DefinitionTests: XCTestCase {
]
// When
let propertyFr = definition.getStaticProperty(forLang: "fr", visibility: .internal)
let propertyEn = definition.getStaticProperty(forLang: "en", visibility: .internal)
let propertyEnUs = definition.getStaticProperty(forLang: "en-us", visibility: .internal)
let propertyFr = definition.getProperty(
forLang: "fr",
visibility: .internal,
isStatic: true
)
let propertyEn = definition.getProperty(
forLang: "en",
visibility: .internal,
isStatic: true
)
let propertyEnUs = definition.getProperty(
forLang: "en-us",
visibility: .internal,
isStatic: true
)
// Expect
let expectFr = """

View File

@@ -11,7 +11,7 @@ import ToolCore
extension StringsFileGeneratorTests {
static func getExtensionContentExpectation(
staticVar: Bool,
isStatic: Bool,
s1DefOneFr: String = "Section Un - Definition Un",
s1DefOneComment: String = "",
s1DefTwoFr: String = "Section Un - Definition Deux",
@@ -20,7 +20,8 @@ extension StringsFileGeneratorTests {
s2DefOneComment: String = "",
s2DefTwoFr: String = "Section Deux - Definition Deux",
s2DefTwoComment: String = "",
visibility: ExtensionVisibility = .internal
visibility: ExtensionVisibility = .internal,
assetBundle: AssetBundle = .main
) -> String {
"""
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
@@ -54,8 +55,8 @@ extension StringsFileGeneratorTests {
///
/// Comment :
/// \(s1DefOneComment.isEmpty ? "No comment" : s1DefOneComment)
\(visibility) \(staticVar ? "static " : "")var s1_def_one: String {
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "\(s1DefOneComment)")
\(visibility) \(isStatic ? "static " : "")var s1_def_one: String {
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Un - Definition Un", comment: "\(s1DefOneComment)")
}
/// Translation in fr :
@@ -63,8 +64,8 @@ extension StringsFileGeneratorTests {
///
/// Comment :
/// \(s1DefTwoComment.isEmpty ? "No comment" : s1DefTwoComment)
\(visibility) \(staticVar ? "static " : "")var s1_def_two: String {
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "\(s1DefTwoComment)")
\(visibility) \(isStatic ? "static " : "")var s1_def_two: String {
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Un - Definition Deux", comment: "\(s1DefTwoComment)")
}
// MARK: - section_two
@@ -74,8 +75,8 @@ extension StringsFileGeneratorTests {
///
/// Comment :
/// \(s2DefOneComment.isEmpty ? "No comment" : s2DefOneComment)
\(visibility) \(staticVar ? "static " : "")var s2_def_one: String {
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "\(s2DefOneComment)")
\(visibility) \(isStatic ? "static " : "")var s2_def_one: String {
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Deux - Definition Un", comment: "\(s2DefOneComment)")
}
/// Translation in fr :
@@ -83,8 +84,8 @@ extension StringsFileGeneratorTests {
///
/// Comment :
/// \(s2DefTwoComment.isEmpty ? "No comment" : s2DefTwoComment)
\(visibility) \(staticVar ? "static " : "")var s2_def_two: String {
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "\(s2DefTwoComment)")
\(visibility) \(isStatic ? "static " : "")var s2_def_two: String {
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Deux - Definition Deux", comment: "\(s2DefTwoComment)")
}
}
"""

View File

@@ -377,16 +377,17 @@ final class StringsFileGeneratorTests: XCTestCase {
sections: [sectionOne, sectionTwo],
defaultLang: "fr",
tags: ["ios", "iosonly", "notranslation"],
staticVar: false,
isStatic: false,
inputFilename: "myInputFilename",
extensionName: "GenStrings",
extensionSuffix: "strings",
visibility: .internal
visibility: .internal,
assetBundle: .main
)
// Expect
let expect = Self.getExtensionContentExpectation(
staticVar: false
isStatic: false
)
if extensionContent != expect {
@@ -411,16 +412,17 @@ final class StringsFileGeneratorTests: XCTestCase {
sections: [sectionOne, sectionTwo],
defaultLang: "fr",
tags: ["ios", "iosonly", "notranslation"],
staticVar: false,
isStatic: false,
inputFilename: "myInputFilename",
extensionName: "GenStrings",
extensionSuffix: "strings",
visibility: .public
visibility: .public,
assetBundle: .main
)
// Expect
let expect = Self.getExtensionContentExpectation(
staticVar: false,
isStatic: false,
s1DefOneComment: "This is a comment",
s1DefTwoComment: "This is a comment",
s2DefOneComment: "This is a comment",
@@ -435,7 +437,7 @@ final class StringsFileGeneratorTests: XCTestCase {
}
// MARK: - Extension Content Static
func testGeneratedExtensionContentWithStaticVar() {
func testGeneratedExtensionContentWithIsStatic() {
// Given
let sectionOne = Section.Mock.getSectionOne()
let sectionTwo = Section.Mock.getSectionTwo()
@@ -445,17 +447,19 @@ final class StringsFileGeneratorTests: XCTestCase {
sections: [sectionOne, sectionTwo],
defaultLang: "fr",
tags: ["ios", "iosonly", "notranslation"],
staticVar: true,
isStatic: true,
inputFilename: "myInputFilename",
extensionName: "GenStrings",
extensionSuffix: "strings",
visibility: .package
visibility: .package,
assetBundle: .module
)
// Expect
let expect = Self.getExtensionContentExpectation(
staticVar: true,
visibility: .package
isStatic: true,
visibility: .package,
assetBundle: .module
)
if extensionContent != expect {
@@ -464,7 +468,7 @@ final class StringsFileGeneratorTests: XCTestCase {
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
}
func testGeneratedExtensionContentWithStaticVarWithComment() {
func testGeneratedExtensionContentWithIsStaticWithComment() {
// Given
let sectionOne = Section.Mock.getSectionOne(
defOneComment: "This is a comment",
@@ -480,21 +484,23 @@ final class StringsFileGeneratorTests: XCTestCase {
sections: [sectionOne, sectionTwo],
defaultLang: "fr",
tags: ["ios", "iosonly", "notranslation"],
staticVar: true,
isStatic: true,
inputFilename: "myInputFilename",
extensionName: "GenStrings",
extensionSuffix: "strings",
visibility: .internal
visibility: .internal,
assetBundle: .module
)
// Expect
let expect = Self.getExtensionContentExpectation(
staticVar: true,
isStatic: true,
s1DefOneComment: "This is a comment",
s1DefTwoComment: "This is a comment",
s2DefOneComment: "This is a comment",
s2DefTwoComment: "This is a comment",
visibility: .internal
visibility: .internal,
assetBundle: .module
)
if extensionContent != expect {

View File

@@ -49,7 +49,7 @@ final class TagsGeneratorTests: XCTestCase {
sections: [sectionOne, sectionTwo, sectionThree],
lang: "ium",
tags: ["ios", "iosonly"],
staticVar: false,
isStatic: false,
extensionName: "GenTags",
visibility: .public
)