-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose StringCatalog target as a library (#48)
* Make StringCatalog initializers public * Expose StringCatalog as a linkable library * Add StringCatalog test * Ensure parser can be used externally * Address PR comments * Update tests.yml
- Loading branch information
1 parent
05bb5f4
commit ddbda75
Showing
11 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Foundation | ||
import XCTest | ||
import StringCatalog | ||
|
||
class StringCatalogTests: XCTestCase { | ||
func testCreateCatalog() { | ||
let stringUnit = StringUnit(state: .translated, value: "Example value") | ||
let variations = StringVariations(device: [.iPad: StringVariation(stringUnit: stringUnit)], plural: [:]) | ||
let substitutions = ["substitution": StringSubstitution(argNum: 0, formatSpecifier: "%lld", variations: variations)] | ||
let localization = StringLocalization(stringUnit: stringUnit, substitutions: substitutions, variations: variations) | ||
let entry = StringEntry(comment: "A comment", extractionState: "manual", localizations: [ "en": localization ]) | ||
_ = StringCatalog(sourceLanguage: "en", strings: ["ExampleKey": entry], version: "1.0") | ||
} | ||
|
||
func testParseCatalog() throws { | ||
let fixtureUrl = try fixture(named: "Localizable") | ||
let catalog = try StringCatalog(contentsOf: fixtureUrl) | ||
print(String(describing: catalog)) | ||
} | ||
|
||
func fixture(named name: String) throws -> URL { | ||
let bundle = Bundle.module | ||
return try XCTUnwrap( | ||
bundle.url(forResource: name, withExtension: "xcstrings", subdirectory: "__Fixtures__") | ||
) | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
Tests/StringCatalogTests/__Fixtures__/Localizable.xcstrings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
"sourceLanguage" : "en", | ||
"strings" : { | ||
"Empty" : { | ||
"extractionState" : "manual" | ||
}, | ||
"Empty.Comment" : { | ||
"comment" : "Value is empty but there is a comment", | ||
"extractionState" : "manual" | ||
}, | ||
"Key" : { | ||
"comment" : "This is a comment", | ||
"extractionState" : "manual", | ||
"localizations" : { | ||
"en" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "Default Value" | ||
} | ||
} | ||
} | ||
}, | ||
"myDeviceVariant" : { | ||
"extractionState" : "manual", | ||
"localizations" : { | ||
"en" : { | ||
"variations" : { | ||
"device" : { | ||
"ipad" : { | ||
"stringUnit" : { | ||
"state" : "needs_review", | ||
"value" : "macOS Original" | ||
} | ||
}, | ||
"mac" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "macOS Original" | ||
} | ||
}, | ||
"other" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "Multiplatform Original" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"myPlural" : { | ||
"extractionState" : "manual", | ||
"localizations" : { | ||
"en" : { | ||
"variations" : { | ||
"plural" : { | ||
"one" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "I have %lld plural" | ||
} | ||
}, | ||
"other" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "I have %lld plurals" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"mySubstitute" : { | ||
"extractionState" : "manual", | ||
"localizations" : { | ||
"en" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "%lld: People liked %#@count@ posts" | ||
}, | ||
"substitutions" : { | ||
"count" : { | ||
"argNum" : 2, | ||
"formatSpecifier" : "lld", | ||
"variations" : { | ||
"plural" : { | ||
"one" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "%arg" | ||
} | ||
}, | ||
"other" : { | ||
"stringUnit" : { | ||
"state" : "needs_review", | ||
"value" : "%arg" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"version" : "1.0" | ||
} |