From 54017be9c3e7b9a029cab50c72b5733669038a92 Mon Sep 17 00:00:00 2001 From: Felix Schwarz Date: Thu, 5 Dec 2024 22:19:14 +0100 Subject: [PATCH] - remove unused .github/workflows.inactive/normalizestrings.yml - ocstringstool: update to normalize xcstrings - ownCloudSDK.xcodeproj: remove normalization step - pull-transifex.yml: integrate updated ocstringstool --- .../workflows.inactive/normalizestrings.yml | 28 ---------------- .github/workflows/pull-transifex.yml | 32 +++++++++++++++++++ ownCloudSDK.xcodeproj/project.pbxproj | 21 ------------ tools/ocstringstool/ocstringstool/main.swift | 25 +++++++++++---- 4 files changed, 51 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows.inactive/normalizestrings.yml diff --git a/.github/workflows.inactive/normalizestrings.yml b/.github/workflows.inactive/normalizestrings.yml deleted file mode 100644 index 4dfcedc4..00000000 --- a/.github/workflows.inactive/normalizestrings.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Normalize .strings files to UTF-8 -# This workflow is triggered on pushes to the repository. -on: - push: - branches: - - fix/* - - feature/* - - milestone/* - - translation-sync - -jobs: - build: - runs-on: macos-latest - name: Update Configuration Documentation - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - name: Xcode version - run: /usr/bin/xcodebuild -version - - name: Run Generate Docs - run: ./normalizestrings.sh - working-directory: ./tools/normalizestrings/ - - name: Commit files - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Normalized .strings files to UTF-8 - file_pattern: *.strings diff --git a/.github/workflows/pull-transifex.yml b/.github/workflows/pull-transifex.yml index 56d77ba1..868eaa0a 100644 --- a/.github/workflows/pull-transifex.yml +++ b/.github/workflows/pull-transifex.yml @@ -31,6 +31,38 @@ 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: wget 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 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 ocstringstool + + - name: Run compiled Swift program + run: ./ocstringstool normalize "ownCloudSDK/Resources" "ownCloudUI/Resources" + + - name: Cleanup download and ocstringstool + run: | + rm swift-*-ubuntu20.04.tar.gz + rm ocstringstool + - uses: GuillaumeFalourd/git-commit-push@v1.3 with: email: devops@owncloud.com diff --git a/ownCloudSDK.xcodeproj/project.pbxproj b/ownCloudSDK.xcodeproj/project.pbxproj index ca27f761..5067d0e3 100644 --- a/ownCloudSDK.xcodeproj/project.pbxproj +++ b/ownCloudSDK.xcodeproj/project.pbxproj @@ -4902,7 +4902,6 @@ DCC8F9A8202852A200EB6701 /* Headers */, DCC8F9A9202852A200EB6701 /* Resources */, DC102FAD22D3E0F300DEBC38 /* Update LastGitCommit key in Info.plist */, - DC86F8572CF345AA00D757DA /* Normalize xcstrings files */, ); buildRules = ( ); @@ -5113,26 +5112,6 @@ shellPath = /bin/sh; shellScript = "LASTGITCOMMIT=$(git rev-parse --short HEAD)\ndefaults write \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}\" \"LastGitCommit\" \"${LASTGITCOMMIT}\"\n\nGITTAGS=$(git describe --tags)\ndefaults write \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}\" \"GitTags\" \"${GITTAGS}\"\n\nGITBRANCH=$(git branch --show-current)\ndefaults write \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}\" \"GitBranch\" \"${GITBRANCH}\"\n"; }; - DC86F8572CF345AA00D757DA /* Normalize xcstrings files */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "$(SRCROOT)/ownCloudSDK/Resources/Localizable.xcstrings", - "$(SRCROOT)/ownCloudUI/Resources/Localizable.xcstrings", - ); - name = "Normalize xcstrings files"; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/bash; - shellScript = "if ! command -v jq 2>&1 >/dev/null\nthen\n echo \"jq could not be found\"\n exit 0\nfi\n\nbeautifyJSON() {\n 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\n mv $1.tmp $1\n}\nbeautifyJSON \"ownCloudSDK/Resources/Localizable.xcstrings\"\nbeautifyJSON \"ownCloudUI/Resources/Localizable.xcstrings\"\n"; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/tools/ocstringstool/ocstringstool/main.swift b/tools/ocstringstool/ocstringstool/main.swift index 09eb20e2..5ff52a5e 100644 --- a/tools/ocstringstool/ocstringstool/main.swift +++ b/tools/ocstringstool/ocstringstool/main.swift @@ -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 + } } } }