Skip to content

Commit

Permalink
GH workflows:
Browse files Browse the repository at this point in the history
- add LocalizationTests with automatic UTF-16 to UTF-8 conversion
  • Loading branch information
felix-schwarz committed Aug 23, 2023
1 parent c41b0cc commit 0a47517
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/localization-utf8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Localizable.strings to UTF8
# This workflow is triggered on pushes to the repository.
on:
push:
branches:
- fix/*
- feature/*
- milestone/*

jobs:
build:
runs-on: macos-latest
name: Localizable.strings to UTF8
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Xcode version
run: /usr/bin/xcodebuild -version
- name: Run Localizations To UTF8
run: ./localizations_to_utf8.sh
working-directory: ./tools/LocalizationsToUTF8/
- name: Commit files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: converted Localizable.strings to UTF8
file_pattern: '*.strings'
12 changes: 12 additions & 0 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
DC60F2A629802ABE00905EC8 /* UINavigationItem+NavigationContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC60F2A529802ABE00905EC8 /* UINavigationItem+NavigationContent.swift */; };
DC60F2A829802B0900905EC8 /* NavigationContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC60F2A729802B0900905EC8 /* NavigationContent.swift */; };
DC60F2AA29802D5800905EC8 /* NavigationContentItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC60F2A929802D5800905EC8 /* NavigationContentItem.swift */; };
DC61450C2A96497D00BFF393 /* LocalizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC61450B2A96497D00BFF393 /* LocalizationTests.swift */; };
DC6179E728E0578400C7C4E0 /* OCFileProviderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = DC6179E528E0578400C7C4E0 /* OCFileProviderSettings.h */; settings = {ATTRIBUTES = (Public, ); }; };
DC6179E828E0578400C7C4E0 /* OCFileProviderSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = DC6179E628E0578400C7C4E0 /* OCFileProviderSettings.m */; };
DC625141225C904700736874 /* NSError+MessageResolution.m in Sources */ = {isa = PBXBuildFile; fileRef = DC625140225C904700736874 /* NSError+MessageResolution.m */; };
Expand Down Expand Up @@ -1316,6 +1317,7 @@
DC60F2A729802B0900905EC8 /* NavigationContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationContent.swift; sourceTree = "<group>"; };
DC60F2A929802D5800905EC8 /* NavigationContentItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationContentItem.swift; sourceTree = "<group>"; };
DC60F2AB29812A9B00905EC8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
DC61450B2A96497D00BFF393 /* LocalizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizationTests.swift; sourceTree = "<group>"; };
DC6179E528E0578400C7C4E0 /* OCFileProviderSettings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCFileProviderSettings.h; sourceTree = "<group>"; };
DC6179E628E0578400C7C4E0 /* OCFileProviderSettings.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCFileProviderSettings.m; sourceTree = "<group>"; };
DC62513F225C904700736874 /* NSError+MessageResolution.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSError+MessageResolution.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1826,6 +1828,7 @@
233BDEB3204FEFE500C06732 /* ownCloudTests */ = {
isa = PBXGroup;
children = (
DC61450A2A96495800BFF393 /* Localization */,
DC26ADBD2550C02F0059680D /* Metadata */,
233BDEB6204FEFE500C06732 /* Info.plist */,
);
Expand Down Expand Up @@ -2517,6 +2520,14 @@
path = "Navigation Content";
sourceTree = "<group>";
};
DC61450A2A96495800BFF393 /* Localization */ = {
isa = PBXGroup;
children = (
DC61450B2A96497D00BFF393 /* LocalizationTests.swift */,
);
path = Localization;
sourceTree = "<group>";
};
DC62F56A2925059E0095BB5D /* Connection */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4440,6 +4451,7 @@
files = (
39057AA4233BA7A60008E6C0 /* Intents.intentdefinition in Sources */,
DC26ADDE2550C0B20059680D /* MetadataDocumentationTests.swift in Sources */,
DC61450C2A96497D00BFF393 /* LocalizationTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 5 additions & 0 deletions ownCloud.xcodeproj/xcshareddata/xcschemes/ownCloud.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
value = "${PROJECT_DIR}/doc/CONFIGURATION.json"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "OC_LOCALIZATION_ROOT"
value = "${PROJECT_DIR}/ownCloud/Resources"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
Expand Down
5 changes: 4 additions & 1 deletion ownCloud/Resources/Theming/Branding.plist
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>server-locator.use</key>
<string>web-finger</string>
</dict>
</plist>
Binary file modified ownCloud/Resources/de.lproj/Localizable.strings
Binary file not shown.
Binary file not shown.
46 changes: 46 additions & 0 deletions ownCloudTests/Localization/LocalizationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// LocalizationTests.swift
// ownCloudTests
//
// Created by Felix Schwarz on 23.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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import XCTest

final class LocalizationTests: XCTestCase {
func testConvertLocalizableUTF16() throws {
if let locRootPath = ProcessInfo.processInfo.environment["OC_LOCALIZATION_ROOT"] {
let locRootURL = NSURL(fileURLWithPath: 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 {
if let utf8Data = strings.data(using: .utf8, allowLossyConversion: false) {
try? utf8Data.write(to: fileURL)
}
}
}
}
}
}
}
8 changes: 8 additions & 0 deletions tools/LocalizationsToUTF8/localizations_to_utf8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Run test to convert the app's Localizable.strings to UTF-8 where needed
xcodebuild test \
-project ../../ownCloud.xcodeproj \
-scheme ownCloud \
-destination 'platform=iOS Simulator,name=iPhone 14,OS=latest' \
-only-testing ownCloudTests/LocalizationTests/testConvertLocalizableUTF16

0 comments on commit 0a47517

Please sign in to comment.