Skip to content

Commit f77f68a

Browse files
authored
Рефактор локализации (#20)
- Применил новые настройки для генерации локализации - Переезд на String(localized:)
1 parent 5123a62 commit f77f68a

25 files changed

+483
-102
lines changed

SwiftUI-Days.xcodeproj/project.pbxproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
attributes = {
189189
BuildIndependentTargetsInParallel = 1;
190190
LastSwiftUpdateCheck = 1610;
191-
LastUpgradeCheck = 1630;
191+
LastUpgradeCheck = 2600;
192192
TargetAttributes = {
193193
6717F8CD2BBEA5F700A32083 = {
194194
CreatedOnToolsVersion = 15.3;
@@ -434,6 +434,7 @@
434434
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
435435
MTL_FAST_MATH = YES;
436436
ONLY_ACTIVE_ARCH = YES;
437+
STRING_CATALOG_GENERATE_SYMBOLS = YES;
437438
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
438439
SWIFT_EMIT_LOC_STRINGS = YES;
439440
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -494,6 +495,7 @@
494495
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
495496
MTL_ENABLE_DEBUG_INFO = NO;
496497
MTL_FAST_MATH = YES;
498+
STRING_CATALOG_GENERATE_SYMBOLS = YES;
497499
SWIFT_COMPILATION_MODE = wholemodule;
498500
SWIFT_EMIT_LOC_STRINGS = YES;
499501
SWIFT_VERSION = 6.0;
@@ -512,8 +514,10 @@
512514
CURRENT_PROJECT_VERSION = 1;
513515
DEAD_CODE_STRIPPING = YES;
514516
DEVELOPMENT_ASSET_PATHS = "\"SwiftUI-Days/Preview Content\"";
517+
ENABLE_APP_SANDBOX = YES;
515518
ENABLE_HARDENED_RUNTIME = YES;
516519
ENABLE_PREVIEWS = YES;
520+
ENABLE_USER_SELECTED_FILES = readonly;
517521
GENERATE_INFOPLIST_FILE = YES;
518522
INFOPLIST_FILE = "SwiftUI-Days/SupportingFiles/Info.plist";
519523
INFOPLIST_KEY_CFBundleDisplayName = Days;
@@ -534,7 +538,7 @@
534538
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
535539
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
536540
MACOSX_DEPLOYMENT_TARGET = 14.0;
537-
MARKETING_VERSION = 1.10;
541+
MARKETING_VERSION = 1.11;
538542
PRODUCT_BUNDLE_IDENTIFIER = "com.oleg991.SwiftUI-Days";
539543
PRODUCT_NAME = "$(TARGET_NAME)";
540544
SDKROOT = auto;
@@ -560,8 +564,10 @@
560564
CURRENT_PROJECT_VERSION = 1;
561565
DEAD_CODE_STRIPPING = YES;
562566
DEVELOPMENT_ASSET_PATHS = "\"SwiftUI-Days/Preview Content\"";
567+
ENABLE_APP_SANDBOX = YES;
563568
ENABLE_HARDENED_RUNTIME = YES;
564569
ENABLE_PREVIEWS = YES;
570+
ENABLE_USER_SELECTED_FILES = readonly;
565571
GENERATE_INFOPLIST_FILE = YES;
566572
INFOPLIST_FILE = "SwiftUI-Days/SupportingFiles/Info.plist";
567573
INFOPLIST_KEY_CFBundleDisplayName = Days;
@@ -582,7 +588,7 @@
582588
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
583589
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
584590
MACOSX_DEPLOYMENT_TARGET = 14.0;
585-
MARKETING_VERSION = 1.10;
591+
MARKETING_VERSION = 1.11;
586592
PRODUCT_BUNDLE_IDENTIFIER = "com.oleg991.SwiftUI-Days";
587593
PRODUCT_NAME = "$(TARGET_NAME)";
588594
SDKROOT = auto;

SwiftUI-Days.xcodeproj/xcshareddata/xcschemes/SwiftUI-Days.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1630"
3+
LastUpgradeVersion = "2600"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

SwiftUI-Days.xcodeproj/xcshareddata/xcschemes/SwiftUI-DaysUITests.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1630"
3+
LastUpgradeVersion = "2600"
44
version = "2.2">
55
<BuildAction
66
parallelizeBuildables = "YES"

SwiftUI-Days/Models/AppTheme.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ enum AppTheme: Int, CaseIterable, Identifiable {
66
case light = 1
77
case dark = 2
88

9-
var title: LocalizedStringResource {
9+
var title: String {
1010
switch self {
11-
case .system: "System"
12-
case .light: "Light"
13-
case .dark: "Dark"
11+
case .system: String(localized: .system)
12+
case .light: String(localized: .light)
13+
case .dark: String(localized: .dark)
1414
}
1515
}
1616

SwiftUI-Days/Models/DisplayOption.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ enum DisplayOption: String, Codable, CaseIterable, Hashable {
1616
}
1717

1818
/// Локализованное название формата отображения
19-
var localizedTitle: LocalizedStringKey {
19+
var localizedTitle: String {
2020
switch self {
21-
case .day: "Days only"
22-
case .monthDay: "Months and days"
23-
case .yearMonthDay: "Years, months and days"
21+
case .day: String(localized: .daysOnly)
22+
case .monthDay: String(localized: .monthsAndDays)
23+
case .yearMonthDay: String(localized: .yearsMonthsAndDays)
2424
}
2525
}
2626
}

SwiftUI-Days/Models/Item.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class Item {
3838
let yearsCount = components.year ?? 0
3939
let monthsCount = components.month ?? 0
4040
let daysCount = components.day ?? 0
41-
let todayString = String(localized: "Today")
41+
let todayString = String(localized: .today)
4242
guard yearsCount != 0 || monthsCount != 0 || daysCount != 0 else {
4343
return todayString
4444
}

SwiftUI-Days/Models/SortOrder+.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import SwiftUI
22

33
extension SortOrder {
4-
var name: LocalizedStringKey {
4+
var name: String {
55
switch self {
6-
case .forward: "Old first"
7-
case .reverse: "New first"
6+
case .forward: String(localized: .oldFirst)
7+
case .reverse: String(localized: .newFirst)
88
}
99
}
1010
}

SwiftUI-Days/Screens/CommonViews/SectionTitleView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import SwiftUI
22

33
struct SectionTitleView: View {
44
@Environment(\.isEnabled) private var isEnabled
5-
private let title: LocalizedStringKey
5+
private let title: String
66

7-
init(_ title: LocalizedStringKey) {
7+
init(_ title: String) {
88
self.title = title
99
}
1010

@@ -17,10 +17,10 @@ struct SectionTitleView: View {
1717
}
1818

1919
#Preview(traits: .sizeThatFitsLayout) {
20-
let titleStringKeys: [LocalizedStringKey] = [
21-
"Title",
22-
"Details",
23-
"Add color tag"
20+
let titleStringKeys: [String] = [
21+
String(localized: "Title"),
22+
String(localized: "Details"),
23+
String(localized: "Add color tag")
2424
]
2525
VStack(spacing: 20) {
2626
ForEach(

SwiftUI-Days/Screens/Detail/EditItemScreen.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct EditItemScreen: View {
4646
.accessibilityIdentifier(backButtonAccessibilityIdentifier)
4747
}
4848
ToolbarItem(placement: .topBarTrailing) {
49-
Button("Save") {
49+
Button(.save) {
5050
save()
5151
closeAction()
5252
}
@@ -58,8 +58,8 @@ struct EditItemScreen: View {
5858

5959
private var titleSection: some View {
6060
EditSectionView(
61-
headerText: "Title",
62-
placeholder: "Title for the Item",
61+
headerText: String(localized: .title),
62+
placeholder: String(localized: .titleForTheItem),
6363
text: $title
6464
)
6565
.focused($isFirstFieldFocused)
@@ -68,8 +68,8 @@ struct EditItemScreen: View {
6868

6969
private var detailsSection: some View {
7070
EditSectionView(
71-
headerText: "Details",
72-
placeholder: "Details for the Item",
71+
headerText: String(localized: .details),
72+
placeholder: String(localized: .detailsForTheItem),
7373
text: $details
7474
)
7575
}
@@ -87,12 +87,12 @@ struct EditItemScreen: View {
8787
}
8888
),
8989
label: {
90-
SectionTitleView("Add color tag")
90+
SectionTitleView(String(localized: .addColorTag))
9191
}
9292
)
9393
if let colorTag {
9494
ColorPicker(
95-
"Color tag",
95+
.colorTag,
9696
selection: .init(
9797
get: { colorTag },
9898
set: { self.colorTag = $0 }
@@ -112,12 +112,12 @@ struct EditItemScreen: View {
112112
ItemDisplayOptionPicker(displayOption: $displayOption)
113113
}
114114

115-
private var navigationTitle: LocalizedStringKey {
116-
oldItem == nil ? "New Item" : "Edit Item"
115+
private var navigationTitle: String {
116+
oldItem == nil ? String(localized: .newItem) : String(localized: .editItem)
117117
}
118118

119-
private var backButtonTitle: LocalizedStringKey {
120-
oldItem == nil ? "Close" : "Cancel"
119+
private var backButtonTitle: String {
120+
oldItem == nil ? String(localized: .close) : String(localized: .cancel)
121121
}
122122

123123
private var backButtonAccessibilityIdentifier: String {

SwiftUI-Days/Screens/Detail/EditSectionView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import SwiftUI
22

33
struct EditSectionView: View {
4-
let headerText: LocalizedStringKey
5-
let placeholder: LocalizedStringKey
4+
let headerText: String
5+
let placeholder: String
66
@Binding var text: String
77

88
var body: some View {
@@ -23,8 +23,8 @@ struct EditSectionView: View {
2323

2424
#Preview {
2525
EditSectionView(
26-
headerText: "Title",
27-
placeholder: "Title for the Item",
26+
headerText: String(localized: "Title"),
27+
placeholder: String(localized: "Title for the Item"),
2828
text: .constant("Событие, которое очень хочется запомнить, и никак нельзя забывать, например, первая поездка на велосипеде")
2929
)
3030
}

0 commit comments

Comments
 (0)