diff --git a/CalendarKit.podspec b/CalendarKit.podspec index 819db46f..9b1c453c 100644 --- a/CalendarKit.podspec +++ b/CalendarKit.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "CalendarKit" s.summary = "Fully customizable calendar for iOS" - s.version = "0.11.1" + s.version = "0.11.2" s.homepage = "https://github.com/richardtop/CalendarKit" s.license = 'MIT' s.author = { "Richard Topchii" => "richardtop@users.noreply.github.com" } @@ -11,6 +11,7 @@ Pod::Spec.new do |s| s.swift_version = '5.1' s.requires_arc = true s.source_files = 'Source/**/*' + s.ios.resource_bundle = { 'CalendarKit' => ['Localizations/*.lproj'] } s.dependency 'DateToolsSwift' s.dependency 'Neon' end diff --git a/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj b/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj index d515433f..b35f5178 100644 --- a/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj +++ b/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 75776AF58133F6BBDDCF1CE7 /* Pods_CalendarApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */; }; 7924834B23CB7B57003E3D27 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834923CB7B57003E3D27 /* Main.storyboard */; }; 7924834D23CB7B58003E3D27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7924834C23CB7B58003E3D27 /* Assets.xcassets */; }; 7924835023CB7B58003E3D27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834E23CB7B58003E3D27 /* LaunchScreen.storyboard */; }; @@ -16,7 +17,6 @@ 7924836C23CB7BFE003E3D27 /* CustomCalendarExampleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */; }; 7924836D23CB7BFE003E3D27 /* ExampleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836723CB7BFE003E3D27 /* ExampleController.swift */; }; 7924836E23CB7BFE003E3D27 /* ExampleNotificationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836823CB7BFE003E3D27 /* ExampleNotificationController.swift */; }; - DFA7CAE4CAC5C89EE8AF6696 /* Pods_CalendarApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A05C820D1C9D1BE2E012F4DF /* Pods_CalendarApp.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,7 +32,7 @@ 7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomCalendarExampleController.swift; sourceTree = ""; }; 7924836723CB7BFE003E3D27 /* ExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleController.swift; sourceTree = ""; }; 7924836823CB7BFE003E3D27 /* ExampleNotificationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleNotificationController.swift; sourceTree = ""; }; - A05C820D1C9D1BE2E012F4DF /* Pods_CalendarApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CalendarApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CalendarApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FEBA81B9D67F9FBBA5381D09 /* Pods-CalendarApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CalendarApp.debug.xcconfig"; path = "Target Support Files/Pods-CalendarApp/Pods-CalendarApp.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -41,7 +41,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - DFA7CAE4CAC5C89EE8AF6696 /* Pods_CalendarApp.framework in Frameworks */, + 75776AF58133F6BBDDCF1CE7 /* Pods_CalendarApp.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -96,7 +96,7 @@ D2B9A4777F5DB09BCFA26C1E /* Frameworks */ = { isa = PBXGroup; children = ( - A05C820D1C9D1BE2E012F4DF /* Pods_CalendarApp.framework */, + A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */, ); name = Frameworks; sourceTree = ""; @@ -112,7 +112,7 @@ 7924833C23CB7B57003E3D27 /* Sources */, 7924833D23CB7B57003E3D27 /* Frameworks */, 7924833E23CB7B57003E3D27 /* Resources */, - 7016FF6EA52C87C95AE483A7 /* [CP] Embed Pods Frameworks */, + 5A00DDEECC79568B66DC9F20 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -193,7 +193,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 7016FF6EA52C87C95AE483A7 /* [CP] Embed Pods Frameworks */ = { + 5A00DDEECC79568B66DC9F20 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( diff --git a/CalendarKitDemo/CalendarApp.xcodeproj/xcshareddata/xcschemes/CalendarApp.xcscheme b/CalendarKitDemo/CalendarApp.xcodeproj/xcshareddata/xcschemes/CalendarApp.xcscheme new file mode 100644 index 00000000..53cd6008 --- /dev/null +++ b/CalendarKitDemo/CalendarApp.xcodeproj/xcshareddata/xcschemes/CalendarApp.xcscheme @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Localizations/da.lproj/Localizable.strings b/Localizations/da.lproj/Localizable.strings new file mode 100644 index 00000000..a6112064 --- /dev/null +++ b/Localizations/da.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "heldag"; +"12:00" = "Middag"; diff --git a/Localizations/de.lproj/Localizable.strings b/Localizations/de.lproj/Localizable.strings new file mode 100644 index 00000000..5b934ca1 --- /dev/null +++ b/Localizations/de.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "Ganztägig"; +"12:00" = "Mittag"; diff --git a/Localizations/en.lproj/Localizable.strings b/Localizations/en.lproj/Localizable.strings new file mode 100644 index 00000000..72c57d28 --- /dev/null +++ b/Localizations/en.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "all-day"; +"12:00" = "Noon"; diff --git a/Localizations/es.lproj/Localizable.strings b/Localizations/es.lproj/Localizable.strings new file mode 100644 index 00000000..7dac4c0d --- /dev/null +++ b/Localizations/es.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "todo el día"; +"12:00" = "12:00; diff --git a/Localizations/fr.lproj/Localizable.strings b/Localizations/fr.lproj/Localizable.strings new file mode 100644 index 00000000..4045433f --- /dev/null +++ b/Localizations/fr.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "Jour entier"; +"12:00" = "Midi"; diff --git a/Localizations/nl.lproj/Localizable.strings b/Localizations/nl.lproj/Localizable.strings new file mode 100644 index 00000000..858b18f0 --- /dev/null +++ b/Localizations/nl.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "hele dag"; +"12:00" = "12 PM"; diff --git a/Localizations/ru.lproj/Localizable.strings b/Localizations/ru.lproj/Localizable.strings new file mode 100644 index 00000000..36fa249c --- /dev/null +++ b/Localizations/ru.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "весь день"; +"12:00" = "12:00"; diff --git a/Localizations/sv.lproj/Localizable.strings b/Localizations/sv.lproj/Localizable.strings new file mode 100644 index 00000000..adf8ed30 --- /dev/null +++ b/Localizations/sv.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"all-day" = "heldag"; +"12:00" = "12:00"; diff --git a/Source/Localization.swift b/Source/Localization.swift new file mode 100644 index 00000000..249c2b8e --- /dev/null +++ b/Source/Localization.swift @@ -0,0 +1,19 @@ +import Foundation + +extension Bundle { + static var localizationBundle: Bundle? { + let bundle = Bundle(for: DayViewController.self) + guard let bundlePath = bundle.path(forResource: "CalendarKit", + ofType: "bundle"), + let targetBundle = Bundle(path: bundlePath) else { + return nil + } + return targetBundle + } +} + +func localizedString(_ key: String) -> String { + return Bundle.localizationBundle?.localizedString(forKey: key, + value: nil, + table: nil) ?? key +} diff --git a/Source/Timeline/AllDayView.swift b/Source/Timeline/AllDayView.swift index 38941682..5bc6bca3 100644 --- a/Source/Timeline/AllDayView.swift +++ b/Source/Timeline/AllDayView.swift @@ -18,9 +18,8 @@ public class AllDayView: UIView { private lazy var textLabel: UILabel = { let label = UILabel(frame: CGRect(x: 8.0, y: 4.0, width: allDayLabelWidth, height: 24.0)) - label.text = "all-day" + label.text = localizedString("all-day") label.autoresizingMask = [.flexibleWidth] - return label }() diff --git a/Source/Timeline/Generator.swift b/Source/Timeline/TimeStringsFactory.swift similarity index 54% rename from Source/Timeline/Generator.swift rename to Source/Timeline/TimeStringsFactory.swift index 774fdc4d..48efcc9a 100644 --- a/Source/Timeline/Generator.swift +++ b/Source/Timeline/TimeStringsFactory.swift @@ -1,7 +1,13 @@ import Foundation -enum Generator { - static func timeStrings24H() -> [String] { +struct TimeStringsFactory { + private let calendar: Calendar + + init(_ calendar: Calendar = Calendar.autoupdatingCurrent) { + self.calendar = calendar + } + + func make24hStrings() -> [String] { var numbers = [String]() numbers.append("00:00") @@ -15,7 +21,7 @@ enum Generator { return numbers } - static func timeStrings12H() -> [String] { + func make12hStrings() -> [String] { var numbers = [String]() numbers.append("12") @@ -24,9 +30,10 @@ enum Generator { numbers.append(string) } - var am = numbers.map { $0 + " AM" } - var pm = numbers.map { $0 + " PM" } - am.append("Noon") + var am = numbers.map { $0 + " " + calendar.amSymbol} + var pm = numbers.map { $0 + " " + calendar.pmSymbol} + + am.append(localizedString("12:00")) pm.removeFirst() pm.append(am.first!) return am + pm diff --git a/Source/Timeline/TimelineView.swift b/Source/Timeline/TimelineView.swift index 2f4e0159..dea3faba 100644 --- a/Source/Timeline/TimelineView.swift +++ b/Source/Timeline/TimelineView.swift @@ -110,6 +110,7 @@ public class TimelineView: UIView { didSet { snappingBehavior = snappingBehaviorType.init(calendar) nowLine.calendar = calendar + regenerateTimeStrings() setNeedsLayout() } } @@ -128,8 +129,14 @@ public class TimelineView: UIView { return is24hClock ? _24hTimes : _12hTimes } - fileprivate lazy var _12hTimes: [String] = Generator.timeStrings12H() - fileprivate lazy var _24hTimes: [String] = Generator.timeStrings24H() + private lazy var _12hTimes: [String] = TimeStringsFactory(calendar).make12hStrings() + private lazy var _24hTimes: [String] = TimeStringsFactory(calendar).make24hStrings() + + private func regenerateTimeStrings() { + let factory = TimeStringsFactory(calendar) + _12hTimes = factory.make12hStrings() + _24hTimes = factory.make24hStrings() + } public lazy var longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPress(_:)))