Skip to content

Commit

Permalink
Fix empty string shown if company name is empty
Browse files Browse the repository at this point in the history
If the company name is empty in the custom locales set in the web (as is the
default), then the widgets tried to get it, but as it is empty, then the
fallback was the theme and the configuration. If neither of those was able to
provide a non-empty value, then the idea is to use the local fallback. However,
for this I was mistakenly using the value from `Localizable.tr`. The problem is
that this method first attempts to get it again from the string provider. As we
determined in the first step, this is empty. However, `Localizable.tr` doesn't
filter empty values, as all other strings can legitimately be empty. So the
method returns empty string, and this is shown on the widgets.

The solution was to create a new value in the SwiftGen stencil, which is called
`companyNameLocalFallbackOnly`. As the name says, this variable sends the string
provider as nil, thus ignoring the company name's empty value, and using the
value in the `Localizable.strings`, or the hardcoded "Company Name" as fallback.

For now, no other string is subject to this matter where the string can come
from a lot of various sources, so this approach should be sufficient. If at some
point it happens that quite a lot of strings need to be fetched from various
sources, what can be done is that the stencil can be changed so that instead of
generating `static let`s, we generate `static func`s, and then we can easily
send the string provider as needed.

MOB-2768
  • Loading branch information
gersonnoboa committed Oct 19, 2023
1 parent df37271 commit 915fa92
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
14 changes: 6 additions & 8 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
846A5C3929D18D400049B29F /* ScreenShareHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846A5C3829D18D400049B29F /* ScreenShareHandlerTests.swift */; };
846A5C3E29D1C7B00049B29F /* CallVisualizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846A5C3D29D1C7B00049B29F /* CallVisualizerTests.swift */; };
846A5C4029ED83C50049B29F /* CallVisualizer.Coordinator.DelegateEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846A5C3F29ED83C50049B29F /* CallVisualizer.Coordinator.DelegateEvent.swift */; };
846A5C4529F6BEFA0049B29F /* GliaTests+StartEngagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846A5C4429F6BEFA0049B29F /* GliaTests+StartEngagement.swift */; };
846A5C4529F6BEFA0049B29F /* GliaTests+StartEngagementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846A5C4429F6BEFA0049B29F /* GliaTests+StartEngagementTests.swift */; };
846E822828996A5C008EFBF0 /* AlertViewControllerVoiceOverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846E822728996A5C008EFBF0 /* AlertViewControllerVoiceOverTests.swift */; };
847A7643285A1914004044D1 /* FileUploadListViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847A7642285A1914004044D1 /* FileUploadListViewModelTests.swift */; };
8491AF002A6FB44200CC3E72 /* GvaGalleryCardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AEFF2A6FB44200CC3E72 /* GvaGalleryCardCell.swift */; };
Expand Down Expand Up @@ -599,10 +599,10 @@
C06A7586296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06A7585296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift */; };
C06A7588296ECD75006B69A2 /* Theme+VisitorCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06A7587296ECD75006B69A2 /* Theme+VisitorCode.swift */; };
C07F62462ABC322B003EFC97 /* OrientationManager.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62452ABC322B003EFC97 /* OrientationManager.Mock.swift */; };
C07F62772AC1BA2B003EFC97 /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */; };
C07F62792AC2D2E8003EFC97 /* BackgroundSwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62782AC2D2E8003EFC97 /* BackgroundSwiftUI.swift */; };
C07F627D2AC2F31F003EFC97 /* ScreenSharingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F627C2AC2F31F003EFC97 /* ScreenSharingViewModel.swift */; };
C07F62812AC3057C003EFC97 /* ScreenSharingViewModel.mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62802AC3057C003EFC97 /* ScreenSharingViewModel.mock.swift */; };
C07F62772AC1BA2B003EFC97 /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */; };
C07F62832AC33BB9003EFC97 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62822AC33BB9003EFC97 /* UIView+Extensions.swift */; };
C07FA04029AF542A00E9FB7F /* ScreenSharingViewStyle+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84265E0B298AECBA00D65842 /* ScreenSharingViewStyle+Mock.swift */; };
C07FA04B29AF83B900E9FB7F /* ActionButton.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07FA04929AF83A400E9FB7F /* ActionButton.Mock.swift */; };
Expand Down Expand Up @@ -1104,7 +1104,7 @@
846A5C3829D18D400049B29F /* ScreenShareHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenShareHandlerTests.swift; sourceTree = "<group>"; };
846A5C3D29D1C7B00049B29F /* CallVisualizerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallVisualizerTests.swift; sourceTree = "<group>"; };
846A5C3F29ED83C50049B29F /* CallVisualizer.Coordinator.DelegateEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallVisualizer.Coordinator.DelegateEvent.swift; sourceTree = "<group>"; };
846A5C4429F6BEFA0049B29F /* GliaTests+StartEngagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GliaTests+StartEngagement.swift"; sourceTree = "<group>"; };
846A5C4429F6BEFA0049B29F /* GliaTests+StartEngagementTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GliaTests+StartEngagementTests.swift"; sourceTree = "<group>"; };
846E822728996A5C008EFBF0 /* AlertViewControllerVoiceOverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertViewControllerVoiceOverTests.swift; sourceTree = "<group>"; };
847A7642285A1914004044D1 /* FileUploadListViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadListViewModelTests.swift; sourceTree = "<group>"; };
8491AEFF2A6FB44200CC3E72 /* GvaGalleryCardCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GvaGalleryCardCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1341,13 +1341,11 @@
C06A7585296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisitorCodeStyle.Accessibility.swift; sourceTree = "<group>"; };
C06A7587296ECD75006B69A2 /* Theme+VisitorCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+VisitorCode.swift"; sourceTree = "<group>"; };
C07F62452ABC322B003EFC97 /* OrientationManager.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrientationManager.Mock.swift; sourceTree = "<group>"; };
C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = "<group>"; };
C07F62782AC2D2E8003EFC97 /* BackgroundSwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundSwiftUI.swift; sourceTree = "<group>"; };
C07F627C2AC2F31F003EFC97 /* ScreenSharingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenSharingViewModel.swift; sourceTree = "<group>"; };
C07F62802AC3057C003EFC97 /* ScreenSharingViewModel.mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenSharingViewModel.mock.swift; sourceTree = "<group>"; };
C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = "<group>"; };
C07F62822AC33BB9003EFC97 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = "<group>"; };
C07FA04129AF550500E9FB7F /* ScreenSharingView.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenSharingView.Mock.swift; sourceTree = "<group>"; };
C07FA04429AF55F600E9FB7F /* ScreenSharingViewController.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenSharingViewController.Mock.swift; sourceTree = "<group>"; };
C07FA04929AF83A400E9FB7F /* ActionButton.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionButton.Mock.swift; sourceTree = "<group>"; };
C07FA04C29B0E41A00E9FB7F /* ScreenShareViewControllerVoiceOverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScreenShareViewControllerVoiceOverTests.swift; sourceTree = "<group>"; };
C07FA04D29B0E41A00E9FB7F /* VideoCallViewControllerVoiceOverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCallViewControllerVoiceOverTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3209,7 +3207,7 @@
children = (
8491AF612AA20F8F00CC3E72 /* Mocks */,
7512A5A627C3926500319DF1 /* GliaTests.swift */,
846A5C4429F6BEFA0049B29F /* GliaTests+StartEngagement.swift */,
846A5C4429F6BEFA0049B29F /* GliaTests+StartEngagementTests.swift */,
);
path = Glia;
sourceTree = "<group>";
Expand Down Expand Up @@ -4908,7 +4906,7 @@
C0175A0F2A55A624001FACDE /* ChatMessagaEntryViewTests.swift in Sources */,
9A8130C627D90B3800220BBD /* FileSystemStorage.Failing.swift in Sources */,
846429832A45DA7500943BD6 /* AlertViewController+Mock.swift in Sources */,
846A5C4529F6BEFA0049B29F /* GliaTests+StartEngagement.swift in Sources */,
846A5C4529F6BEFA0049B29F /* GliaTests+StartEngagementTests.swift in Sources */,
7512A57A27BF9FCD00319DF1 /* ChatViewModelTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 2 additions & 0 deletions GliaWidgets/Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ internal enum Localization {
internal static let comment = Localization.tr("Localizable", "general.comment", fallback: "Comment")
/// Company Name
internal static let companyName = Localization.tr("Localizable", "general.company_name", fallback: "Company Name")
/// Company Name without asking string provider
internal static let companyNameLocalFallbackOnly = Localization.tr("Localizable", "general.company_name", fallback: "Company Name", stringProviding: nil)
/// Decline
internal static let decline = Localization.tr("Localizable", "general.decline", fallback: "Decline")
/// Download
Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/Public/Glia/Glia+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extension Glia {
else {
// This will return the fallback value every time, because we have
// already determined that the remote string is empty.
return Localization.General.companyName
return Localization.General.companyNameLocalFallbackOnly
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,43 @@ extension GliaTests {
XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "Glia 1")
XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, "Glia 2")
}

func testCompanyNameIsReceivedFromLocalFallbackIfCustomLocalesIsEmpty() throws {
var environment = Glia.Environment.failing
var resultingViewFactory: ViewFactory?

environment.createRootCoordinator = { _, viewFactory, _, _, _, _, _ in
resultingViewFactory = viewFactory

return .mock(
interactor: .mock(environment: .failing),
viewFactory: viewFactory,
sceneProvider: nil,
engagementKind: .none,
screenShareHandler: .mock,
features: [],
environment: .failing
)
}

environment.coreSdk.localeProvider.getRemoteString = { _ in "" }
environment.coreSdk.configureWithInteractor = { _ in }
environment.coreSdk.configureWithConfiguration = { _, completion in
// Simulating what happens in the Widgets when the configuration gets done
Glia.sharedInstance.stringProviding = StringProviding(
getRemoteString: environment.coreSdk.localeProvider.getRemoteString
)
completion?()
}
environment.coreSdk.getCurrentEngagement = { nil }

let sdk = Glia(environment: environment)
try sdk.configure(with: .mock(), completion: {})
try sdk.startEngagement(engagementKind: .chat, in: ["queueId"])

let configuredSdkTheme = resultingViewFactory?.theme
let localFallbackCompanyName = "Company Name"
XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, localFallbackCompanyName)
XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, localFallbackCompanyName)
}
}
4 changes: 4 additions & 0 deletions swiftgen-strings.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ import Foundation
{{accessModifier}} static var {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}", fallback: "{{translation}}") }
{% else %}
{{accessModifier}} static let {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}", fallback: "{{translation}}")
{% if string.key == "general.company_name" %}
/// {{translation}} without asking string provider
{{accessModifier}} static let {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}LocalFallbackOnly = {{enumName}}.tr("{{table}}", "{{string.key}}", fallback: "{{translation}}", stringProviding: nil)
{% endif %}
{% endif %}
{% endfor %}
{% for child in item.children %}
Expand Down

0 comments on commit 915fa92

Please sign in to comment.