TelemetryDeck / SwiftSDK

Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
Other
148 stars 30 forks source link

Make it easier to check for appLanguage, preferredLanguage, and region + grand rename #149

Closed Jeehut closed 2 months ago

Jeehut commented 2 months ago

In Swift, Locale.current represents the language and region the app is currently using. When an app is not localized to say German, for example, the identifier will not return de for the language even it's the users preferred language.

To make it easier for TelemetryDeck users to use a data-driven approach in deciding which languages to localize for next, it is important to add the preferred language of the user though, even if the app doesn't support it. It can also be useful to see just the app language or just the region, without them being clutched together in locale as in en_DE.

This PR therefore introduces region (the regional part of locale), appLanguage (the language part of locale), and the new preferredLanguage which is the field that is most useful to make the localization expansion decision.

winsmith commented 2 months ago

Love it, just one change request. We talked recently about prefixing default keys, so let's do that here. Can you prefix all new keys with e.g "TelemetryDeck.Localization."?

Jeehut commented 2 months ago

@winsmith I just updated this PR to also include the new parameters suggested in https://github.com/TelemetryDeck/docs/pull/85 and the grand rename with the parallel sending of old and new parameters at the same time. For the streamlining of the call APIs (rename of send to signal etc.), I will create a separate PR. In that, I will also bump the version num to 2.0.0.

Note that I greatly simplified the creation of the dictionary. I don't know why exactly you were using a JSONEncoder and then parsing back with JSONSerialization, but I'm now just creating a dictionary literal. Probably a historical leftover. See my commit 28065ca1d90f3d2ce251bc2f309a96519c365a34.

Jeehut commented 2 months ago

Note to myself: Don't forget to also send the new signal name TelemetryDeck.Session.started.