Skip to content

Commit

Permalink
Merge pull request #9 from superarts/feature/api-string
Browse files Browse the repository at this point in the history
Added new string API
  • Loading branch information
superarts authored Nov 27, 2023
2 parents 1c75eab + dbadd6c commit be69031
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ If you are not familiar with [Apple's String Catalog](https://developer.apple.co
- It can be constructed manually, all you need is to use a `LocalizedStringKey` in `SwiftUI.View`, not the String itself.
- Helper function: `var key: LocalizedStringKey { LocalizedStringKey(rawValue) }`
- OR use the [StringCatalogEnum](./StringCatalogEnum) CLI tool in this repo.
- Copy `xcstrings-enum-generate` to your project.
- Download from [releases](./releases), and copy `xcstrings-enum-generate` to your project.
- OR build from source: `cd StringCatalogEnum && make release`
- Added something like `xcstrings-enum-generate --xcstrings-path ../Resources/Localizable.xcstrings --output-filename ../Generated/XcodeString.swift` to generate the `enum`.
- OR use [SwiftGen](https://github.com/SwiftGen/SwiftGen/issues/1065) - hopefully better support will be added in future.
- OR explore how to achieve it with [Sourcery](https://github.com/krzysztofzablocki/Sourcery).
Expand Down
9 changes: 7 additions & 2 deletions StringCatalogEnum/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
NAME=xcstrings-enum-generate

# TODO: get from ENV
EXPORT_PROJECT_ROOT=~/prj/business/quible/quible-ios
# TODO: remove other hard-coded paths

all: debug
./$(NAME) \
--xcstrings-path ~/prj/ios/quible/Quible/Resources/Localizable.xcstrings \
--xcstrings-path $(EXPORT_PROJECT_ROOT)/Quible/Resources/Localizable.xcstrings \
--enum-name XcodeString \
--enum-typealias X \
--output-filename ~/prj/ios/quible/Quible/Const/Generated/XcodeString.swift
--output-filename $(EXPORT_PROJECT_ROOT)/Quible/Const/Generated/XcodeString.swift

debug:
swift build
Expand All @@ -14,6 +18,7 @@ debug:
release: clean
swift build -c release
cp ./.build/release/$(NAME) .
cp xcstrings-enum-generate $(EXPORT_PROJECT_ROOT)/utility/

test:
swift test
Expand Down
2 changes: 1 addition & 1 deletion StringCatalogEnum/Sources/StringCatalogEnum/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct StringCatalogEnum: ParsableCommand {
/// Usage: `SwiftUI.Text(\(enumTypealias).yourStringCatalogKey.key)`
var key: LocalizedStringKey { LocalizedStringKey(rawValue) }
// var text: String { String(localized: key) }
var string: String { NSLocalizedString(self.rawValue, comment: "Generated localization from String Catalog key: \\(key)") }
// var text: String.LocalizationValue { String.LocalizationValue(rawValue) }
}
Expand Down

0 comments on commit be69031

Please sign in to comment.