Skip to content

Commit b62a705

Browse files
committed
♻️ cleanup
1 parent 67a384a commit b62a705

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

LocalizationEditor/Providers/LocalizationProvider.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ class LocalizationProvider {
5353
Log.debug?.message("Same value provided for \(string)")
5454
return
5555
}
56-
56+
5757
Log.debug?.message("Updating \(string) with \(value) in \(localization)")
58-
58+
5959
string.update(value: value)
60-
60+
6161
let data = localization.translations.map { string in
6262
"\"\(string.key)\" = \"\(string.value.replacingOccurrences(of: "\"", with: "\\\""))\";"
63-
}.reduce("") { (prev, next) in
64-
"\(prev)\n\(next)"
63+
}.reduce("") { prev, next in
64+
"\(prev)\n\(next)"
6565
}
66-
66+
6767
do {
6868
try data.write(toFile: localization.path, atomically: false, encoding: .utf8)
6969
Log.debug?.message("Localization file for \(localization) updated")

LocalizationEditor/Providers/LocalizationsDataSource.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ class LocalizationsDataSource: NSObject, NSTableViewDataSource {
1313

1414
// MARK: - Properties
1515

16-
private(set) var localizations: [Localization] = []
17-
16+
private var localizations: [Localization] = []
1817
private var masterLocalization: Localization?
1918
private let localizationProvider = LocalizationProvider()
2019
private var numberOfKeys = 0
2120

2221
// MARK: - Action
2322

24-
func load(folder: URL) {
23+
func load(folder: URL) -> [String] {
2524
localizations = localizationProvider.getLocalizations(url: folder)
2625
numberOfKeys = localizations.map({ $0.translations.count }).max() ?? 0
2726
masterLocalization = localizations.first(where: { $0.translations.count == numberOfKeys })
27+
return localizations.map({ $0.language })
2828
}
2929

3030
func getKey(row: Int) -> String? {

LocalizationEditor/UI/ViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ViewController: NSViewController {
4343
tableView.dataSource = dataSource
4444
}
4545

46-
func reloadData() {
46+
func reloadData(with languages: [String]) {
4747
let columns = tableView.tableColumns
4848
columns.forEach {
4949
self.tableView.removeTableColumn($0)
@@ -54,10 +54,10 @@ class ViewController: NSViewController {
5454
column.width = 200
5555
tableView.addTableColumn(column)
5656

57-
dataSource.localizations.forEach { localization in
58-
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier(localization.language))
59-
column.title = localization.language.uppercased()
60-
column.width = (self.view.bounds.width - 200.0) / CGFloat(self.dataSource.localizations.count)
57+
languages.forEach { language in
58+
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier(language))
59+
column.title = language.uppercased()
60+
column.width = (self.view.bounds.width - 200.0) / CGFloat(languages.count)
6161
self.tableView.addTableColumn(column)
6262
}
6363

@@ -73,8 +73,8 @@ class ViewController: NSViewController {
7373
openPanel.begin { [unowned self] (result) -> Void in
7474
if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
7575
if let url = openPanel.url {
76-
self.dataSource.load(folder: url)
77-
self.reloadData()
76+
let languages = self.dataSource.load(folder: url)
77+
self.reloadData(with: languages)
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)