Skip to content

Commit

Permalink
Merge pull request #344 from m-sanders/master
Browse files Browse the repository at this point in the history
Expose BCP47 language tag for iOS.
  • Loading branch information
hyochan committed Dec 20, 2018
2 parents 10af709 + 1cf5679 commit e62ccb4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ async componentDidMount() {
|`productId`||| Returns a string needed to purchase the item later |
|`currency`||| Returns the currency code |
|`localizedPrice`||| Use localizedPrice if you want to display the price to the user so you don't need to worry about currency symbols. |
|`localeIOS`|| | Returns the BCP 47 language tag. (eg. `en-US`) (iOS). |
|`title`||| Returns the title Android and localizedTitle on iOS |
|`description`||| Returns the localized description on Android and iOS |
|`introductoryPrice`||| Formatted introductory price of a subscription, including its currency sign, such as €3.99. The price doesn't include tax. |
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Common {
price: string
currency: string
localizedPrice: string
localeIOS: string
}

export interface Product<ID extends string> extends Common {
Expand Down
9 changes: 9 additions & 0 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ -(NSDictionary*)getProductObject:(SKProduct *)product {

NSString* localizedPrice = [formatter stringFromNumber:product.price];
NSString* introductoryPrice = localizedPrice;
NSString* locale = localeIdentifierToBCP47(product.priceLocale.localeIdentifier);

NSString* introductoryPricePaymentMode = @"";
NSString* introductoryPriceNumberOfPeriods = @"";
Expand Down Expand Up @@ -400,6 +401,7 @@ -(NSDictionary*)getProductObject:(SKProduct *)product {
product.localizedTitle ? product.localizedTitle : @"", @"title",
product.localizedDescription ? product.localizedDescription : @"", @"description",
localizedPrice, @"localizedPrice",
locale, @"localeIOS",
periodNumberIOS, @"subscriptionPeriodNumberIOS",
periodUnitIOS, @"subscriptionPeriodUnitIOS",
introductoryPrice, @"introductoryPrice",
Expand Down Expand Up @@ -452,4 +454,11 @@ - (NSDictionary *)getPurchaseData:(SKPaymentTransaction *)transaction {
return [NSString stringWithFormat:@"%p", instance];
}

static NSString *localeIdentifierToBCP47(NSString* localeIdentifier)
{
// e.g. `en_US@currency=USD` -> `en-US`.
NSString *identifier = [[product.priceLocale.localeIdentifier componentsSeparatedByString:@"@"] objectAtIndex:0];
return [identifier stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
}

@end

0 comments on commit e62ccb4

Please sign in to comment.