Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/xcstrings-format] xcstrings normalization to Xcode style #134

Merged
merged 8 commits into from
Dec 20, 2024
28 changes: 0 additions & 28 deletions .github/workflows.inactive/normalizestrings.yml

This file was deleted.

15 changes: 13 additions & 2 deletions .github/workflows/pull-transifex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@ jobs:
shell: bash
run: |
beautifyJSON() {
jq --sort-keys 'walk(if type == "object" then del(."th_TH", ."pt_PT", ."pt_BR", ."nn_NO", ."nb_NO", ."en_GB") else . end)' $1 >$1.tmp
mv $1.tmp $1
jq --sort-keys 'walk(if type == "object" then del(."th_TH", ."pt_PT", ."pt_BR", ."nn_NO", ."nb_NO", ."en_GB") else . end)' "$1" >"$1.tmp"
mv "$1.tmp" "$1"
}
beautifyJSON "ownCloudSDK/Resources/Localizable.xcstrings"
beautifyJSON "ownCloudUI/Resources/Localizable.xcstrings"

- name: Setup Swift
uses: swift-actions/setup-swift@v2.1.0

- name: Build ocstringstool
run: |
swift -v
swiftc tools/ocstringstool/ocstringstool/main.swift -o /tmp/ocstringstool

- name: Run ocstringstool
run: /tmp/ocstringstool normalize "ownCloudSDK/Resources" "ownCloudUI/Resources"

- uses: GuillaumeFalourd/git-commit-push@v1.3
with:
email: devops@owncloud.com
Expand Down
25 changes: 19 additions & 6 deletions tools/ocstringstool/ocstringstool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,25 @@ func commandNormalize(rootPath locRootPath: String) {

var encoding: String.Encoding = .utf8

if !isDirectory, fileName.hasSuffix(".strings"),
let strings = try? String(contentsOf: fileURL, usedEncoding: &encoding), encoding != .utf8 {
print("[normalize] converting \(fileURL.path(percentEncoded: false)) to UTF-8…")
if let utf8Data = strings.data(using: .utf8, allowLossyConversion: false) {
try? utf8Data.write(to: fileURL)
convertedFilesCount += 1
if !isDirectory {
if fileName.hasSuffix(".strings"),
let strings = try? String(contentsOf: fileURL, usedEncoding: &encoding), encoding != .utf8 {
print("[normalize] converting \(fileURL.absoluteString) to UTF-8…")
if let utf8Data = strings.data(using: .utf8, allowLossyConversion: false) {
try? utf8Data.write(to: fileURL)
convertedFilesCount += 1
}
}

if fileName.hasSuffix(".xcstrings"),
let data = try? Data(contentsOf: fileURL),
let jsonObj = try? JSONSerialization.jsonObject(with: data) {
print("[normalize] normalizing \(fileURL.absoluteString) to AppleJSON[sortedKeys,prettyPrinted,withoutEscapingSlashes]…")

if let reformattedJSONData = try? JSONSerialization.data(withJSONObject: jsonObj, options: [.sortedKeys, .prettyPrinted, .withoutEscapingSlashes]) {
try? reformattedJSONData.write(to: fileURL)
convertedFilesCount += 1
}
}
}
}
Expand Down