Skip to content

Commit

Permalink
feat: Localization 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhyunm committed Sep 16, 2023
1 parent 6c3541f commit 2b7e4a2
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 50 deletions.
31 changes: 19 additions & 12 deletions Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
63E527352A9D7EBF0000FBA6 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */; };
63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527362A9D87660000FBA6 /* DiaryListTableViewCell.swift */; };
63E527392A9D97160000FBA6 /* DiaryDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527382A9D97160000FBA6 /* DiaryDetailViewController.swift */; };
BA1A55ED2A9D90810012C89D /* DateFormatter+.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */; };
BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDAE42A9F13A200D8D50B /* DecodingError.swift */; };
BABBDB342AA6D05A00D8D50B /* ShareDisplayable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDB332AA6D05A00D8D50B /* ShareDisplayable.swift */; };
BABBDB362AAD904100D8D50B /* CoreDataError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDB352AAD904100D8D50B /* CoreDataError.swift */; };
BAECB2CF2AB15742006B4A46 /* Key.plist in Resources */ = {isa = PBXBuildFile; fileRef = BAECB2CE2AB15742006B4A46 /* Key.plist */; };
BAECB2D12AB157CB006B4A46 /* NetworkConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAECB2D02AB157CB006B4A46 /* NetworkConfiguration.swift */; };
BAECB2D92AB18611006B4A46 /* DiaryV2.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = BAECB2D82AB18611006B4A46 /* DiaryV2.xcmappingmodel */; };
BAECB2DD2AB187D6006B4A46 /* ImageCachingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAECB2DC2AB187D6006B4A46 /* ImageCachingManager.swift */; };
BAECB2E12AB568A0006B4A46 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BAECB2E32AB568A0006B4A46 /* Localizable.strings */; };
C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE24284DF28600741E8F /* AppDelegate.swift */; };
C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE26284DF28600741E8F /* SceneDelegate.swift */; };
C739AE29284DF28600741E8F /* DiaryListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE28284DF28600741E8F /* DiaryListViewController.swift */; };
Expand All @@ -53,14 +53,16 @@
63E527362A9D87660000FBA6 /* DiaryListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryListTableViewCell.swift; sourceTree = "<group>"; };
63E527382A9D97160000FBA6 /* DiaryDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewController.swift; sourceTree = "<group>"; };
7B86D20E06F2B506DECF94F6 /* Pods-Diary.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Diary.release.xcconfig"; path = "Target Support Files/Pods-Diary/Pods-Diary.release.xcconfig"; sourceTree = "<group>"; };
BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+.swift"; sourceTree = "<group>"; };
BABBDAE42A9F13A200D8D50B /* DecodingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingError.swift; sourceTree = "<group>"; };
BABBDB332AA6D05A00D8D50B /* ShareDisplayable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareDisplayable.swift; sourceTree = "<group>"; };
BABBDB352AAD904100D8D50B /* CoreDataError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataError.swift; sourceTree = "<group>"; };
BAECB2CE2AB15742006B4A46 /* Key.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Key.plist; sourceTree = "<group>"; };
BAECB2D02AB157CB006B4A46 /* NetworkConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConfiguration.swift; sourceTree = "<group>"; };
BAECB2D82AB18611006B4A46 /* DiaryV2.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = DiaryV2.xcmappingmodel; sourceTree = "<group>"; };
BAECB2DC2AB187D6006B4A46 /* ImageCachingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCachingManager.swift; sourceTree = "<group>"; };
BAECB2E22AB568A0006B4A46 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
BAECB2E42AB568D2006B4A46 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
BAECB2E52AB568D2006B4A46 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
C739AE21284DF28600741E8F /* Diary.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Diary.app; sourceTree = BUILT_PRODUCTS_DIR; };
C739AE24284DF28600741E8F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C739AE26284DF28600741E8F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -150,14 +152,6 @@
path = Model;
sourceTree = "<group>";
};
63E5273E2A9ECD800000FBA6 /* Extension */ = {
isa = PBXGroup;
children = (
BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */,
);
path = Extension;
sourceTree = "<group>";
};
63E5273F2A9ECDA90000FBA6 /* Controller */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -215,6 +209,7 @@
C739AE18284DF28600741E8F = {
isa = PBXGroup;
children = (
BAECB2E32AB568A0006B4A46 /* Localizable.strings */,
63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */,
C739AE23284DF28600741E8F /* Diary */,
C739AE22284DF28600741E8F /* Products */,
Expand All @@ -236,7 +231,6 @@
children = (
632F74EE2AB14CF3003E1B97 /* Network */,
636B19AA2AA6C5C200B5242D /* Protocol */,
63E5273E2A9ECD800000FBA6 /* Extension */,
63E5273D2A9ECD660000FBA6 /* Model */,
BABBDAE62A9F13AE00D8D50B /* Error */,
63E5273F2A9ECDA90000FBA6 /* Controller */,
Expand Down Expand Up @@ -295,6 +289,7 @@
knownRegions = (
en,
Base,
ko,
);
mainGroup = C739AE18284DF28600741E8F;
productRefGroup = C739AE22284DF28600741E8F /* Products */;
Expand All @@ -311,6 +306,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BAECB2E12AB568A0006B4A46 /* Localizable.strings in Resources */,
BAECB2CF2AB15742006B4A46 /* Key.plist in Resources */,
63E527352A9D7EBF0000FBA6 /* .swiftlint.yml in Resources */,
C739AE34284DF28600741E8F /* LaunchScreen.storyboard in Resources */,
Expand Down Expand Up @@ -375,7 +371,6 @@
BAECB2DD2AB187D6006B4A46 /* ImageCachingManager.swift in Sources */,
63BB62822A9F109400524DCB /* DecodingManager.swift in Sources */,
632F74F22AB14D8D003E1B97 /* WeatherResult.swift in Sources */,
BA1A55ED2A9D90810012C89D /* DateFormatter+.swift in Sources */,
63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */,
C739AE2F284DF28600741E8F /* Diary.xcdatamodeld in Sources */,
BAECB2D12AB157CB006B4A46 /* NetworkConfiguration.swift in Sources */,
Expand All @@ -397,10 +392,20 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
BAECB2E32AB568A0006B4A46 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
BAECB2E22AB568A0006B4A46 /* en */,
BAECB2E52AB568D2006B4A46 /* ko */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
C739AE32284DF28600741E8F /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
C739AE33284DF28600741E8F /* Base */,
BAECB2E42AB568D2006B4A46 /* ko */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
Expand All @@ -412,6 +417,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
Expand Down Expand Up @@ -473,6 +479,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
Expand Down
5 changes: 2 additions & 3 deletions Diary.xcodeproj/xcshareddata/xcschemes/Diary.xcscheme
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -28,13 +28,12 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = "ko"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
37 changes: 24 additions & 13 deletions Diary/Controller/DiaryDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ final class DiaryDetailViewController: UIViewController, AlertDisplayable, Share

private func configureUI() {
view.backgroundColor = .systemBackground
self.title = DateFormatter().formatToString(from: Date(), with: "YYYY년 MM월 dd일")

let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .none
self.title = dateFormatter.string(from: diary.createdAt ?? Date())
view.addSubview(textView)
textView.delegate = self

Expand Down Expand Up @@ -102,7 +106,7 @@ final class DiaryDetailViewController: UIViewController, AlertDisplayable, Share
}

private func setupNavigationBarButton() {
let moreButton = UIBarButtonItem(title: ButtonNamespace.more,
let moreButton = UIBarButtonItem(title: NSLocalizedString("moreOptions", comment: ""),
style: .plain,
target: self,
action: #selector(showMoreOptions))
Expand All @@ -124,20 +128,22 @@ final class DiaryDetailViewController: UIViewController, AlertDisplayable, Share
}

private func showDeleteAlert() {
let cancelAction = UIAlertAction(title: ButtonNamespace.cancel, style: .cancel)
let deleteAction = UIAlertAction(title: ButtonNamespace.delete, style: .destructive) { [weak self] _ in
let cancelAction = UIAlertAction(title: NSLocalizedString("cancelOption", comment: ""),
style: .cancel)
let deleteAction = UIAlertAction(title: NSLocalizedString("deleteOption", comment: ""),
style: .destructive) { [weak self] _ in
guard let self else { return }
do {
try CoreDataManager.shared.deleteDiary(self.diary)
self.navigationController?.popViewController(animated: true)
} catch CoreDataError.deleteFailure {
let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel)
let cancelAction = UIAlertAction(title: NSLocalizedString("confirm", comment: ""), style: .cancel)
self.showAlert(title: CoreDataError.deleteFailure.alertTitle,
message: CoreDataError.deleteFailure.message,
actions: [cancelAction],
preferredStyle: .alert)
} catch {
let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel)
let cancelAction = UIAlertAction(title: NSLocalizedString("confirm", comment: ""), style: .cancel)
self.showAlert(title: CoreDataError.deleteFailure.alertTitle,
message: CoreDataError.unknown.message,
actions: [cancelAction],
Expand Down Expand Up @@ -167,17 +173,20 @@ extension DiaryDetailViewController {
@objc private func showMoreOptions() {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

let deleteAction = UIAlertAction(title: ButtonNamespace.deleteEnglish, style: .destructive) { [weak self] _ in
let deleteAction = UIAlertAction(title: NSLocalizedString("deleteOption", comment: ""),
style: .destructive) { [weak self] _ in
guard let self else { return }
self.showDeleteAlert()
}

let shareAction = UIAlertAction(title: ButtonNamespace.shareEnglish, style: .default) { [weak self] _ in
let shareAction = UIAlertAction(title: NSLocalizedString("shareOption", comment: ""),
style: .default) { [weak self] _ in
guard let self else { return }
self.shareDiary(self.diary)
}

let cancelAction = UIAlertAction(title: ButtonNamespace.cancelEnglish, style: .cancel)
let cancelAction = UIAlertAction(title: NSLocalizedString("cancelOption", comment: ""),
style: .cancel)

alertController.addAction(shareAction)
alertController.addAction(deleteAction)
Expand All @@ -199,13 +208,13 @@ extension DiaryDetailViewController: UITextViewDelegate {
do {
try CoreDataManager.shared.saveContext()
} catch CoreDataError.saveFailure {
let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel)
let cancelAction = UIAlertAction(title: NSLocalizedString("confirm", comment: ""), style: .cancel)
self.showAlert(title: CoreDataError.saveFailure.alertTitle,
message: CoreDataError.saveFailure.message,
actions: [cancelAction],
preferredStyle: .alert)
} catch {
let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel)
let cancelAction = UIAlertAction(title: NSLocalizedString("confirm", comment: ""), style: .cancel)
self.showAlert(title: CoreDataError.saveFailure.alertTitle,
message: CoreDataError.unknown.message,
actions: [cancelAction],
Expand Down Expand Up @@ -244,7 +253,8 @@ extension DiaryDetailViewController {
self.diary.weatherIcon = weatherIcon
} catch {
DispatchQueue.main.async {
let confirmAction = UIAlertAction(title: ButtonNamespace.confirm, style: .default)
let confirmAction = UIAlertAction(title: NSLocalizedString("confirm", comment: ""),
style: .default)
self.showAlert(title: AlertNamespace.networkErrorTitle,
message: nil,
actions: [confirmAction],
Expand All @@ -253,7 +263,8 @@ extension DiaryDetailViewController {
}
case .failure:
DispatchQueue.main.async {
let confirmAction = UIAlertAction(title: ButtonNamespace.confirm, style: .default)
let confirmAction = UIAlertAction(title: NSLocalizedString("confirm", comment: ""),
style: .default)
self.showAlert(title: AlertNamespace.networkErrorTitle,
message: nil,
actions: [confirmAction],
Expand Down
14 changes: 10 additions & 4 deletions Diary/Controller/DiaryListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ final class DiaryListViewController: UIViewController {
return tableView
}()

private let dateFormatter = DateFormatter()
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.timeStyle = .none

return formatter
}()

private let container = CoreDataManager.shared.persistentContainer
private var diaryList = [Diary]()

Expand All @@ -41,7 +48,7 @@ final class DiaryListViewController: UIViewController {

private func configureUI() {
view.backgroundColor = .systemBackground
self.title = "일기장"
self.title = NSLocalizedString("titleLabel", comment: "")

view.addSubview(tableView)

Expand Down Expand Up @@ -108,8 +115,7 @@ extension DiaryListViewController: UITableViewDataSource {
let body = diaryEntity.body?.split(separator: "\n").joined(separator: "\n") else {
return UITableViewCell()
}
let date = dateFormatter.formatToString(from: createdAt, with: "YYYY년 MM월 dd일")

let date = dateFormatter.string(from: createdAt)
cell.setModel(title: title, date: date, body: body, icon: diaryEntity.weatherIcon)

return cell
Expand Down
16 changes: 0 additions & 16 deletions Diary/Extension/DateFormatter+.swift

This file was deleted.

7 changes: 5 additions & 2 deletions Diary/Protocol/ShareDisplayable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ extension ShareDisplayable where Self: UIViewController {
let body = diary.body else {
return
}

let date = DateFormatter().formatToString(from: createdAt, with: "YYYY년 MM월 dd일")

let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .none
let date = dateFormatter.string(from: createdAt)
let shareText = """
제목: \(title)
작성일자: \(date)
Expand Down
1 change: 1 addition & 0 deletions Diary/View/ko.lproj/LaunchScreen.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"titleLabel" = "Diary";
"moreOptions" = "More";
"shareOption" = "Share...";
"deleteOption" = "Delete";
"cancelOption" = "Cancel";
"confirm" = "Confirm";
6 changes: 6 additions & 0 deletions ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"titleLabel" = "일기장";
"moreOptions" = "더보기";
"shareOption" = "공유하기";
"deleteOption" = "삭제";
"cancelOption" = "취소";
"confirm" = "확인";

0 comments on commit 2b7e4a2

Please sign in to comment.