Question

How to localise periodTitle


Badge +6

Hi all,

On my paywall I have a subscribe button that lists the introductory trial period and am trying to make it dynamic so I can A/B test trial period lengths, I have achieved this with string interpolation but can not work out how to localise the periodTitle. Any help would be greatly appreciated.

How does one localise the periodTitle property 

storeProduct.introductoryDiscount?.subscriptionPeriod.periodTitle

 


7 replies

Badge +3

Hi! I have the same issue with localization. Wrote about It to support, waiting for answer. moreover, for some reason periodTitle property is not available for me (don’t know, may be because of xCode version, or RevCat version. i get this error: “Value of type 'SubscriptionPeriod' has no member 'periodTitle'” 😕 but i found two other properties of subsctiptionPeriod - value (number) and unit (days, weeks, months etc) and the same - I can’t localize this units because they are of type SubscriptionPeriod.Unit, can’t turn it into String… will write back, if guys from support give me a solution. 

Badge +6

Hi Maria, thanks for the reply. I actually just figured it out. I am not sure why periodTitle isn't available to you but here is how I worked out the localisation.

 

Example for a string in a Text view with German localisation and with string interpolation for your trial length property:

Text(“Start \(NSLocalizedString(introDuration, comment: "intro length")) free trial”)

then in your Localizable file:

“Start %@ free trial" = "Probieren Sie %@ kostenlos";

 

I hope that helps :)

Badge +3

Hi Nic! 

 

Happy to hear that you’ve found the solution, that works for you.. But I still can’t even access this periodTitle property 😫 btw, your introDuration that you localize here - (“Start \(NSLocalizedString(introDuration, comment: "intro length")) free trial”) is of the String type?… 

Badge +6

Hi Maria,

Sorry yes my introDuration variable is of type String 😊

Oh gosh I forgot to give you the extension that gives you the periodTitle here it is :)

extension SubscriptionPeriod {
var durationTitle: String {
switch self.unit {
case .day: return "day"
case .week: return "week"
case .month: return "month"
case .year: return "year"
@unknown default: return "Unknown"
}
}

var periodTitle: String {
let periodString = "\(self.value) \(self.durationTitle)"
let pluralized = self.value > 1 ? periodString + "s" : periodString
return pluralized
}
}

 

 

Badge +3

this is brilliant! Thank you for this extension, now i fixed one of my problems with RevCat 😅 Gooog luck 🤗

Userlevel 4
Badge +6

Hey Nic, 

 

Glad you were able to get this solved! Unfortunately we dont have a method that returns a localized string for the periodTitle but I will go ahead and mark that as a feature request! 

 

For future reference, you can see what localized strings we have by searching for `localized` in our SDK reference sheets listed here: https://www.revenuecat.com/docs/reference

Badge +6

Hi Michael oh cool thanks so much 😄

Reply