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

Update breakage report locale to JSON format #905

Merged
merged 4 commits into from
Jul 22, 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
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
26 changes: 26 additions & 0 deletions Sources/Common/Extensions/LocaleExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// LocaleExtensions.swift
//
// Copyright © 2022 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

public extension Locale {
var localeIdentifierAsJsonFormat: String {
let baseIdentifier = self.identifier.components(separatedBy: "@").first ?? self.identifier
return baseIdentifier.replacingOccurrences(of: "_", with: "-")
}
SlayterDev marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public struct BrokenSiteReport {
let vpnOn: Bool
let jsPerformance: [Double]?
let userRefreshCount: Int
let localeIdentifier: String
let locale: Locale
#if os(iOS)
let siteType: SiteType
let atb: String
Expand Down Expand Up @@ -125,7 +125,7 @@ public struct BrokenSiteReport {
vpnOn: Bool,
jsPerformance: [Double]?,
userRefreshCount: Int,
localeIdentifier: String = Locale.current.identifier
locale: Locale = Locale.current
) {
self.siteUrl = siteUrl
self.category = category
Expand All @@ -147,7 +147,7 @@ public struct BrokenSiteReport {
self.vpnOn = vpnOn
self.jsPerformance = jsPerformance
self.userRefreshCount = userRefreshCount
self.localeIdentifier = localeIdentifier
self.locale = locale
}
#endif

Expand Down Expand Up @@ -177,7 +177,7 @@ public struct BrokenSiteReport {
jsPerformance: [Double]?,
userRefreshCount: Int,
variant: String,
localeIdentifier: String = Locale.current.identifier
locale: Locale = Locale.current
) {
self.siteUrl = siteUrl
self.category = category
Expand All @@ -203,7 +203,7 @@ public struct BrokenSiteReport {
self.jsPerformance = jsPerformance
self.userRefreshCount = userRefreshCount
self.variant = variant
self.localeIdentifier = localeIdentifier
self.locale = locale
}
#endif

Expand All @@ -226,7 +226,7 @@ public struct BrokenSiteReport {
"openerContext": openerContext?.rawValue ?? "",
"vpnOn": vpnOn.description,
"userRefreshCount": String(userRefreshCount),
"locale": localeIdentifier
"locale": locale.localeIdentifierAsJsonFormat
]

if mode == .regular {
Expand Down
31 changes: 31 additions & 0 deletions Tests/CommonTests/Extensions/LocaleExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// LocaleExtensionsTests.swift
//
// Copyright © 2022 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import XCTest
@testable import Common

final class LocaleExtensionsTests: XCTest {

func testThatJSONLocaleFormatIsReturned() {
let locale = Locale(identifier: "en_US")

XCTAssert(locale.localeIdentifierAsJsonFormat == "en-US", "The returned identifier should be in JSON format")
}

}
Loading