Skip to content

Commit

Permalink
Update breakage report locale to JSON format (#905)
Browse files Browse the repository at this point in the history
* Standardize locale format

* Lint

* Add unit test for extension

* Lint
  • Loading branch information
SlayterDev authored Jul 22, 2024
1 parent 6db80af commit 63195a3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
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: "-")
}
}
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")
}

}

0 comments on commit 63195a3

Please sign in to comment.