From f0086ee4616087357a09c8277d1018bdb3871189 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 31 Aug 2026 23:01:02 +0200 Subject: [PATCH] Added the alternate locales to the Social Card in the Infrastructure package. --- .../Sources/Public/Types/SocialCard.swift | 12 +++++++++--- .../Public/Types/SocialCard/SocialCardTag.swift | 1 + .../Tests/Cases/Public/Types/SocialCardTests.swift | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Packages/Infrastructure/Sources/Public/Types/SocialCard.swift b/Packages/Infrastructure/Sources/Public/Types/SocialCard.swift index 0fe4a74..e8a8d3d 100644 --- a/Packages/Infrastructure/Sources/Public/Types/SocialCard.swift +++ b/Packages/Infrastructure/Sources/Public/Types/SocialCard.swift @@ -7,6 +7,9 @@ public struct SocialCard: Sendable { // MARK: Properties + /// The locales of the card's other language editions, in Open Graph's `language_TERRITORY` form; empty to omit their tags. + public let alternateLocales: [String] + /// The card's share image, or `nil` to omit its tags. public let image: Image? @@ -43,6 +46,7 @@ public struct SocialCard: Sendable { /// - siteName: the name of the site the card belongs to, or `nil` (the default) to omit its tag. /// - locale: the locale of the card's text, ideally in Open Graph's `language_TERRITORY` form (e.g. `en_US`), or `nil` (the default) /// to omit its tag. + /// - alternateLocales: the locales the card's page is also published in, in the same form; empty (the default) to omit their tags. /// - image: the card's share image, or `nil` (the default) to omit its tags. /// - type: the Open Graph type of the object the card describes. Defaults to `website`. /// - style: the layout a Twitter card scraper gives the card. Defaults to ``Style/summaryLargeImage``. @@ -52,10 +56,12 @@ public struct SocialCard: Sendable { url: String? = nil, siteName: String? = nil, locale: String? = nil, + alternateLocales: [String] = [], image: Image? = nil, type: String = "website", style: Style = .summaryLargeImage ) { + self.alternateLocales = alternateLocales self.image = image self.locale = locale self.siteName = siteName @@ -68,8 +74,8 @@ public struct SocialCard: Sendable { // MARK: Computed - /// The card's meta tags, in a stable order: the Open Graph type, site name, title, description, URL, and locale, then the image group, and - /// the Twitter card style last. A tag whose fact the card does not carry is left out. + /// The card's meta tags, in a stable order: the Open Graph type, site name, title, description, URL, locale, and alternate locales, then the + /// image group, and the Twitter card style last. A tag whose fact the card does not carry is left out. public var tags: [Tag] { let tags: [Tag?] = [ Tag(type, name: .type), @@ -78,7 +84,7 @@ public struct SocialCard: Sendable { summary.map { Tag($0, name: .description) }, url.map { Tag($0, name: .url) }, locale.map { Tag($0, name: .locale) }, - ] + (image?.tags ?? []) + [ + ] + alternateLocales.map { Tag($0, name: .localeAlternate) } + (image?.tags ?? []) + [ Tag(style.rawValue, name: .twitter), ] diff --git a/Packages/Infrastructure/Sources/Public/Types/SocialCard/SocialCardTag.swift b/Packages/Infrastructure/Sources/Public/Types/SocialCard/SocialCardTag.swift index ec446a5..1924635 100644 --- a/Packages/Infrastructure/Sources/Public/Types/SocialCard/SocialCardTag.swift +++ b/Packages/Infrastructure/Sources/Public/Types/SocialCard/SocialCardTag.swift @@ -60,6 +60,7 @@ extension SocialCard.Tag { case imageWidth = "og:image:width" /// The `og:locale` tag, carrying the locale of the card's text. case locale = "og:locale" + case localeAlternate = "og:locale:alternate" /// The `og:site_name` tag, carrying the name of the site the card belongs to. case siteName = "og:site_name" /// The `og:title` tag, carrying the card's title. diff --git a/Packages/Infrastructure/Tests/Cases/Public/Types/SocialCardTests.swift b/Packages/Infrastructure/Tests/Cases/Public/Types/SocialCardTests.swift index 6849302..a1c2a1e 100644 --- a/Packages/Infrastructure/Tests/Cases/Public/Types/SocialCardTests.swift +++ b/Packages/Infrastructure/Tests/Cases/Public/Types/SocialCardTests.swift @@ -18,6 +18,7 @@ struct SocialCardTests { url: "https://site.example/", siteName: "A Site", locale: "en", + alternateLocales: ["nl_NL", "de_DE"], image: .init( url: "https://site.example/img/card.png", width: 2400, @@ -33,6 +34,8 @@ struct SocialCardTests { .init("A summary.", name: .description), .init("https://site.example/", name: .url), .init("en", name: .locale), + .init("nl_NL", name: .localeAlternate), + .init("de_DE", name: .localeAlternate), .init("https://site.example/img/card.png", name: .image), .init("2400", name: .imageWidth), .init("1260", name: .imageHeight),