Skip to content

Commit

Permalink
Merge branch 'release/4.1.1' into versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Apr 16, 2020
2 parents be24041 + da667cc commit 201b0b0
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 87 deletions.
2 changes: 1 addition & 1 deletion BartyCrouch.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "BartyCrouch"
s.version = "4.1.0"
s.version = "4.1.1"
s.summary = "Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files."

s.description = <<-DESC
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
### Security
- None.

## [4.1.1] - 2020-04-16
### Fixed
- Fixed crashes in projects with large number of files by introducing new `plist` file based approach for passing arguments. See the new `--plist-arguments` option. Will be automatically turned on when needed (many files in project).
Issues: [#92](https://github.com/Flinesoft/BartyCrouch/issues/92), [#99](https://github.com/Flinesoft/BartyCrouch/issues/99) | PRs: [#150](https://github.com/Flinesoft/BartyCrouch/pull/150), [#176](https://github.com/Flinesoft/BartyCrouch/pull/176) | Authors: [Christos Koninis](https://github.com/csknns), [Cihat Gündüz](https://github.com/Jeehut)

## [4.1.0] - 2020-04-10
### Added
- Added support for specifying multiple paths for all `path` options.
Expand Down
4 changes: 2 additions & 2 deletions Formula/bartycrouch.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Bartycrouch < Formula
desc "Incrementally update/translate your Strings files"
homepage "https://github.com/Flinesoft/BartyCrouch"
url "https://github.com/Flinesoft/BartyCrouch.git", :tag => "4.0.2", :revision => "7d4cfec9530c7364727a4461712b54909f8d4a90"
url "https://github.com/Flinesoft/BartyCrouch.git", :tag => "4.1.0", :revision => "be2404129aa6141b00a2e7fd61e7dd8ab088d1d6"
head "https://github.com/Flinesoft/BartyCrouch.git"

depends_on :xcode => ["10.2", :build]
depends_on :xcode => ["11.4", :build]

def install
system "make", "install", "prefix=#{prefix}"
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
<a href="https://www.codacy.com/gh/Flinesoft/BartyCrouch">
<img src="https://api.codacy.com/project/badge/Grade/7b34ad9193c2438aa32aa29a0490451f"/>
</a>
<a href="https://www.codacy.com/gh/Flinesoft/BartyCrouch">
<img src="https://api.codacy.com/project/badge/Coverage/7b34ad9193c2438aa32aa29a0490451f"/>
</a>
<a href="https://github.com/Flinesoft/BartyCrouch/releases">
<img src="https://img.shields.io/badge/Version-4.1.0-blue.svg"
alt="Version: 4.1.0">
<img src="https://img.shields.io/badge/Version-4.1.1-blue.svg"
alt="Version: 4.1.1">
</a>
<img src="https://img.shields.io/badge/Swift-5.2-FFAC45.svg"
alt="Swift: 5.2">
Expand Down Expand Up @@ -55,7 +58,7 @@ Checkout [this blog post](https://medium.com/@Jeehut/localization-in-swift-like-

## Requirements

- Xcode 10.2+ & Swift 5.0+
- Xcode 11.4+ & Swift 5.2+
- Xcode Command Line Tools (see [here](http://stackoverflow.com/a/9329325/3451975) for installation instructions)

## Getting Started
Expand Down Expand Up @@ -248,6 +251,7 @@ tasks = ["interfaces", "code", "transform", "normalize"]
- `customFunction`: Use alternative name to `NSLocalizedString`.
- `customLocalizableName`: Use alternative name for `Localizable.strings`.
- `unstripped`: Keeps whitespaces at beginning & end of Strings files.
- `plistArguments`: Use a plist file to store all the code files for the ExtractLocStrings tool. (Recommended for large projects.)

</details>

Expand Down
2 changes: 1 addition & 1 deletion Sources/BartyCrouch/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftCLI
// MARK: - CLI
let cli = CLI(
name: "bartycrouch",
version: "4.1.0",
version: "4.1.1",
description: "Incrementally update & translate your Strings files from code or interface files."
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct CodeOptions {
let customFunction: String?
let customLocalizableName: String?
let unstripped: Bool
let plistArguments: Bool
}

extension CodeOptions: TomlCodable {
Expand All @@ -23,7 +24,8 @@ extension CodeOptions: TomlCodable {
additive: toml.bool(update, code, "additive") ?? true,
customFunction: toml.string(update, code, "customFunction"),
customLocalizableName: toml.string(update, code, "customLocalizableName"),
unstripped: toml.bool(update, code, "unstripped") ?? false
unstripped: toml.bool(update, code, "unstripped") ?? false,
plistArguments: toml.bool(update, code, "plistArguments") ?? true
)
}

Expand All @@ -44,6 +46,7 @@ extension CodeOptions: TomlCodable {
}

lines.append("unstripped = \(unstripped)")
lines.append("plistArguments = \(plistArguments)")

return lines.joined(separator: "\n")
}
Expand Down
22 changes: 20 additions & 2 deletions Sources/BartyCrouchKit/OldCommandLine/CodeCommander.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public final class CodeCommander {
public static let shared = CodeCommander()

// MARK: - Instance Methods
public func export(stringsFilesToPath stringsFilePath: String, fromCodeInDirectoryPath codeDirectoryPath: String, customFunction: String?) throws {
public func export(
stringsFilesToPath stringsFilePath: String,
fromCodeInDirectoryPath codeDirectoryPath: String,
customFunction: String?,
usePlistArguments: Bool
) throws {
let files = try findFiles(in: codeDirectoryPath)
let customFunctionArgs = customFunction != nil ? ["-s", "\(customFunction!)"] : []

let arguments = ["extractLocStrings"] + files + ["-o", stringsFilePath] + customFunctionArgs + ["-q"]
let argumentsWithoutTheFiles = ["extractLocStrings"] + ["-o", stringsFilePath] + customFunctionArgs + ["-q"]

let arguments = try appendFiles(files, inListOfArguments: argumentsWithoutTheFiles, usePlistArguments: usePlistArguments)
try Task.run("/usr/bin/xcrun", arguments: arguments)
}

Expand Down Expand Up @@ -56,4 +63,15 @@ public final class CodeCommander {

return matchedFiles
}

// In the existing list of arguments it appends also the files arguments.
func appendFiles(_ files: [String], inListOfArguments existingArguments: [String], usePlistArguments: Bool) throws -> [String] {
if usePlistArguments {
let fileArgumentsPlistFile = try ExtractLocStrings().writeFilesArgumentsInPlist(files)
return existingArguments + ["-f", fileArgumentsPlistFile]
} else {
let completeArgumentList = existingArguments + files
return completeArgumentList
}
}
}
12 changes: 8 additions & 4 deletions Sources/BartyCrouchKit/OldCommandLine/CommandLineActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class CommandLineActor {
overrideComments: Bool,
unstripped: Bool,
customFunction: String?,
customLocalizableName: String?
customLocalizableName: String?,
usePlistArguments: Bool
) {
let localizableFileName = customLocalizableName ?? "Localizable"
let allLocalizableStringsFilePaths = localizables.flatMap {
Expand All @@ -47,7 +48,8 @@ public class CommandLineActor {
overrideComments: overrideComments,
unstripped: unstripped,
customFunction: customFunction,
localizableFileName: localizableFileName
localizableFileName: localizableFileName,
usePlistArguments: usePlistArguments
)
}

Expand Down Expand Up @@ -212,7 +214,8 @@ public class CommandLineActor {
overrideComments: Bool,
unstripped: Bool,
customFunction: String?,
localizableFileName: String
localizableFileName: String,
usePlistArguments: Bool
) {
for inputDirectoryPath in inputDirectoryPaths {
let extractedStringsFileDirectory = inputDirectoryPath + "/tmpstrings/"
Expand All @@ -228,7 +231,8 @@ public class CommandLineActor {
try CodeCommander.shared.export(
stringsFilesToPath: extractedStringsFileDirectory,
fromCodeInDirectoryPath: inputDirectoryPath,
customFunction: customFunction
customFunction: customFunction,
usePlistArguments: usePlistArguments
)
} catch {
print("Could not extract strings from Code in directory '\(inputDirectoryPath)'.", level: .error)
Expand Down
53 changes: 53 additions & 0 deletions Sources/BartyCrouchKit/OldCommandLine/ExtractLocStrings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Created by Christos Koninis on 25/09/2019.

import Foundation

/// Class to handle extractLocStrings's tool file argument list. It provides methods to serialize the file list to an argument plist file. See
/// https://github.com/Flinesoft/BartyCrouch/issues/92
class ExtractLocStrings {
/// extractLocStrings tools supports instead of passing files as arguments in the command line to pass a plist with the files. This is the format of that
/// plist.
struct File: Codable, Equatable {
var path: String
}
struct ArgumentsPlist: Codable, Equatable {
var files: [File] = []

init(filePaths: [String]) {
files = filePaths.map(File.init)
}
}

/// Serializes the extractLocStrings's file arguments to an argument plist file.
///
/// - Parameter files: A array containing the list of files.
/// - Returns: The argument plist file that contains the list of file arguments.
/// - Throws: An error if any value throws an error during plist encoding.
func writeFilesArgumentsInPlist(_ files: [String]) throws -> String {
let data = try encodeFilesArguments(files)
let tempPlistFilePath = createTemporaryArgumentsPlistFile()
try data.write(to: tempPlistFilePath)

return tempPlistFilePath.path
}

/// Serializes the extractLocStrings's file arguments to byte array
///
/// - Parameter files: A array containing the list of files.
/// - Returns: A plist encoded value of the supplied array
func encodeFilesArguments(_ files: [String]) throws -> Data {
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml

return try encoder.encode(ArgumentsPlist(filePaths: files))
}

private func createTemporaryArgumentsPlistFile() -> URL {
let temporaryFilename = ProcessInfo().globallyUniqueString
var temporaryPath = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
temporaryPath.appendPathComponent(temporaryFilename)
temporaryPath.appendPathExtension("plist")

return temporaryPath
}
}
3 changes: 2 additions & 1 deletion Sources/BartyCrouchKit/TaskHandlers/CodeTaskHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extension CodeTaskHandler: TaskHandler {
overrideComments: false,
unstripped: options.unstripped,
customFunction: options.customFunction,
customLocalizableName: options.customLocalizableName
customLocalizableName: options.customLocalizableName,
usePlistArguments: options.plistArguments
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.1.0</string>
<string>4.1.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
29 changes: 29 additions & 0 deletions Tests/BartyCrouchKitTests/CommandLine/ExtractLocStringsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Created by Christos Koninis on 25/09/2019.

@testable import BartyCrouchKit
import XCTest

// swiftlint:disable force_try

class ExtractLocStringsTests: XCTestCase {
func testEncodedArgumentPlistFormat() {
let files = ["file.m", "otherfile.swift", "/path/of/anotherfile.swift"]
// Disabling whitespace_comment_start due to false positives
// swiftlint:disable whitespace_comment_start
let expectedArgumentsPlistString = """
<?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><key>files</key><array><dict><key>path</key><string>file.m</string></dict><dict><key>path</key><string>otherfile.swift\
</string></dict><dict><key>path</key><string>/path/of/anotherfile.swift</string></dict></array></dict></plist>
"""

let argumentsPlistData = try! ExtractLocStrings().encodeFilesArguments(files)
let argumentsPlist = try! argumentsPlistFromData(argumentsPlistData)
let expectedArgumentsPlist = try! argumentsPlistFromData(expectedArgumentsPlistString.data(using: .utf8)!)

XCTAssertEqual(argumentsPlist, expectedArgumentsPlist)
}

private func argumentsPlistFromData(_ data: Data) throws -> ExtractLocStrings.ArgumentsPlist {
return try PropertyListDecoder().decode(ExtractLocStrings.ArgumentsPlist.self, from: data)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class ConfigurationTests: XCTestCase {
customFunction = "MyOwnLocalizedString"
customLocalizableName = "MyOwnLocalizable"
unstripped = true
plistArguments = true
[update.transform]
codePaths = ["."]
Expand Down

0 comments on commit 201b0b0

Please sign in to comment.