Skip to content

Commit

Permalink
more localisation support
Browse files Browse the repository at this point in the history
  • Loading branch information
pdtxie committed Aug 14, 2024
1 parent 1b88514 commit 16db474
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 71 deletions.
4 changes: 2 additions & 2 deletions CubeTime/Helper/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let sessionTypeForID: [SessionType: Session.Type] = [
let sessionDescriptions: [SessionType: String] = [
.multiphase: String(localized: "A multiphase session gives you the ability to breakdown your solves into sections, such as memo/exec stages in blindfolded solving or stages in 3x3 solves.\n\nTap anywhere on the timer during a solve to record a phase lap. You can access your breakdown statistics in each time card and view overall statistics in the Stats view."),
.playground: String(localized: "A playground session allows you to quickly change the scramble type within a session without having to specify a scramble type for the whole session."),
.compsim: String(localized: "A comp sim (Competition Simulation) session mimics a competition scenario better by recording a non-rolling session. Your solves will be split up into averages of 5 that can be accessed in your times and statistics view.\n\nStart by choosing a target to reach.")
.compsim: String(localized: "A compsim (Competition Simulation) session mimics a competition scenario better by recording a non-rolling session. Your solves will be split up into averages of 5 that can be accessed in your times and statistics view.\n\nStart by choosing a target to reach.")
]


Expand Down Expand Up @@ -321,7 +321,7 @@ func getAvgOfSolveGroup(_ compsimsolvegroup: CompSimSolveGroup) -> CalculatedAve
let trimmedSolves: [Solve] = sorted.prefix(trim) + sorted.suffix(trim)

return CalculatedAverage(
name: "Comp Sim",
name: "Compsim",
average: sorted.dropFirst(trim).dropLast(trim)
.reduce(0, { $0 + $1.timeIncPen }) / Double(3),
accountedSolves: sorted,
Expand Down
5 changes: 3 additions & 2 deletions CubeTime/Helper/HelperButtons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,15 @@ struct ContextMenuButton: View {
}

var body: some View {
Button(role: title == "Delete Session" ? .destructive : nil, action: delayedAction) {
Button(role: systemImage == "trash" ? .destructive : nil, action: delayedAction) {
HStack {
Text(title)
if image != nil {
Image(uiImage: image!)
}
}
}.disabled(disableButton ?? false)
}
.disabled(disableButton ?? false)
}

private var image: UIImage? {
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extension CompSimSolveGroup {
}

var avg: CalculatedAverage? {
return StopwatchManager.getCalculatedAverage(forSolves: self.solves!.allObjects as! [Solve], name: String(localized: "Comp Sim Group"), isCompsim: true)
return StopwatchManager.getCalculatedAverage(forSolves: self.solves!.allObjects as! [Solve], name: String(localized: "Compsim Group"), isCompsim: true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Onboarding/Updates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let updatesList: [String: (majorAdditions: [ListPoint]?,
bugFixes: [
ListPoint(1, "fixed various dynamic type bugs"),
ListPoint(1, "fixed calculator tool bugs"),
ListPoint(1, "fixed comp sim crashing"),
ListPoint(1, "fixed compsim crashing"),
ListPoint(1, "fixed time distribution crashing"),
ListPoint(1, "fixed inverted iPad trackpad gesture to show penalty bar"),
ListPoint(1, "fixed select all only selected shown solves"),
Expand Down
14 changes: 7 additions & 7 deletions CubeTime/Sessions/NewSessionRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,29 @@ struct NewSessionRootView: View {


VStack(alignment: .leading, spacing: 48) {
NewSessionTypeCardGroup(title: "Normal Sessions") {
NewSessionTypeCardGroup(title: String(localized: "Normal Sessions")) {
NavigationLink(destination: NewSessionView(sessionType: SessionType.standard, typeName: "Standard", showNewSessionPopUp: $showNewSessionPopUp)) {
NewSessionTypeCard(name: "Standard Session", icon: SessionTypeIcon(iconName: "timer.square"))
NewSessionTypeCard(name: String(localized: "Standard Session"), icon: SessionTypeIcon(iconName: "timer.square"))
}

CTDivider()
.padding(.leading, 48)

NavigationLink(destination: NewSessionView(sessionType: SessionType.multiphase, typeName: "Multiphase", showNewSessionPopUp: $showNewSessionPopUp)) {
NewSessionTypeCard(name: "Multiphase", icon: SessionTypeIcon(size: 24, iconName: "square.stack", padding: (10, 6)))
NewSessionTypeCard(name: String(localized: "Multiphase"), icon: SessionTypeIcon(size: 24, iconName: "square.stack", padding: (10, 6)))
}

CTDivider()
.padding(.leading, 48)

NavigationLink(destination: NewSessionView(sessionType: SessionType.playground, typeName: "Playground", showNewSessionPopUp: $showNewSessionPopUp)) {
NewSessionTypeCard(name: "Playground", icon: SessionTypeIcon(size: 24, iconName: "square.on.square"))
NewSessionTypeCard(name: String(localized: "Playground"), icon: SessionTypeIcon(size: 24, iconName: "square.on.square"))
}
}

NewSessionTypeCardGroup(title: "Other Sessions") {
NavigationLink(destination: NewSessionView(sessionType: SessionType.compsim, typeName: "Comp Sim", showNewSessionPopUp: $showNewSessionPopUp)) {
NewSessionTypeCard(name: "Comp Sim", icon: SessionTypeIcon(iconName: "globe.asia.australia", weight: .medium))
NewSessionTypeCardGroup(title: String(localized: "Other Sessions")) {
NavigationLink(destination: NewSessionView(sessionType: SessionType.compsim, typeName: "Compsim", showNewSessionPopUp: $showNewSessionPopUp)) {
NewSessionTypeCard(name: String(localized: "Compsim"), icon: SessionTypeIcon(iconName: "globe.asia.australia", weight: .medium))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions CubeTime/Sessions/SessionCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct SessionCard: View {
.contextMenu(menuItems: {
ContextMenuButton(delay: false,
action: { isShowingCustomizeDialog = true },
title: "Customise",
title: String(localized: "Customise"),
systemImage: "pencil", disableButton: false);

ContextMenuButton(delay: true,
Expand All @@ -163,13 +163,13 @@ struct SessionCard: View {
try! managedObjectContext.save()
}
},
title: item.pinned ? "Unpin" : "Pin",
title: item.pinned ? String(localized: "Unpin") : String(localized: "Pin"),
systemImage: item.pinned ? "pin.slash" : "pin", disableButton: false);
Divider()

ContextMenuButton(delay: false,
action: { isShowingDeleteDialog = true },
title: "Delete Session",
title: String(localized: "Delete Session"),
systemImage: "trash",
disableButton: allSessions.count <= 1)
.foregroundColor(Color.red)
Expand All @@ -181,7 +181,7 @@ struct SessionCard: View {
.tint(Color("accent"))
}

.confirmationDialog(String("Are you sure you want to delete \"\(self.item.name ?? "this session")\"? All solves will be deleted and this cannot be undone."), isPresented: $isShowingDeleteDialog, titleVisibility: .visible) {
.confirmationDialog(String(localized: "Are you sure you want to delete \"\(self.item.name ?? "this session")\"? All solves will be deleted and this cannot be undone."), isPresented: $isShowingDeleteDialog, titleVisibility: .visible) {
Button("Confirm", role: .destructive) {
if item == stopwatchManager.currentSession {
var next: Session? = nil
Expand Down
4 changes: 2 additions & 2 deletions CubeTime/Sessions/SessionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ struct EventPicker: View {
onTapRun: {
sessionEventType = Int32(index)
}) {
Image(element.name)
Image(element.imageName)
.renderingMode(.template)
.resizable()
.frame(width: imageSize, height: imageSize)
.frame(width: imageSize * 1.2, height: imageSize * 1.2)
}
}
}
Expand Down
37 changes: 18 additions & 19 deletions CubeTime/Sessions/Tools/ToolsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ class ToolsViewModel: ObservableObject {
}


enum ToolType: Identifiable {
case timerOnly, scrambleOnly, scrambleGenerator, calculator

var id: ToolType { self }
}

struct Tool: Identifiable, Equatable {
var id: String {
get { return name }
var id: ToolType {
get { return self.toolType }
}

let name: String
let toolType: ToolType
let iconName: String
let description: String
}

let tools: [Tool] = [
Tool(name: "Timer Only", iconName: "stopwatch", description: "Just a timer. No scrambles are shown. Your solves are **not** recorded and are not saved to a session."),
Tool(name: "Scramble Only", iconName: "cube", description: "Displays one scramble at a time. A timer is not shown. Tap to generate the next scramble."),
Tool(name: "Scramble Generator", iconName: "server.rack", description: "Generate multiple scrambles at once, to share, save or use."),
Tool(name: "Calculator", iconName: "function", description: "Simple average and mean calculator."),
Tool(name: String(localized: "Timer Only"), toolType: .timerOnly, iconName: "stopwatch", description: String(localized: "Just a timer. No scrambles are shown. Your solves are **not** recorded and are not saved to a session.")),
Tool(name: String(localized: "Scramble Only"), toolType: .scrambleOnly, iconName: "cube", description: String(localized: "Displays one scramble at a time. A timer is not shown. Tap to generate the next scramble.")),
Tool(name: String(localized: "Scramble Generator"), toolType: .scrambleGenerator, iconName: "server.rack", description: String(localized: "Generate multiple scrambles at once, to share, save or use.")),
Tool(name: String(localized: "Calculator"), toolType: .calculator, iconName: "function", description: String(localized: "Simple average and mean calculator.")),
/*
Tool(name: "Tracker", iconName: "scope", description: "Track someone's average at a comp. Calculates times needed for a chance for a target, BPA, WPA, and more."),
Tool(name: "Scorecard Generator", iconName: "printer", description: "Export scorecards for use at meetups (or comps!)."),
Expand Down Expand Up @@ -76,27 +83,19 @@ struct ToolsList: View {

Group {
if let tool = toolsViewModel.currentTool {
switch (tool.name) {
case "Timer Only":
switch (tool.toolType) {
case .timerOnly:
TimerOnlyTool()

case "Scramble Only":
case .scrambleOnly:
ScrambleOnlyTool()

case "Scramble Generator":
case .scrambleGenerator:
ScrambleGeneratorTool()

case "Calculator":
case .calculator:
CalculatorTool()

/*
case "Tracker":
EmptyView()
case "Scorecard Generator":
EmptyView()
*/

default:
EmptyView()
}
Expand Down
4 changes: 2 additions & 2 deletions CubeTime/Settings/AppearanceSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ struct AppearanceSettingsView: View {
}
}

SettingsDragger(text: "Font Weight", value: $fontWeight, in: 300...800)
SettingsDragger(text: "Font Casualness", value: $fontCasual, in: 0...1)
SettingsDragger(text: String(localized: "Font Weight"), value: $fontWeight, in: 300...800)
SettingsDragger(text: String(localized: "Font Casualness"), value: $fontCasual, in: 0...1)
SettingsToggle(String(localized: "Cursive Font"), $fontCursive)
}

Expand Down
4 changes: 3 additions & 1 deletion CubeTime/Settings/GeneralSettings.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import SwiftUI

enum InputMode: String, Codable, CaseIterable {
enum InputMode: LocalizedStringKey, Codable, CaseIterable, Identifiable {
case timer = "Timer"
case typing = "Typing"

var id: InputMode { self }
/*, stackmat, smartcube, virtual*/
}

Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct SettingsDetail: View {
ZStack {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Color("overlay0"))
.matchedGeometryEffect(id: "bg " + currentCard.name, in: namespace)
.matchedGeometryEffect(id: "bg \(currentCard.id)", in: namespace)
.ignoresSafeArea()
.shadowLight(x: 0, y: 3)

Expand Down
6 changes: 3 additions & 3 deletions CubeTime/Stats/StatsDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct StatsDetailView: View {
Text("|")
.offset(y: -1) // slight offset of bar

Text(solves.name == "Comp Sim Solve" ? "compsim" : solves.name.lowercased())
Text(solves.name == "Compsim Solve" ? "compsim" : solves.name.lowercased())


Spacer()
Expand All @@ -142,9 +142,9 @@ struct StatsDetailView: View {
let shareStr = getShareStr(solves: solves)

HStack(spacing: 8) {
CTCopyButton(toCopy: shareStr, buttonText: "Copy Average")
CTCopyButton(toCopy: shareStr, buttonText: String(localized: "Copy Average"))

CTShareButton(toShare: shareStr, buttonText: "Share Average")
CTShareButton(toShare: shareStr, buttonText: String(localized: "Share Average"))
}
.padding(.top, 16)
.padding(.bottom, 4)
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Stats/TimeTrend/TimeTrendDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct TimeTrendDetail: View {
@State var selectedLines = [true]

let labels: [(label: String, type: CTButtonType)] = [
("time", .halfcoloured(nil)),
(String(localized: "time"), .halfcoloured(nil)),
// ("ao5", .green),
// ("ao12", .red),
// ("ao100", .orange)
Expand Down
6 changes: 3 additions & 3 deletions CubeTime/StopwatchManager/ExportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ExportFormat: ReferenceFileDocument {

class CSVExportFormat: ExportFormat {
override func getName() -> String {
return "CSV (generic)"
return String(localized: "CSV (generic)")
}

static var _readableContentTypes: [UTType] = [.commaSeparatedText]
Expand Down Expand Up @@ -145,7 +145,7 @@ let styles = ##"""

class ODSExportFormat: ExportFormat {
override func getName() -> String {
return "ODF (MS Excel/Google Sheets)"
return String(localized: "ODF (MS Excel/Google Sheets)")
}

static var _readableContentTypes: [UTType] = [.zip]
Expand Down Expand Up @@ -303,7 +303,7 @@ class ODSExportFormat: ExportFormat {

class CSTimerExportFormat: ExportFormat {
override func getName() -> String {
return "JSON (csTimer)"
return String(localized: "JSON (csTimer)")
}

static var _readableContentTypes: [UTType] = [.commaSeparatedText]
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/StopwatchManager/StopwatchManager+Stats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ extension StopwatchManager {
return (nil, [])
} else {
var bestAverage: CalculatedAverage?
// var bestAverage: CalculatedAverage = calculateAverage(((compsimSession.solvegroups!.firstObject as! CompSimSolveGroup).solves!.array as! [Solves]), "Best Comp Sim", true)!
// var bestAverage: CalculatedAverage = calculateAverage(((compsimSession.solvegroups!.firstObject as! CompSimSolveGroup).solves!.array as! [Solves]), "Best Compsim", true)!

for solvegroup in compsimSolveGroups {
if solvegroup.solves!.allObjects.count == 5 {
Expand Down
Loading

0 comments on commit 16db474

Please sign in to comment.