Fix localization issues and export strings for translation

This commit is contained in:
2023-07-09 15:12:35 -04:00
parent 83ef50586a
commit fcd7d2beab
10 changed files with 202 additions and 101 deletions

View File

@@ -80,6 +80,11 @@ class ScriptModel: ObservableObject {
}
}
func imports_string(_ count: Int, locale: Locale = Locale.current) -> String {
let format = localizedStringFormat(key: "imports_count", locale: locale)
return String(format: format, locale: locale, count)
}
struct LoadScript: View {
let pool: RelayPool
@@ -89,10 +94,9 @@ struct LoadScript: View {
ScrollView {
VStack {
let imports = script.script.imports()
(Text(verbatim: "\(imports.count)") +
Text(" Imports"))
.font(.title)
let nounText = Text(verbatim: imports_string(imports.count)).font(.title)
Text("\(Text(verbatim: imports.count.formatted())) \(nounText)", comment: "Sentence composed of 2 variables to describe how many imports were performed from loading a NostrScript. In source English, the first variable is the number of imports, and the second variable is 'Import' or 'Imports'.")
ForEach(imports.indices, id: \.self) { ind in
Text(imports[ind])
@@ -100,25 +104,25 @@ struct LoadScript: View {
switch script.state {
case .loaded:
BigButton("Run") {
BigButton(NSLocalizedString("Run", comment: "Button that runs a NostrScript.")) {
Task {
await model.run()
}
}
case .running:
Text("Running...")
Text("Running...", comment: "Indication that the execution of a NostrScript is running.")
case .ran(let result):
switch result {
case .runtime_err(let errs):
Text("Runtime error")
Text("Runtime error", comment: "Indication that a runtime error occurred when running a NostrScript.")
.font(.title2)
ForEach(errs.indices, id: \.self) { ind in
Text(verbatim: errs[ind])
}
case .suspend:
Text("Ran to suspension.")
Text("Ran to suspension.", comment: "Indication that a NostrScript was run until it reached a suspended state.")
case .finished(let code):
Text("Executed successfuly, returned with code \(code)")
Text("Executed successfully, returned with code \(code.description)", comment: "Indication that the execution of running a NostrScript finished successfully, while providing a numeric return code.")
}
}
}
@@ -138,13 +142,13 @@ struct LoadScript: View {
ScriptView(loaded)
case .failed(let load_err):
VStack(spacing: 20) {
Text("NostrScript Error")
Text("NostrScript Error", comment: "Text indicating that there was an error with loading NostrScript. There is a more descriptive error message shown separately underneath.")
.font(.title)
switch load_err {
case .parse:
Text("Failed to parse")
Text("Failed to parse", comment: "NostrScript error message when it fails to parse a script.")
case .module_init:
Text("Failed to initialize")
Text("Failed to initialize", comment: "NostrScript error message when it fails to initialize a module.")
}
}
}
@@ -152,7 +156,7 @@ struct LoadScript: View {
.task {
await model.load(pool: self.pool)
}
.navigationTitle("NostrScript")
.navigationTitle(NSLocalizedString("NostrScript", comment: "Navigation title for the view showing NostrScript."))
}
}

View File

@@ -452,7 +452,8 @@ struct ProfileView: View {
NavigationLink(value: Route.FollowersYouKnow(friendedFollowers: friended_followers, followers: followers)) {
HStack {
CondensedProfilePicturesView(state: damus_state, pubkeys: friended_followers, maxPictures: 3)
Text(followedByString(friended_followers, profiles: damus_state.profiles))
let followedByString = followedByString(friended_followers, profiles: damus_state.profiles)
Text(followedByString)
.font(.subheadline).foregroundColor(.gray)
.multilineTextAlignment(.leading)
}

View File

@@ -126,7 +126,7 @@ struct RelayDetailView: View {
}
if state.settings.developer_mode, let log_contents = log.contents {
Section("Log") {
Section(NSLocalizedString("Log", comment: "Label to display developer mode logs.")) {
Text(log_contents)
.font(.system(size: 13))
.lineLimit(nil)

View File

@@ -61,15 +61,15 @@ struct ZapTypePicker: View {
}
}
}
ZapTypeSelection(text: "Public", comment: "Picker option to indicate that a zap should be sent publicly and identify the user as who sent it.", img: "globe", action: {zap_type = ZapType.pub}, type: ZapType.pub)
ZapTypeSelection(text: "Private", comment: "Picker option to indicate that a zap should be sent privately and not identify the user to the public.", img: "lock", action: {zap_type = ZapType.priv}, type: ZapType.priv)
ZapTypeSelection(text: "Anonymous", comment: "Picker option to indicate that a zap should be sent anonymously and not identify the user as who sent it.", img: "question", action: {zap_type = ZapType.anon}, type: ZapType.anon)
ZapTypeSelection(text: "None", comment: "Picker option to indicate that sats should be sent to the user's wallet as a regular Lightning payment, not as a zap.", img: "zap", action: {zap_type = ZapType.non_zap}, type: ZapType.non_zap)
ZapTypeSelection(text: NSLocalizedString("Public", comment: "Picker option to indicate that a zap should be sent publicly and identify the user as who sent it."), img: "globe", action: {zap_type = ZapType.pub}, type: ZapType.pub)
ZapTypeSelection(text: NSLocalizedString("Private", comment: "Picker option to indicate that a zap should be sent privately and not identify the user to the public."), img: "lock", action: {zap_type = ZapType.priv}, type: ZapType.priv)
ZapTypeSelection(text: NSLocalizedString("Anonymous", comment: "Picker option to indicate that a zap should be sent anonymously and not identify the user as who sent it."), img: "question", action: {zap_type = ZapType.anon}, type: ZapType.anon)
ZapTypeSelection(text: NSLocalizedString("None", comment: "Picker option to indicate that sats should be sent to the user's wallet as a regular Lightning payment, not as a zap."), img: "zap", action: {zap_type = ZapType.non_zap}, type: ZapType.non_zap)
}
.padding(.horizontal)
}
func ZapTypeSelection(text: LocalizedStringKey, comment: StaticString, img: String, action: @escaping () -> (), type: ZapType) -> some View {
func ZapTypeSelection(text: String, img: String, action: @escaping () -> (), type: ZapType) -> some View {
Button(action: action) {
VStack(alignment: .leading, spacing: 5) {
HStack {
@@ -79,14 +79,15 @@ struct ZapTypePicker: View {
.frame(width: 20, height: 20)
.foregroundColor(.gray)
Text(text, comment: comment)
Text(text)
.font(.system(size: 20, weight: .semibold))
Spacer()
}
.padding(.horizontal)
Text(zap_type_desc(type: type, profiles: profiles, pubkey: pubkey))
let zapTypeDescription = zap_type_desc(type: type, profiles: profiles, pubkey: pubkey)
Text(zapTypeDescription)
.padding(.horizontal)
.foregroundColor(.gray)
.font(.system(size: 16))