Skip to content

Commit 03c3816

Browse files
committed
Merge branch 'release/4.14.0' into versions
2 parents 36cc463 + 2f12a53 commit 03c3816

File tree

11 files changed

+93
-45
lines changed

11 files changed

+93
-45
lines changed

BartyCrouch.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "BartyCrouch"
4-
s.version = "4.13.0"
4+
s.version = "4.14.0"
55
s.summary = "Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files."
66

77
s.description = <<-DESC

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
3131
### Security
3232
- None.
3333

34+
## [4.14.0] - 2022-12-14
35+
### Added
36+
- Support for Swift 5.7 and Xcode 14, dropping support for older versions and fixing the 'could not parse syntax tree' issue.
37+
- BartyCrouch now recognizes `LocalizedStringResource` entries by default (unless you override the `customFunction` option). This helps support localization in newer APIs like the AppIntents framework. See README for more info.
38+
### Fixed
39+
- Updated DeepL API to a POST request according to the documentation to fix issues.
40+
3441
## [4.13.0] - 2022-10-07
3542
### Added
3643
- Re-implement option `overrideComments` for code update (see README).

Formula/bartycrouch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Bartycrouch < Formula
22
desc "Incrementally update/translate your Strings files"
33
homepage "https://github.com/Flinesoft/BartyCrouch"
4-
url "https://github.com/Flinesoft/BartyCrouch.git", :tag => "4.12.1", :revision => "f2515c0e78b35681602a7b48bc6b08a8d19bf864"
4+
url "https://github.com/Flinesoft/BartyCrouch.git", :tag => "4.13.0", :revision => "36cc46399abe717986cda40ccd6d6eb34c6ff70d"
55
head "https://github.com/Flinesoft/BartyCrouch.git"
66

77
depends_on :xcode => ["14.0", :build]

Makefile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL = /bin/bash
22

3-
prefix ?= /usr/local
3+
prefix ?= /opt/homebrew
44
bindir ?= $(prefix)/bin
55
libdir ?= $(prefix)/lib
66
srcdir = Sources
@@ -18,26 +18,33 @@ bartycrouch: $(SOURCES)
1818
@swift build \
1919
-c release \
2020
--disable-sandbox \
21-
--scratch-path "$(BUILDDIR)" \
22-
-Xlinker -dead_strip_dylibs
21+
--scratch-path "$(BUILDDIR)"
2322

2423
bartycrouch_universal: $(SOURCES)
2524
@swift build \
2625
-c release \
2726
--arch arm64 --arch x86_64 \
2827
--disable-sandbox \
29-
--scratch-path "$(BUILDDIR)" \
30-
-Xlinker -dead_strip_dylibs
28+
--scratch-path "$(BUILDDIR)"
3129

3230
.PHONY: install
3331
install: bartycrouch
3432
@install -d "$(bindir)" "$(libdir)"
3533
@install "$(BUILDDIR)/release/bartycrouch" "$(bindir)"
34+
@install ".build/artifacts/swift-syntax/_InternalSwiftSyntaxParser.xcframework/macos-arm64_x86_64/lib_InternalSwiftSyntaxParser.dylib" \
35+
"$(libdir)"
36+
@install_name_tool -change \
37+
"@rpath/lib_InternalSwiftSyntaxParser.dylib" \
38+
"$(libdir)/lib_InternalSwiftSyntaxParser.dylib" \
39+
"$(bindir)/bartycrouch"
3640

3741
.PHONY: portable_zip
3842
portable_zip: bartycrouch_universal
3943
rm -f "$(BUILDDIR)/Apple/Products/Release/portable_bartycrouch.zip"
40-
zip -j "$(BUILDDIR)/Apple/Products/Release/portable_bartycrouch.zip" "$(BUILDDIR)/Apple/Products/Release/bartycrouch" "$(REPODIR)/LICENSE"
44+
zip -j "$(BUILDDIR)/Apple/Products/Release/portable_bartycrouch.zip" \
45+
"$(BUILDDIR)/Apple/Products/Release/bartycrouch" \
46+
"$(REPODIR)/LICENSE" \
47+
".build/artifacts/swift-syntax/_InternalSwiftSyntaxParser.xcframework/macos-arm64_x86_64/lib_InternalSwiftSyntaxParser.dylib"
4148
echo "Portable ZIP created at: $(BUILDDIR)/Apple/Products/Release/portable_bartycrouch.zip"
4249

4350
.PHONY: uninstall

