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

[feature/xcstrings-build-normalization] Normalize xcstrings on every build #131

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows.inactive/normalizestrings.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/pull-transifex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ jobs:
beautifyJSON "ownCloudSDK/Resources/Localizable.xcstrings"
beautifyJSON "ownCloudUI/Resources/Localizable.xcstrings"

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y clang libpython2.7 libpython2.7-dev

- name: Download Swift
run: curl -o /tmp/swift-6.0.2-RELEASE-ubuntu20.04.tar.gz https://download.swift.org/swift-6.0.2-release/ubuntu2004/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE-ubuntu20.04.tar.gz

- name: Extract Swift
run: tar -xzf /tmp/swift-6.0.2-RELEASE-ubuntu20.04.tar.gz

- name: Move Swift to /usr/share
run: sudo mv swift-6.0.2-RELEASE-ubuntu20.04 /usr/share/swift

- name: Add Swift to PATH
run: echo "export PATH=/usr/share/swift/usr/bin:\$PATH" >> $GITHUB_ENV

- name: Verify Swift installation
run: swift -v

- name: Show Swift file
run: cat tools/ocstringstool/ocstringstool/main.swift

- name: Compile Swift file
run: swiftc tools/ocstringstool/ocstringstool/main.swift -o /tmp/ocstringstool

- name: Run compiled Swift program
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
Loading