mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2026-04-28 18:30:09 +00:00
Adding Localization
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
General.strings
|
||||
DHBW-Service
|
||||
|
||||
Created by Patrick Müller on 22.12.20.
|
||||
|
||||
*/
|
||||
"name" = "Name";
|
||||
"course" = "Kurs";
|
||||
"director" = "Studiengangsleiter";
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
Localizable.strings
|
||||
DHBW-Service
|
||||
|
||||
Created by Patrick Müller on 22.12.20.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
General.strings
|
||||
DHBW-Service
|
||||
|
||||
Created by Patrick Müller on 22.12.20.
|
||||
|
||||
*/
|
||||
"name" = "Name";
|
||||
"course" = "Course";
|
||||
"director" = "Director";
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
Localizable.strings
|
||||
DHBW-Service
|
||||
|
||||
Created by Patrick Müller on 22.12.20.
|
||||
|
||||
*/
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user