Package.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ let package = Package(
2323
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.3.0"),
2424
],
2525
targets: [
26-
.binaryTarget(
27-
name: "lib_InternalSwiftSyntaxParser",
28-
url: "https://github.com/keith/StaticInternalSwiftSyntaxParser/releases/download/5.7/lib_InternalSwiftSyntaxParser.xcframework.zip",
29-
checksum: "99803975d10b2664fc37cc223a39b4e37fe3c79d3d6a2c44432007206d49db15"
30-
),
3126
.executableTarget(
3227
name: "BartyCrouch",
3328
dependencies: ["BartyCrouchKit"]
@@ -43,7 +38,6 @@ let package = Package(
4338
"SwiftCLI",
4439
.product(name: "SwiftSyntaxParser", package: "swift-syntax"),
4540
.product(name: "SwiftSyntax", package: "swift-syntax"),
46-
"lib_InternalSwiftSyntaxParser",
4741
"BartyCrouchUtility",
4842
]
4943
),

README.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<img src="https://api.codacy.com/project/badge/Coverage/7b34ad9193c2438aa32aa29a0490451f"/>
1515
</a>
1616
<a href="https://github.com/FlineDev/BartyCrouch/releases">
17-
<img src="https://img.shields.io/badge/Version-4.13.0-blue.svg"
18-
alt="Version: 4.13.0">
17+
<img src="https://img.shields.io/badge/Version-4.14.0-blue.svg"
18+
alt="Version: 4.14.0">
1919
</a>
2020
<img src="https://img.shields.io/badge/Swift-5.7-FFAC45.svg"
2121
alt="Swift: 5.7">
@@ -50,6 +50,14 @@
5050
• <a href="#license">License</a>
5151
</p>
5252

53+
> :sparkles: **Important Notice** :sparkles:
54+
>
55+
> There's [**now a new Mac app called RemafoX**](https://remafox.app?source=github.com.BartyCrouch) which is the _successor_ to BartyCrouch. It improves upon several aspects of BartyCrouch, such as having **no flaky dependencies**, adding **pluralization** support, **smart** machine translation, a built-in SwiftUI-compatible **enum generator**, built-in **step-by-step instructions** for easier setup, **detailed explanations** of all config options, and even [**a set of video guides**](https://www.youtube.com/watch?v=ObGIiWARjmw&list=PLvkAveYAfY4TLPtPd5jnqMwpAzY_pdxs5) for things like setup, key naming best practices and team onboarding. Get it for free [here](https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=github.com.BartyCrouch&mt=8).
56+
>
57+
> Note that RemafoX is being **actively worked on**, you can even [vote for or request new features here](https://github.com/FlineDev/RemafoX/issues?q=is%3Aissue+label%3A%22Feature+Request%22+sort%3Areactions-%2B1-desc).
58+
> In comparison, BartyCrouch is kept up-to-date mostly by the community.
59+
60+
5361
# BartyCrouch
5462

5563
BartyCrouch **incrementally updates** your Strings files from your Code *and* from Interface Builder files. "Incrementally" means that BartyCrouch will by default **keep** both your already **translated values** and even your altered comments. Additionally you can also use BartyCrouch for **machine translating** from one language to 60+ other languages. Using BartyCrouch is as easy as **running a few simple commands** from the command line what can even be **automated using a [build script](#build-script)** within your project.
@@ -58,7 +66,7 @@ Checkout [this blog post](https://jeehut.medium.com/localization-in-swift-like-a
5866

5967
## Requirements
6068

61-
- Xcode 13.3+ & Swift 5.6+
69+
- Xcode 14+ & Swift 5.7+
6270
- Xcode Command Line Tools (see [here](http://stackoverflow.com/a/9329325/3451975) for installation instructions)
6371

6472
## Getting Started
@@ -258,12 +266,12 @@ tasks = ["interfaces", "code", "transform", "normalize"]
258266
- `localizablePaths`: The enclosing path(s) containing the localized `Localizable.strings` files.
259267
- `defaultToKeys`: Add new keys both as key and value.
260268
- `additive`: Prevents cleaning up keys not found in code.
261-
- `customFunction`: Use alternative name to `NSLocalizedString`.
269+
- `customFunction`: Use alternative name to search for strings to localize, in addition to `NSLocalizedString`, and `CFCopyLocalizedString`. Defaults to `LocalizedStringResource`.
262270
- `customLocalizableName`: Use alternative name for `Localizable.strings`.
263271
- `unstripped`: Keeps whitespaces at beginning & end of Strings files.
264272
- `plistArguments`: Use a plist file to store all the code files for the ExtractLocStrings tool. (Recommended for large projects.)
265273
- `ignoreKeys`: Keys (e.g. in the comment) indicating that specific translation entries should be ignored when generating String files.
266-
- `overrideComments`: Always overrides the comment with the keys new translation, useful for IB files.
274+
- `overrideComments`: Always overrides the comment with the keys new translation, useful for IB files.
267275

268276
</details>
269277

@@ -355,6 +363,40 @@ self.title = L10n.Onboarding.FirstPage.headerTitle
355363

356364
NOTE: As of version 4.x of BartyCrouch *formatted* localized Strings are not supported by this automatic feature.
357365

366+
### Localizing strings of `LocalizableStringResource` type (AppIntents, ...)
367+
368+
Historically, Apple platforms used `CFCopyLocalizedString`, and `NSLocalizedString` macros and their variants, to mark strings used in code to be localized, and to load their localized versions during runtime from `Localizable.strings` file.
369+
370+
Since introduction of the AppIntents framework, the localized strings in code can also be typed as `LocalizedStringResource`, and are no longer marked explicitly.
371+
372+
Let's examine this snippet of AppIntents code:
373+
374+
```
375+
struct ExportAllTransactionsIntent: AppIntent {
376+
static var title: LocalizedStringResource = "Export all transactions"
377+
378+
static var description =
379+
IntentDescription("Exports your transaction history as CSV data.")
380+
}
381+
```
382+
383+
In the example above, both the `"Export all transactions"`, and `"Exports your transaction history as CSV data."` are actually `StaticString` instances that will be converted during compilation into `LocalizedStringResource` instances, and will lookup their respective localizations during runtime from `Localized.strings` file the same way as when using `NSLocalizedString` in the past. The only exception being that such strings are not marked explicitly, and require swift compiler to parse and extract such strings for localization. This is what Xcode does from version 13 when using `Product -> Export Localizations...` option.
384+
385+
In order to continue translating these strings with `bartycrouch` it is required to mark them explicitely with `LocalizedStringResource(_: String, comment: String)` call, and specify `customFunction="LocalizedStringResource"` in `code` task options.
386+
387+
The example AppIntents code that can be localized with `bartycrouch` will look like this:
388+
389+
```
390+
struct ExportAllTransactionsIntent: AppIntent {
391+
static var title = LocalizedStringResource("Export all transactions", comment: "")
392+
393+
static var description =
394+
IntentDescription(LocalizedStringResource("Exports your transaction history as CSV data.", comment: ""))
395+
}
396+
```
397+
398+
Note that you must use the full form of `LocalizedStringResource(_: StaticString, comment: StaticString)` for the `bartycrouch`, or more specifically for the `extractLocStrings` (see `xcrun extractLocStrings`) to properly parse the strings.
399+
358400
### Build Script
359401

360402
In order to truly profit from BartyCrouch's ability to update & lint your `.strings` files you can make it a natural part of your development workflow within Xcode. In order to do this select your target, choose the `Build Phases` tab and click the + button on the top left corner of that pane. Select `New Run Script Phase` and copy the following into the text box below the `Shell: /bin/sh` of your new run script phase:
@@ -426,6 +468,11 @@ See the file [MIGRATION_GUIDES.md](https://github.com/FlineDev/BartyCrouch/blob/
426468

427469
Contributions are welcome. Feel free to open an issue on GitHub with your ideas or implement an idea yourself and post a pull request. If you want to contribute code, please try to follow the same syntax and semantic in your **commit messages** (see rationale [here](http://chris.beams.io/posts/git-commit/)). Also, please make sure to add an entry to the `CHANGELOG.md` file which explains your change.
428470

471+
In order for the tests to run build issues, you need to run – also add an an API key in the new file to run the translations tests, too:
472+
```shell
473+
cp Tests/BartyCrouchTranslatorTests/Secrets/secrets.json.sample Tests/BartyCrouchTranslatorTests/Secrets/secrets.json
474+
```
475+
429476
After Release Checklist:
430477

431478
1. Run `make portable_zip` to generate `.build/release/portable_bartycrouch.zip`

Sources/BartyCrouch/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SwiftCLI
55
// MARK: - CLI
66
let cli = CLI(
77
name: "bartycrouch",
8-
version: "4.13.0",
8+
version: "4.14.0",
99
description: "Incrementally update & translate your Strings files from code or interface files."
1010
)
1111

Sources/BartyCrouchConfiguration/Options/UpdateOptions/CodeOptions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension CodeOptions: TomlCodable {
2727
localizablePaths: toml.filePaths(update, code, singularKey: "localizablePath", pluralKey: "localizablePaths"),
2828
defaultToKeys: toml.bool(update, code, "defaultToKeys") ?? false,
2929
additive: toml.bool(update, code, "additive") ?? true,
30-
customFunction: toml.string(update, code, "customFunction"),
30+
customFunction: toml.string(update, code, "customFunction") ?? "LocalizedStringResource",
3131
customLocalizableName: toml.string(update, code, "customLocalizableName"),
3232
unstripped: toml.bool(update, code, "unstripped") ?? false,
3333
plistArguments: toml.bool(update, code, "plistArguments") ?? true,

Sources/BartyCrouchTranslator/DeeplApi/DeepLApi.swift

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum DeepLApi {
1616

1717
for text in texts {
1818
if currentBatch.count < maximumTextsPerRequest
19-
&& text.count + currentBatchTotalLength < maximumTextsLengthPerRequest
19+
&& text.count + currentBatchTotalLength < maximumTextsLengthPerRequest
2020
{
2121
currentBatch.append(text)
2222
currentBatchTotalLength += text.count
@@ -47,10 +47,6 @@ extension DeepLApi: Endpoint {
4747
return decoder
4848
}
4949

50-
var encoder: JSONEncoder {
51-
JSONEncoder()
52-
}
53-
5450
var subpath: String {
5551
switch self {
5652
case .translate:
@@ -59,25 +55,20 @@ extension DeepLApi: Endpoint {
5955
}
6056

6157
var method: HttpMethod {
62-
.get
63-
}
64-
65-
var queryParameters: [String: QueryParameterValue] {
66-
var urlParameters: [String: QueryParameterValue] = [:]
67-
6858
switch self {
69-
case let .translate(texts, sourceLanguage, targetLanguage, apiKey):
70-
urlParameters["text"] = .array(texts)
71-
urlParameters["source_lang"] = sourceLanguage.deepLParameterValue
72-
urlParameters["target_lang"] = targetLanguage.deepLParameterValue
73-
urlParameters["auth_key"] = .string(apiKey)
59+
case .translate(let texts, let sourceLanguage, let targetLanguage, let authKey):
60+
let textEntries = texts.map { "text=\($0.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)" }
61+
.joined(separator: "&")
62+
let authKeyEntry = "auth_key=\(authKey)"
63+
let sourceLanguageEntry = "source_lang=\(sourceLanguage.deepLParameterValue)"
64+
let targetLanguageEntry = "target_lang=\(targetLanguage.deepLParameterValue)"
65+
let bodyString = [authKeyEntry, sourceLanguageEntry, targetLanguageEntry, textEntries].joined(separator: "&")
66+
return .post(body: bodyString.data(using: .utf8)!)
7467
}
75-
76-
return urlParameters
7768
}
7869

7970
var headers: [String: String] {
80-
["Content-Type": "application/json"]
71+
["Content-Type": "application/x-www-form-urlencoded"]
8172
}
8273

8374
static func baseUrl(for apiType: ApiType) -> URL {
@@ -92,13 +83,13 @@ extension DeepLApi: Endpoint {
9283
}
9384

9485
private extension Language {
95-
var deepLParameterValue: QueryParameterValue {
86+
var deepLParameterValue: String {
9687
switch self {
9788
case .chineseSimplified:
98-
return .string("ZH")
89+
return "ZH"
9990

10091
default:
101-
return .string(rawValue.uppercased())
92+
return rawValue.uppercased()
10293
}
10394
}
10495
}

Sources/SupportingFiles/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>4.13.0</string>
18+
<string>4.14.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>

Tests/BartyCrouchConfigurationTests/ConfigurationTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConfigurationTests: XCTestCase {
2121
XCTAssertEqual(configuration.updateOptions.code.codePaths, ["."])
2222
XCTAssertEqual(configuration.updateOptions.code.localizablePaths, ["."])
2323
XCTAssertEqual(configuration.updateOptions.code.additive, true)
24-
XCTAssertEqual(configuration.updateOptions.code.customFunction, nil)
24+
XCTAssertEqual(configuration.updateOptions.code.customFunction, "LocalizedStringResource")
2525
XCTAssertEqual(configuration.updateOptions.code.customLocalizableName, nil)
2626
XCTAssertEqual(configuration.updateOptions.code.defaultToKeys, false)
2727
XCTAssertEqual(configuration.updateOptions.code.unstripped, false)
@@ -117,6 +117,7 @@ class ConfigurationTests: XCTestCase {
117117
XCTAssertEqual(configuration.updateOptions.code.customLocalizableName, "MyOwnLocalizable")
118118
XCTAssertEqual(configuration.updateOptions.code.defaultToKeys, true)
119119
XCTAssertEqual(configuration.updateOptions.code.unstripped, true)
120+
XCTAssertEqual(configuration.updateOptions.code.overrideComments, false)
120121

121122
XCTAssertEqual(configuration.updateOptions.transform.codePaths, ["Sources"])
122123
XCTAssertEqual(configuration.updateOptions.transform.localizablePaths, ["Sources/SupportingFiles"])
@@ -168,6 +169,7 @@ class ConfigurationTests: XCTestCase {
168169
unstripped = true
169170
plistArguments = true
170171
ignoreKeys = ["#bartycrouch-ignore!", "#bc-ignore!", "#i!"]
172+
overrideComments = false
171173
172174
[update.transform]
173175
codePaths = ["."]

0 commit comments

Comments
 (0)