Skip to content

Commit

Permalink
Merge pull request #24 from stelabouras/feature/excluded-files
Browse files Browse the repository at this point in the history
Introduce excluded files option
  • Loading branch information
Nikos Vasileiou authored Aug 21, 2023
2 parents 0411e2e + 5b38a52 commit 9df4fbb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
13 changes: 12 additions & 1 deletion Sources/TXCli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ the CDS server.
""")
private var appendTags: [String] = []

@Option(name: .long, parsing: .upToNextOption, help: """
An optional list of localizable files that the logic must exclude when
processing the exported strings.
""")
private var excludedFiles: [String] = []

@Flag(name: .long, inversion: .prefixedEnableDisable,
exclusivity: .exclusive, help: """
Control whether the keys of strings to be pushed should be hashed (true) or not
Expand Down Expand Up @@ -213,7 +219,12 @@ Emulate a content push, without doing actual changes.
throw CommandError.xliffParsingFailure
}

let filteredResults = XLIFFParser.filter(parser.results)
var excludeFilenames = XLIFFParser.UNSUPPORTED_FILES
excludeFilenames.append(contentsOf: excludedFiles)

let filteredResults = XLIFFParser.filter(parser.results,
excludeFilenames: excludedFiles,
logHandler: logHandler)

var translations: [TXSourceString] = []

Expand Down
28 changes: 20 additions & 8 deletions Sources/TXCliLib/XLIFFParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,33 +301,45 @@ public class XLIFFParser: NSObject {
return true
}

private static let EXCLUDE_FILENAMES = [
/// List of string filenames that Transifex SDK does not support.
public static let UNSUPPORTED_FILES = [
"InfoPlist.strings",
"Root.strings"
]

/// Filters results by excluding translation units that their `files` array lists filenames that cannot be
/// handled by the Transifex SDK (`EXCLUDE_FILENAMES`).
/// Filters results by excluding translation units that their `files` array lists filenames that are included
/// in the provided `excludeFilenames` array.
///
/// If the `files` array includes a filename that is not part of the above array, then that translation
/// If the `files` array includes a filename that is not part of the provided array, then that translation
/// unit is not filtered out.
///
/// Ref: https://transifex.github.io/transifex-swift/#special-cases
///
/// - Parameter results: The parser results
/// - Parameter results: The parser results.
/// - Parameter excludeFilenames: List of filenames that their translation units must be
/// excluded.
/// - Parameter logHandler: Optional log handler for logging purposes.
/// - Returns: Array of filtered results that do not contain translation units that are included in the
/// `SKIP_FILENAMES` files.
public static func filter(_ results: [TranslationUnit]) -> [TranslationUnit] {
public static func filter(_ results: [TranslationUnit],
excludeFilenames: [String],
logHandler: TXLogHandler? = nil) -> [TranslationUnit] {
return results.filter { translationUnit in
var excludedFilenameCount = 0
for file in translationUnit.files {
for excludeFilename in EXCLUDE_FILENAMES {
for excludeFilename in excludeFilenames {
if file.contains(excludeFilename) {
excludedFilenameCount += 1
}
}
}
return excludedFilenameCount != translationUnit.files.count
let isIncluded = excludedFilenameCount != translationUnit.files.count
if let logHandler = logHandler, !isIncluded {
logHandler.verbose("""
[prompt]Excluding \(translationUnit) due to --excluded-files argument.[end]
""")
}
return isIncluded
}
}

Expand Down

0 comments on commit 9df4fbb

Please sign in to comment.