diff --git a/.github/workflows/normalize-strings.yml b/.github/workflows/normalize-strings.yml deleted file mode 100644 index aa7e82ab2..000000000 --- a/.github/workflows/normalize-strings.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Normalize .strings file encoding -# This workflow is triggered on pushes to the repository. -on: - push: - branches: - - fix/* - - feature/* - - milestone/* - - translation-sync - -jobs: - build: - runs-on: macos-13 - name: Normalize .strings file encoding - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - name: Xcode version - run: /usr/bin/xcodebuild -version - - name: Normalize .strings files to UTF-8 - run: ./normalizestrings.sh - working-directory: ./tools/normalizestrings/ - - name: Commit files - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Normalized Localizable.strings encoding (UTF-8) - file_pattern: '*.strings' diff --git a/.github/workflows/run-in-docker.sh b/.github/workflows/run-in-docker.sh new file mode 100644 index 000000000..e70c30bcc --- /dev/null +++ b/.github/workflows/run-in-docker.sh @@ -0,0 +1,32 @@ +#! /bin/bash + +image="$1" +shift + +commands="$@" + +if [[ "$image" == "" ]] || [[ "${commands[@]}" == "" ]]; then + echo "Usage: bash $0 " + exit 1 +fi + +set -exo pipefail + +extra_args=() + +if tty -s; then + extra_args+=("-t") +fi + +docker run \ + --rm \ + --user "$(id -u)" \ + -i "${extra_args[@]}" \ + -e TX_TOKEN \ + -e HOME \ + -v "$HOME:$HOME" \ + -v "$(readlink -f .)":/ws \ + --entrypoint sh \ + -w /ws \ + "$image" \ + -c "${commands[@]}" diff --git a/.github/workflows/translate.yml b/.github/workflows/translate.yml new file mode 100644 index 000000000..5cea53454 --- /dev/null +++ b/.github/workflows/translate.yml @@ -0,0 +1,88 @@ +name: "Update translations" + +on: + workflow_dispatch: + schedule: + - cron: "0 3 * * *" + push: + branches: + - master + +permissions: {} + +defaults: + run: + shell: pwsh + +jobs: + update-translations: + permissions: + contents: write # for git push + runs-on: ubuntu-latest + + env: + TX_TOKEN: ${{ secrets.TX_TOKEN }} + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + ref: ${{ github.ref }} + + - name: l10n-push + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # we need to use a different docker image for those two, this appears to be a bit tricky with github actions out of the box + run: bash .github/workflows/run-in-docker.sh owncloudci/transifex:latest "cd ownCloud/Resources/en.lproj && tx push -s --skip" + + - name: l10n-pull + run: bash .github/workflows/run-in-docker.sh owncloudci/transifex:latest "cd ownCloud/Resources/ && tx pull --force --skip --all" + + - 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://swift.org/builds/swift-5.3-release/ubuntu2004/swift-5.3-RELEASE/swift-5.3-RELEASE-ubuntu20.04.tar.gz + + - name: Extract Swift + run: tar xzf swift-5.3-RELEASE-ubuntu20.04.tar.gz + + - name: Move Swift to /usr/share + run: sudo mv swift-5.3-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 ocstringstool + + - name: Run compiled Swift program + run: ./ocstringstool normalize ownCloud/Resources/ + + - name: update-repo-before-commit + run: | + git status + git add ownCloud/Resources/*.strings + git status + git stash + git pull --ff-only origin + + - name: commit and push + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + run: | + install -d -m 0700 ~/.ssh + Set-Content -Value "${{ secrets.DEPLOYMENT_SSH_KEY }}" -Path ~/.ssh/id_ed25519 + chmod 0600 ~/.ssh/id_ed25519 + if(git stash list) { + git stash pop + install -d -m 0700 ~/.ssh + Set-Content -Value "${{ secrets.DEPLOYMENT_SSH_KEY }}" -Path ~/.ssh/id_ed25519 + chmod 0600 ~/.ssh/id_ed25519 + git config user.name "ownClouders" + git config user.email "devops@owncloud.com" + git add translations/ + git commit -m "[tx] updated client translations from transifex [skip ci]" + git push git@github.com:owncloud/ios-app.git + } diff --git a/.tx/config b/.tx/config index 61d785d57..0c1a406e0 100644 --- a/.tx/config +++ b/.tx/config @@ -1,5 +1,6 @@ [main] host = https://www.transifex.com +minimum_perc = 75 [o:owncloud-org:p:owncloud:r:mobile-ios-app] file_filter = ownCloud/Resources/.lproj/Localizable.strings diff --git a/tools/normalizestrings/main.swift b/tools/normalizestrings/main.swift new file mode 100644 index 000000000..05074fccf --- /dev/null +++ b/tools/normalizestrings/main.swift @@ -0,0 +1,79 @@ +// +// main.swift +// ocstringstool +// +// Created by Felix Schwarz on 24.08.23. +// Copyright © 2023 ownCloud GmbH. All rights reserved. +// + +/* + * Copyright (C) 2023, ownCloud GmbH. + * + * This code is covered by the GNU Public License Version 3. + * + * For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/ + * You should have received a copy of this license along with this program. If not, see . + * + */ + +import Foundation + +// MARK: - Types +enum Command: String { + case normalize +} + +// MARK: - Parsing +if CommandLine.argc < 3 { + print("ocstringstool normalize [base folder 1] …") + exit(0) +} + +let arguments = CommandLine.arguments +let command = Command(rawValue: arguments[1]) +var argIdx = 2 + +switch command { + case .normalize: + while argIdx < CommandLine.argc { + let rootPath = arguments[argIdx] + commandNormalize(rootPath: rootPath) + argIdx += 1 + } + + default: + print("Unknown command \(command?.rawValue ?? "")") + exit(-1) +} + +// MARK: - Commands +func commandNormalize(rootPath locRootPath: String) { + let locRootURL = NSURL(fileURLWithPath: locRootPath) + var convertedFilesCount = 0 + + print("[normalize] scanning \(locRootURL.path ?? locRootPath)") + + if let enumerator = FileManager.default.enumerator(at: locRootURL as URL, includingPropertiesForKeys: [ .isDirectoryKey, .nameKey ]) { + for case let fileURL as URL in enumerator { + guard let resourceValues = try? fileURL.resourceValues(forKeys: [.isDirectoryKey, .nameKey]), + let isDirectory = resourceValues.isDirectory, + let fileName = resourceValues.name + else { + continue + } + + 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 + } + } + } + } + + print("[normalize] converted \(convertedFilesCount) files in \(locRootURL.path ?? locRootPath)") +} diff --git a/tools/normalizestrings/normalizestrings.sh b/tools/normalizestrings/normalizestrings.sh deleted file mode 100755 index 3bf6e4f5f..000000000 --- a/tools/normalizestrings/normalizestrings.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Build ocstringstool -cd ../../ios-sdk/tools/ocstringstool/ -./build_tool.sh -cd ../normalizestrings -cd ../../../tools/normalizestrings/ -mv ../../ios-sdk/tools/ocstringstool/tool ./ocstringstool -chmod u+x ./ocstringstool - -# Perform normalization -echo "Normalizing…" -./ocstringstool normalize ../../ownCloud/Resources/ - -# Remove ocstringstool build -rm ./ocstringstool - -echo "Done." -