Skip to content

Commit

Permalink
- normalizestrings: add xcstrings normalization support
Browse files Browse the repository at this point in the history
- pull-transifex.yml: add normalizestrings xcstrings normalization
  • Loading branch information
felix-schwarz committed Dec 5, 2024
1 parent 828f78e commit c047ba9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/pull-transifex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
shell: bash
run: |
beautifyJSON() {
jq --sort-keys . "$1" >"$1.tmp"
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 "ownCloud Action Extension/InfoPlist.xcstrings"
Expand All @@ -35,6 +35,30 @@ jobs:
beautifyJSON "ownCloud/Resources/Localizable.xcstrings"
beautifyJSON "ownCloudAppFramework/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: Compile Swift file
run: swiftc tools/normalizestrings/main.swift -o /tmp/ocstringstool

- name: Run compiled Swift program
run: /tmp/ocstringstool normalize "ownCloud/Resources" "ownCloud Action Extension" "ownCloud File Provider" "ownCloud Share Extension" "ownCloudAppFramework/Resources"

- uses: GuillaumeFalourd/[email protected]
with:
email: [email protected]
Expand Down
25 changes: 19 additions & 6 deletions tools/normalizestrings/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.absoluteString) 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

0 comments on commit c047ba9

Please sign in to comment.