Commit Graph
19 Commits
Author SHA1 Message Date
Facundo Menzella 6b5c430082 chore: Enable force_unwrapping for SwiftLint (#4820)
* enable force_unwrapping

* avoid force unwrap

* fixed all errors

* remove extra disable
2025-02-26 12:40:49 +01:00
Josh Holtz 1fa69d42f4 [Paywalls] Improve locale consistency (#4158)
⚠️ Waiting for #4188 to be merged first (because needs all the tests to
pass)

## Motivation

Fix cases where paywall was showing multiple languages at once and
random languages.

## Description

👉 For a demo of the problem and solution, look in Slack in the paywalls
or SDK channel for the latest Loom that I posted

### Flow of paywall localization logic (since it can be confusing)

1.
[PaywallView](https://github.com/RevenueCat/purchases-ios/pull/4158/files#diff-ea75fe7280803e15b975d702a16c6851ffc2bbed01b7b196bf0fb80d75b4b332)
starts with `Locale.current` but then calls
`offering.validatedPaywall()` which will return the new
`displayedLocale: Locale` variable
2.
[PaywallData+Validation](https://github.com/RevenueCat/purchases-ios/pull/4158/files#diff-452790cf5287a44f75a4b2260254db2281a066faeea2b3e441a007ec60522b6b)
returns `displayedLocale` if its a valid paywall, otherwise it return
`Locale.current` for fallback paywall
3.
[PaywallData+Localization](https://github.com/RevenueCat/purchases-ios/pull/4158/files#diff-e620baead94f7acad56d931c485d7691c4f909be3fe625e104528a2702cca2a0)
has a lot of the new logic
- New `locale: Locale` computer property that it determines the locale
from the `localizedConfiguration` or `localizedConfigurationsByTier`
- New ` defaultLocalizedConfiguration` that uses the developer set
`defaultLocale` (from `PaywallData`) to find the default localization
- Updated `localizedConfiguration<Value>()` to take a new
`defaultLocalization` to put in its priority (and log it if its used).
If for some reason that's not found, it will use the legacy
`fallbackLocalization` (which is the first localization it finds or
english)
4. After all of that, the `displayedLocale` is passed into the actually
SwiftUI `LoadedOfferingPaywallView` to show this locale everywhere

### Problem 1 - Inconsistent languages displayed at once

The user defined localizations and the pre-localized content in the SDK
(like links in the footer and package duration names) could should
different localizations. The choice of which locale was happening in two
different spots.

Since the SDK has all possible localizations that the dashboard offers,
the locale SDK displays from the dashboard will be chosen for the
pre-localized content.

### Problem 2 - Showing random languages if not supported

We decided early on to not use a `default_locale` but that has hurt us.
The solution to use was use `localizations.first` to show the first
locale in the list and the intention that this was the first locale the
user did in the paywall. That was not the case, however. The order of
the localizations list was indeterministic so it should should a random
language (even to the point where different random languages would show
the the same user).

We are now introducing a `default_locale` that the developer can set in
the paywall. If the locale the user is requesting is not translated by
the developer, it will use the `default_locale`

### Problem 3 - Footer not using correct localization from the bundle

There were times where some parts of the footer itself (mainly the
restore button) would be a different language than the terms of service
and privacy policy buttons. This was due to a code issue where we were
using `Bundle.module`. Instead, we needed to specify a localization
bundle specifically that we wanted to use.
2024-08-20 09:44:27 -05:00
James BorthwickandCesar de la Vega 1499538d33 Xcode project with RevenueCatUI + Tests (#3960)
### RevenueCatUI and its tests are now accessible in the files
navigator:

<img width="555" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/a4067d0a-62e5-43b2-bf77-a8a7ee1dd16e">

### It add two new schemes:

<img width="384" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/94b80848-5cc3-4abc-b132-345d79a6f143">

Use RevenueCatUIDev to build RevenueCatUI, and RevenueCatUITests to run
its tests.

### Linting works:

<img width="716" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/aacfa0bf-84af-494e-a4b1-9434de69b4f8">

### Individual tests can be run from the UI:

<img width="999" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/902c5167-d352-4e6d-a848-c5d6c0e988de">

## N.B.

- Tests must be run via the RevenueCatUITest scheme.
- Xcode sometimes has difficulties switching schemes. If you see the
errors below, **clean the build folder** and try again and it will work
<img width="822" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/0ac8dd77-676c-46e4-bc76-f8edf86f5a79">
- Building with the RevenueCatUIDev scheme creates some warnings related
to switches. Adding in an `@unknown default:` resolves the warning but
causes an error in other configurations ("Default will never be
executed").
<img width="801" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/dcba6e0c-5755-4e5a-b940-ca270242b6bb">
- Because the root Package file was not altered, this PR won't have any
affect on how our package works when integrated via SPM.

---------

Co-authored-by: Cesar de la Vega <cesarvegaro@gmail.com>
2024-06-18 13:14:46 -07:00
NachoSoto e5b5bb0a4d Paywalls: add 4 new variables (#3629)
### Added:
- `price_per_period_full`
- `total_price_and_per_month_full`
- `sub_period_length`
- `sub_period_abbreviated`
2024-02-05 09:18:34 -08:00
Andy BoedoandNachoSoto 56f7178145 Paywalls: fix empty description when using custom package type and {{ sub_period }} (#3495)
If you select a custom package type and set Offer Period, the paywall
would have an empty entry for that package.


<img width="802" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/3922667/fa50e15b-b122-4caa-816e-3250f10d5d89">

| Before | After |
| :-: | :-: |
| ![IMG_908CED5B663B-1
(1)](https://github.com/RevenueCat/purchases-ios/assets/3922667/2519c74e-c0d2-44c1-a126-64bd78808384)
|
![IMG_B1CED574DF20-1](https://github.com/RevenueCat/purchases-ios/assets/3922667/1eaf17d6-75fd-4e20-86cf-ef93de2d74d3)
|

---------

Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
2023-12-08 07:17:49 +08:00
NachoSoto 56daf52f63 Optimization: changed first to first(where:) (#3467)
See https://github.com/apple/swift/issues/55374

`.first` has been broken since 2020.
2023-12-06 11:08:00 -08:00
Tensei 5e9c4f7493 Paywalls: adjusted German translations (#3476)
Special abbreviation style for German and some corrections to the German
translation

The updated translations are more precise. For instance, "Datenschutz"
is a more commonly used term for "Privacy" in German. Similarly,
changing "Lebensdauer" to "Lebenslang" for "Lifetime" is more accurate,
as "Lebenslang" specifically implies 'for life'. The other changes
follow a similar pattern of refining the language for better
comprehension and context-appropriate usage in German.
2023-12-06 11:04:04 -08:00
NachoSoto 0035d18ef5 Fix deprecation warning (#3371)
We normally don't have to handle this because of our lower deployment
target, except we do for `visionOS 1.0`, so this updates it for all.

```
▸ ⚠️  Localization.swift:265:25: 'languageCode' was deprecated in visionOS 1.0: renamed to 'language.languageCode.identifier'
▸ return self.languageCode
▸                         ^
```
2023-11-02 06:43:10 -07:00
NachoSoto c203198973 Paywalls: improve period abbreviations in Japanese (#3367)
This mainly fixes `{{ price_per_period }}` showing `¥1/y` for year.

I fixed it by forcing a single abbreviation style for Japanese.
2023-11-01 09:57:47 -07:00
NachoSoto d9b12fd1d2 Paywalls: {{ price_per_period }} now takes SubscriptionPeriod.value into account (#3133)
This was incorrect for `PackageType.threeMonth` and
`PackageType.sixMonth`.


![image](https://github.com/RevenueCat/purchases-ios/assets/685609/87b1ec00-04a0-4baa-ba73-edc4ce138388)
2023-09-14 18:28:11 -07:00
NachoSoto 64d8f4a856 Paywalls: added all localization (#3080) 2023-09-14 18:28:11 -07:00
NachoSoto 2103b04762 Paywalls: added MIT license to all headers (#3084)
`Xcode` doesn't allow customizing the header (looks like maybe it worked
at some point but not anymore:
https://stackoverflow.com/questions/67614785/changing-the-default-header-comment-license-in-swift-package).

At least this adds the license to all the initial files in the package.
2023-09-14 18:28:11 -07:00
NachoSoto f557edad6d Paywalls: replaced defaultLocale with preferredLocales (#3003)
Depends on #3002.

This is the new logic for finding the locale to use

```swift
var localizedConfiguration: LocalizedConfiguration {
    let locales: [Locale] = [.current] + Locale.preferredLocales

    return locales
        .lazy
        .compactMap(self.config(for:))
        .first ?? self.fallbackLocalizedConfiguration
}
```

And note that `config(for:)` is a fuzzy-lookup (#2847).
2023-09-14 18:28:11 -07:00
NachoSoto df7bd8b33f Paywalls: updated variable names (#2970)
These match the new agreed upon variables.

- Improved the localized unit abbreviations
- Refactored `VariableDataProvider` so all the logic is now in `Package`
- Added new tests for `Package` variables
2023-09-14 18:28:11 -07:00
NachoSoto e78c8782d0 Paywalls: added support for custom and lifetime products (#2941)
The main change is that `VariableHandler` no longer cashes when trying
to determine price per month for non-subscriptions. I added a test to
cover this behavior.
2023-09-14 18:28:11 -07:00
NachoSoto 0ecdd45b0e Paywalls: added ability to calculate and localize subscription discounts (#2943)
![Screenshot 2023-08-02 at 08 17
45](https://github.com/RevenueCat/purchases-ios/assets/685609/0c3ee7b8-1b37-4e6d-81d0-4b2d18086d82)

Useful for template 4, but also for others.
2023-09-14 18:28:11 -07:00
NachoSoto b1af8eb776 Paywalls: new {{ period }} variable (#2876)
This represents the localized `PackageType`.
2023-09-14 18:28:11 -07:00
NachoSoto 46f1224a19 Paywalls: basic localization support (#2851)
Most of the changes are to support the creation of the new
`PaywallViewLocalizationTests` by being able to override the environment
`Locale`.

![Simulator Screenshot - iPhone 14 Pro - 2023-07-20 at 18 10
20](https://github.com/RevenueCat/purchases-ios/assets/685609/27972228-0956-499e-a90c-e8f1ae84bebe)
2023-09-14 18:28:11 -07:00
NachoSoto 3f18b6fcef Paywalls: added new total_price_and_per_month variable (#2845)
This also expands `Localization` support to be able to format this in
any language.
2023-09-14 18:28:11 -07:00