Skip to content

Commit

Permalink
Rename Resource.defaultValue to sourceLocalization
Browse files Browse the repository at this point in the history
  • Loading branch information
liamnichols committed May 16, 2024
1 parent eb2f494 commit 80979c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Sources/StringExtractor/Resource+Extract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ extension Resource {
from segments: [StringParser.ParsedSegment],
labels: [Int: String] = [:],
key: String
) throws -> (arguments: [Argument], defaultValue: String) {
var defaultValue: String = "", arguments: [Int: Argument] = [:]
) throws -> (arguments: [Argument], sourceLocalization: String) {
var sourceLocalization: String = "", arguments: [Int: Argument] = [:]
var nextUnspecifiedPosition = 1

// Convert the parsed string into a default value and extract the arguments
for segment in segments {
switch segment {
case .string(let contents):
defaultValue.append(contents)
sourceLocalization.append(contents)
case .placeholder(let placeholder) where placeholder.rawValue == "%" || placeholder.rawValue == "%%":
defaultValue.append(placeholder.rawValue)
sourceLocalization.append(placeholder.rawValue)
case .placeholder(let placeholder):
// If the placeholder is an unsupported type, raise an error about the invalid string
guard let _type = placeholder.type, let type = String.LocalizationValue.Placeholder(_type) else {
Expand Down Expand Up @@ -61,7 +61,7 @@ extension Resource {
)
}

defaultValue.append(placeholder.rawValue)
sourceLocalization.append(placeholder.rawValue)
arguments[position] = argument
}
}
Expand All @@ -81,7 +81,7 @@ extension Resource {
}
}

return (arguments.sorted(by: { $0.key < $1.key }).map(\.value), defaultValue)
return (arguments.sorted(by: { $0.key < $1.key }).map(\.value), sourceLocalization)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/StringExtractor/Resource+StringUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ extension Resource {
comment: comment,
identifier: identifier,
arguments: extracted.arguments,
defaultValue: extracted.defaultValue
sourceLocalization: extracted.sourceLocalization
)
}

static func extract(
from localization: StringLocalization,
key: String
) throws -> (arguments: [Argument], defaultValue: String) {
) throws -> (arguments: [Argument], sourceLocalization: String) {
guard let stringUnit = preferredStringUnit(from: localization.stringUnit, variations: localization.variations) else {
throw ExtractionError.localizationCorrupt(
ExtractionError.Context(
Expand Down
4 changes: 2 additions & 2 deletions Sources/StringGenerator/StringGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ public struct StringGenerator {
var typeDocumentation: Trivia {
let exampleResource = resources.first(where: { $0.arguments.isEmpty })
let exampleId = exampleResource?.identifier ?? "foo"
let exampleValue = exampleResource?.defaultValue ?? "bar"
let exampleValue = exampleResource?.sourceLocalization ?? "bar"
let exampleAccessor = ".\(variableToken.text).\(exampleId)"

return Trivia(docComment: """
Expand All @@ -1053,7 +1053,7 @@ public struct StringGenerator {
var customTypeDocumentation: Trivia {
let exampleResource = resources.first(where: { $0.arguments.isEmpty })
let exampleId = exampleResource?.identifier ?? "foo"
let exampleValue = exampleResource?.defaultValue ?? "bar"
let exampleValue = exampleResource?.sourceLocalization ?? "bar"

return Trivia(docComment: """
Constant values for the \(tableName) Strings Catalog
Expand Down
8 changes: 4 additions & 4 deletions Sources/StringResource/Resource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public struct Resource: Equatable {
/// An array of arguments to be interpolated into the resource
public let arguments: [Argument]

/// The default localised value
public let defaultValue: String
/// The source localization value
public let sourceLocalization: String

public init(
key: String,
comment: String?,
identifier: String,
arguments: [Argument],
defaultValue: String
sourceLocalization: String
) {
self.key = key
self.comment = comment
self.identifier = identifier
self.arguments = arguments
self.defaultValue = defaultValue
self.sourceLocalization = sourceLocalization
}
}

Expand Down

0 comments on commit 80979c4

Please sign in to comment.