diff --git a/DHBW-Service.xcodeproj/project.pbxproj b/DHBW-Service.xcodeproj/project.pbxproj index dce52e3..285cd09 100644 --- a/DHBW-Service.xcodeproj/project.pbxproj +++ b/DHBW-Service.xcodeproj/project.pbxproj @@ -19,6 +19,9 @@ CDCD72242591316500FBF2F5 /* LocalSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCD72232591316500FBF2F5 /* LocalSettings.swift */; }; CDCD7230259135C500FBF2F5 /* FirstOpeningSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCD722F259135C500FBF2F5 /* FirstOpeningSettings.swift */; }; CDDCF47B2591FE550027CDC5 /* UtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDDCF47A2591FE550027CDC5 /* UtilityFunctions.swift */; }; + CDDCF4842592028A0027CDC5 /* Localizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDDCF4832592028A0027CDC5 /* Localizer.swift */; }; + CDDCF493259203390027CDC5 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CDDCF495259203390027CDC5 /* Localizable.strings */; }; + CDDCF4A2259203B40027CDC5 /* General.strings in Resources */ = {isa = PBXBuildFile; fileRef = CDDCF4A4259203B40027CDC5 /* General.strings */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -57,6 +60,11 @@ CDCD72232591316500FBF2F5 /* LocalSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalSettings.swift; sourceTree = ""; }; CDCD722F259135C500FBF2F5 /* FirstOpeningSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstOpeningSettings.swift; sourceTree = ""; }; CDDCF47A2591FE550027CDC5 /* UtilityFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilityFunctions.swift; sourceTree = ""; }; + CDDCF4832592028A0027CDC5 /* Localizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Localizer.swift; sourceTree = ""; }; + CDDCF494259203390027CDC5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; + CDDCF4992592033F0027CDC5 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = ""; }; + CDDCF4A3259203B40027CDC5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/General.strings; sourceTree = ""; }; + CDDCF4A8259203B80027CDC5 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/General.strings; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -174,6 +182,7 @@ CDCD721225912D6300FBF2F5 /* Supporting Files */ = { isa = PBXGroup; children = ( + CDDCF482259202700027CDC5 /* l10n */, CD9FAB8E258EC60600D6D0C5 /* Info.plist */, CD9FAB84258EC60600D6D0C5 /* Assets.xcassets */, ); @@ -212,6 +221,16 @@ path = Utility; sourceTree = ""; }; + CDDCF482259202700027CDC5 /* l10n */ = { + isa = PBXGroup; + children = ( + CDDCF4832592028A0027CDC5 /* Localizer.swift */, + CDDCF495259203390027CDC5 /* Localizable.strings */, + CDDCF4A4259203B40027CDC5 /* General.strings */, + ); + path = l10n; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -297,6 +316,7 @@ knownRegions = ( en, Base, + de, ); mainGroup = CD9FAB74258EC60100D6D0C5; productRefGroup = CD9FAB7E258EC60200D6D0C5 /* Products */; @@ -316,6 +336,8 @@ buildActionMask = 2147483647; files = ( CD9FAB88258EC60600D6D0C5 /* Preview Assets.xcassets in Resources */, + CDDCF4A2259203B40027CDC5 /* General.strings in Resources */, + CDDCF493259203390027CDC5 /* Localizable.strings in Resources */, CD9FAB85258EC60600D6D0C5 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -341,6 +363,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDDCF4842592028A0027CDC5 /* Localizer.swift in Sources */, CDCD7230259135C500FBF2F5 /* FirstOpeningSettings.swift in Sources */, CD9FAB8A258EC60600D6D0C5 /* Persistence.swift in Sources */, CD9FAB83258EC60200D6D0C5 /* ContentView.swift in Sources */, @@ -383,6 +406,27 @@ }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + CDDCF495259203390027CDC5 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + CDDCF494259203390027CDC5 /* en */, + CDDCF4992592033F0027CDC5 /* de */, + ); + name = Localizable.strings; + sourceTree = ""; + }; + CDDCF4A4259203B40027CDC5 /* General.strings */ = { + isa = PBXVariantGroup; + children = ( + CDDCF4A3259203B40027CDC5 /* en */, + CDDCF4A8259203B80027CDC5 /* de */, + ); + name = General.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ CD9FABA5258EC60600D6D0C5 /* Debug */ = { isa = XCBuildConfiguration; diff --git a/DHBW-Service/Supporting Files/l10n/Localizer.swift b/DHBW-Service/Supporting Files/l10n/Localizer.swift new file mode 100644 index 0000000..6d44df5 --- /dev/null +++ b/DHBW-Service/Supporting Files/l10n/Localizer.swift @@ -0,0 +1,30 @@ +// +// Localizer.swift +// DHBW-Service +// +// Created by Patrick Müller on 22.12.20. +// + +import Foundation + +private class Localizer { + + static let sharedInstance = Localizer() + + func localize(string: String, tableName: String, plural: Bool) -> String { + var localizedString: String + if plural{ + localizedString = NSLocalizedString(string, tableName: tableName, value:"**\(self)**", comment: "plural") + }else{ + localizedString = NSLocalizedString(string, tableName: tableName, value:"**\(self)**", comment: "") + } + + return localizedString + } +} + +extension String { + func localized(tableName: String = "Localizable", plural: Bool) -> String { + return Localizer.sharedInstance.localize(string: self, tableName: tableName, plural: plural) + } +} diff --git a/DHBW-Service/Supporting Files/l10n/de.lproj/General.strings b/DHBW-Service/Supporting Files/l10n/de.lproj/General.strings new file mode 100644 index 0000000..b75ca20 --- /dev/null +++ b/DHBW-Service/Supporting Files/l10n/de.lproj/General.strings @@ -0,0 +1,10 @@ +/* + General.strings + DHBW-Service + + Created by Patrick Müller on 22.12.20. + +*/ +"name" = "Name"; +"course" = "Kurs"; +"director" = "Studiengangsleiter"; diff --git a/DHBW-Service/Supporting Files/l10n/de.lproj/Localizable.strings b/DHBW-Service/Supporting Files/l10n/de.lproj/Localizable.strings new file mode 100644 index 0000000..68c82fe --- /dev/null +++ b/DHBW-Service/Supporting Files/l10n/de.lproj/Localizable.strings @@ -0,0 +1,7 @@ +/* + Localizable.strings + DHBW-Service + + Created by Patrick Müller on 22.12.20. + +*/ diff --git a/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings b/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings new file mode 100644 index 0000000..69266d5 --- /dev/null +++ b/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings @@ -0,0 +1,10 @@ +/* + General.strings + DHBW-Service + + Created by Patrick Müller on 22.12.20. + +*/ +"name" = "Name"; +"course" = "Course"; +"director" = "Director"; diff --git a/DHBW-Service/Supporting Files/l10n/en.lproj/Localizable.strings b/DHBW-Service/Supporting Files/l10n/en.lproj/Localizable.strings new file mode 100644 index 0000000..68c82fe --- /dev/null +++ b/DHBW-Service/Supporting Files/l10n/en.lproj/Localizable.strings @@ -0,0 +1,7 @@ +/* + Localizable.strings + DHBW-Service + + Created by Patrick Müller on 22.12.20. + +*/ diff --git a/DHBW-Service/Views/Other/FirstOpeningSettings.swift b/DHBW-Service/Views/Other/FirstOpeningSettings.swift index 2e1d4d6..dc39d0e 100644 --- a/DHBW-Service/Views/Other/FirstOpeningSettings.swift +++ b/DHBW-Service/Views/Other/FirstOpeningSettings.swift @@ -17,17 +17,17 @@ struct FirstOpeningSettings: View { var body: some View { VStack { - TextField("Name", text: self.$name) + TextField("name".localized(tableName: "General", plural: false), text: self.$name) .textContentType(.name) .textFieldStyle(RoundedBorderTextFieldStyle()) .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) .padding(.horizontal) - TextField("Course", text: self.$course) + TextField("course".localized(tableName: "General", plural: false), text: self.$course) .textContentType(.name) .textFieldStyle(RoundedBorderTextFieldStyle()) .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) .padding(.horizontal) - TextField("Director", text: self.$director) + TextField("director".localized(tableName: "General", plural: false), text: self.$director) .textContentType(.name) .textFieldStyle(RoundedBorderTextFieldStyle()) .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center)