ReadKeep/readeck/Data/Utils/LabelUtils.swift
Ilyas Hallak d6ea56cfa9 feat: Add comprehensive i18n support and Legal & Privacy section
- Create String+Localization extension with .localized property
- Add LabelUtils for consistent label splitting and deduplication logic
- Implement Legal & Privacy settings section with Privacy Policy and Legal Notice views
- Add German/English localization for all navigation states and settings sections
- Fix navigationDestination placement warning in PadSidebarView
- Unify label input handling across main app and share extension
- Support for space-separated label input in share extension

Navigation & Settings now fully localized:
- All/Unread/Favorites/Archive → Alle/Ungelesen/Favoriten/Archiv
- Font/Appearance/Cache/General/Server Settings → German equivalents
- Legal section with GitHub issue reporting and email support contact
2025-09-20 22:14:17 +02:00

29 lines
1.3 KiB
Swift

import Foundation
struct LabelUtils {
/// Splits a label input string by spaces and returns individual trimmed labels
/// - Parameter input: The input string containing one or more labels separated by spaces
/// - Returns: Array of individual trimmed labels, excluding empty strings
static func splitLabelsFromInput(_ input: String) -> [String] {
return input
.components(separatedBy: " ")
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { !$0.isEmpty }
}
/// Filters out labels that already exist in current or available labels
/// - Parameters:
/// - labels: Array of labels to filter
/// - currentLabels: Currently selected labels
/// - availableLabels: Available labels (optional)
/// - Returns: Array of unique labels that don't already exist
static func filterUniqueLabels(_ labels: [String], currentLabels: [String], availableLabels: [String] = []) -> [String] {
let currentSet = Set(currentLabels.map { $0.lowercased() })
let availableSet = Set(availableLabels.map { $0.lowercased() })
return labels.filter { label in
let lowercased = label.lowercased()
return !currentSet.contains(lowercased) && !availableSet.contains(lowercased)
}
}
}