Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix availability of LocalizedStringKey extension (iOS 14+) #88

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ extension AvailabilityArgumentListSyntax {
]
}

static var wwdc2020: AvailabilityArgumentListSyntax {
[
AvailabilityArgumentSyntax(argument: .platformVersionRestriction("macOS", versionMajor: 11))
.with(\.trailingComma, .commaToken()),

AvailabilityArgumentSyntax(argument: .platformVersionRestriction("iOS", versionMajor: 14))
.with(\.trailingComma, .commaToken()),

AvailabilityArgumentSyntax(argument: .platformVersionRestriction("tvOS", versionMajor: 14))
.with(\.trailingComma, .commaToken()),

AvailabilityArgumentSyntax(argument: .platformVersionRestriction("watchOS", versionMajor: 7))
.with(\.trailingComma, .commaToken()),

AvailabilityArgumentSyntax(argument: .token(.binaryOperator("*")))
]
}

static var wwdc2019: AvailabilityArgumentListSyntax {
[
AvailabilityArgumentSyntax(argument: .platformVersionRestriction("macOS", versionMajor: 10, versionMinor: 5))
Expand Down
3 changes: 2 additions & 1 deletion Sources/StringGenerator/Snippets/SourceFileSnippet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct SourceFileSnippet: Snippet {

StringsTableConversionStaticMethodSnippet(
stringsTable: sourceFile.stringExtension.stringsTableStruct,
returnType: .type(.LocalizedStringKey)
returnType: .type(.LocalizedStringKey),
availability: .wwdc2020
)

LocalizedStringKeyOverrideKeySnippet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import SwiftSyntaxBuilder
struct StringsTableConversionStaticMethodSnippet {
let stringsTable: SourceFile.StringExtension.StringsTableStruct
let returnType: TokenSyntax
var availability: AvailabilityArgumentListSyntax?
}

extension StringsTableConversionStaticMethodSnippet: Snippet {
var syntax: some DeclSyntaxProtocol {
FunctionDeclSyntax(
leadingTrivia: leadingTrivia,
attributes: attributes.map({ $0.with(\.trailingTrivia, .newline) }),
modifiers: modifiers,
name: name,
signature: signature,
Expand All @@ -23,6 +25,13 @@ extension StringsTableConversionStaticMethodSnippet: Snippet {
""")
}

@AttributeListBuilder
var attributes: AttributeListSyntax {
if let availability {
AttributeSyntax(availability: availability)
}
}

@DeclModifierListBuilder
var modifiers: DeclModifierListSyntax {
DeclModifierSyntax(name: stringsTable.accessLevel.token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension LocalizedStringKeyInitializerSnippet: Snippet {
var syntax: some DeclSyntaxProtocol {
InitializerDeclSyntax(
leadingTrivia: leadingTrivia,
attributes: attributes.map({ $0.with(\.trailingTrivia, .newline) }),
modifiers: modifiers,
signature: signature,
body: body
Expand All @@ -25,6 +26,11 @@ extension LocalizedStringKeyInitializerSnippet: Snippet {
""")
}

@AttributeListBuilder
var attributes: AttributeListSyntax {
AttributeSyntax(availability: .wwdc2020)
}

@DeclModifierListBuilder
var modifiers: DeclModifierListSyntax {
DeclModifierSyntax(name: stringsTable.accessLevel.token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘FormatSpecifiers‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(formatSpecifiers: String.FormatSpecifiers) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -691,6 +692,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘FormatSpecifiers‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func formatSpecifiers(_ formatSpecifiers: String.FormatSpecifiers) -> LocalizedStringKey {
LocalizedStringKey(formatSpecifiers: formatSpecifiers)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Localizable‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(localizable: String.Localizable) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -378,6 +379,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Localizable‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func localizable(_ localizable: String.Localizable) -> LocalizedStringKey {
LocalizedStringKey(localizable: localizable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Multiline‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(multiline: String.Multiline) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -299,6 +300,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Multiline‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func multiline(_ multiline: String.Multiline) -> LocalizedStringKey {
LocalizedStringKey(multiline: multiline)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Positional‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(positional: String.Positional) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -360,6 +361,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Positional‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func positional(_ positional: String.Positional) -> LocalizedStringKey {
LocalizedStringKey(positional: positional)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Simple‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(simple: String.Simple) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -289,6 +290,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Simple‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func simple(_ simple: String.Simple) -> LocalizedStringKey {
LocalizedStringKey(simple: simple)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Substitution‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(substitution: String.Substitution) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -293,6 +294,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Substitution‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func substitution(_ substitution: String.Substitution) -> LocalizedStringKey {
LocalizedStringKey(substitution: substitution)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Variations‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal init(variations: String.Variations) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -319,6 +320,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Variations‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
internal static func variations(_ variations: String.Variations) -> LocalizedStringKey {
LocalizedStringKey(variations: variations)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Localizable‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
package init(localizable: String.Localizable) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -378,6 +379,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Localizable‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
package static func localizable(_ localizable: String.Localizable) -> LocalizedStringKey {
LocalizedStringKey(localizable: localizable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ extension Text {
@available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *)
extension LocalizedStringKey {
/// Creates a localized string key that represents a localized value in the ‘Localizable‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
public init(localizable: String.Localizable) {
var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1)

Expand All @@ -378,6 +379,7 @@ extension LocalizedStringKey {
}

/// Creates a `LocalizedStringKey` that represents a localized value in the ‘Localizable‘ strings table.
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
public static func localizable(_ localizable: String.Localizable) -> LocalizedStringKey {
LocalizedStringKey(localizable: localizable)
}
Expand Down
Loading