Skip to content

Commit

Permalink
Use localized names for challenge categories. (#1327)
Browse files Browse the repository at this point in the history
Challenge category names returned by the server are actually keys for the
localization system. This commit adds those keys to the iOS app to use for
translation.

Partial fix for #1057.
  • Loading branch information
JBYoshi authored Feb 7, 2024
1 parent ec50fbf commit cca06f5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
33 changes: 33 additions & 0 deletions HabitRPG/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,39 @@ public enum L10n {
public static var wheelchair: String { return L10n.tr("Mainstrings", "avatar.wheelchair") }
}

public enum ChallengeCategory {
/// Academics
public static var academics: String { return L10n.tr("Mainstrings", "challenge_category.academics") }
/// Advocacy + Causes
public static var advocacyCauses: String { return L10n.tr("Mainstrings", "challenge_category.advocacy_causes") }
/// Creativity
public static var creativity: String { return L10n.tr("Mainstrings", "challenge_category.creativity") }
/// Entertainment
public static var entertainment: String { return L10n.tr("Mainstrings", "challenge_category.entertainment") }
/// Finance
public static var finance: String { return L10n.tr("Mainstrings", "challenge_category.finance") }
/// Getting Organized
public static var gettingOrganized: String { return L10n.tr("Mainstrings", "challenge_category.getting_organized") }
/// Habitica Official
public static var habiticaOfficial: String { return L10n.tr("Mainstrings", "challenge_category.habitica_official") }
/// Health + Fitness
public static var healthFitness: String { return L10n.tr("Mainstrings", "challenge_category.health_fitness") }
/// Hobbies + Occupations
public static var hobbiesOccupations: String { return L10n.tr("Mainstrings", "challenge_category.hobbies_occupations") }
/// Location-based
public static var locationBased: String { return L10n.tr("Mainstrings", "challenge_category.location_based") }
/// Mental Health + Self-Care
public static var mentalHealth: String { return L10n.tr("Mainstrings", "challenge_category.mental_health") }
/// Recovery + Support Groups
public static var recoverySupportGroups: String { return L10n.tr("Mainstrings", "challenge_category.recovery_support_groups") }
/// Self-Improvement
public static var selfImprovement: String { return L10n.tr("Mainstrings", "challenge_category.self_improvement") }
/// Spirituality
public static var spirituality: String { return L10n.tr("Mainstrings", "challenge_category.spirituality") }
/// Time-Management + Accountability
public static var timeManagement: String { return L10n.tr("Mainstrings", "challenge_category.time_management") }
}

public enum Classes {
/// Become a %@
public static func becomeAClass(_ p1: String) -> String {
Expand Down
16 changes: 16 additions & 0 deletions HabitRPG/Strings/Base.lproj/Mainstrings.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1304,3 +1304,19 @@
"quest_mechanics_pausing_description" = "If you’re struggling to complete your Dailies, you can pause damage from Settings for a break. This will prevent the Boss from hurting you or others, but also pause your own damage. Other members missed Dailies will still cause damage, so be careful out there!";
"quest_mechanics_rage_title" = "Rage meters";
"quest_mechanics_rage_description" = "Some difficult bosses have an orange Rage meter under their HP. This meter fills up when participants miss Dailies. When it fills completely, the boss will let out a fearsome attack that does extra damage!";

"challenge_category.habitica_official" = "Habitica Official";
"challenge_category.academics" = "Academics";
"challenge_category.advocacy_causes" = "Advocacy + Causes";
"challenge_category.creativity" = "Creativity";
"challenge_category.entertainment" = "Entertainment";
"challenge_category.finance" = "Finance";
"challenge_category.health_fitness" = "Health + Fitness";
"challenge_category.hobbies_occupations" = "Hobbies + Occupations";
"challenge_category.location_based" = "Location-based";
"challenge_category.mental_health" = "Mental Health + Self-Care";
"challenge_category.getting_organized" = "Getting Organized";
"challenge_category.recovery_support_groups" = "Recovery + Support Groups";
"challenge_category.self_improvement" = "Self-Improvement";
"challenge_category.spirituality" = "Spirituality";
"challenge_category.time_management" = "Time-Management + Accountability";
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ChallengeCategoriesTableViewCell: ResizableTableViewCell, ChallengeConfigu

func createCategoryLabel(_ category: String) -> UILabel {
let label = emptyTagLabel()
label.text = " \(category) "
label.text = " \(localizedCategoryNameFor(name: category)) "
label.textColor = ThemeService.shared.theme.ternaryTextColor
label.backgroundColor = ThemeService.shared.theme.offsetBackgroundColor
label.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -112,4 +112,25 @@ class ChallengeCategoriesTableViewCell: ResizableTableViewCell, ChallengeConfigu
}
}

func localizedCategoryNameFor(name: String) -> String {
return switch name {
case "habitica_official": L10n.ChallengeCategory.habiticaOfficial
case "academics": L10n.ChallengeCategory.academics
case "advocacy_causes": L10n.ChallengeCategory.advocacyCauses
case "creativity": L10n.ChallengeCategory.creativity
case "entertainment": L10n.ChallengeCategory.entertainment
case "finance": L10n.ChallengeCategory.finance
case "health_fitness": L10n.ChallengeCategory.healthFitness
case "hobbies_occupations": L10n.ChallengeCategory.hobbiesOccupations
case "location_based": L10n.ChallengeCategory.locationBased
case "mental_health": L10n.ChallengeCategory.mentalHealth
case "getting_organized": L10n.ChallengeCategory.gettingOrganized
case "recovery_support_groups": L10n.ChallengeCategory.recoverySupportGroups
case "self_improvement": L10n.ChallengeCategory.selfImprovement
case "spirituality": L10n.ChallengeCategory.spirituality
case "time_management": L10n.ChallengeCategory.timeManagement
default: name
}
}

}

0 comments on commit cca06f5

Please sign in to comment.