Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the language code to iTunes search api to get localized release notes #443

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/src/itunes_search_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ class ITunesSearchAPI {
/// ```lookupURLByBundleId('com.google.Maps');```
/// ```lookupURLByBundleId('com.google.Maps', country: 'FR');```
Future<Map?> lookupByBundleId(String bundleId,
{String? country = 'US', bool useCacheBuster = true}) async {
{String? country = 'US',
String? language = 'en',
bool useCacheBuster = true}) async {
assert(bundleId.isNotEmpty);
if (bundleId.isEmpty) {
return null;
}

final url = lookupURLByBundleId(bundleId,
country: country ?? '', useCacheBuster: useCacheBuster)!;
country: country ?? '',
language: language ?? '',
useCacheBuster: useCacheBuster)!;
if (debugLogging) {
print('upgrader: download: $url');
}
Expand Down Expand Up @@ -94,14 +98,18 @@ class ITunesSearchAPI {
/// ```lookupURLByBundleId('com.google.Maps');```
/// ```lookupURLByBundleId('com.google.Maps', country: 'FR');```
String? lookupURLByBundleId(String bundleId,
{String country = 'US', bool useCacheBuster = true}) {
{String country = 'US',
String language = 'en',
bool useCacheBuster = true}) {
if (bundleId.isEmpty) {
return null;
}

return lookupURLByQSP(
{'bundleId': bundleId, 'country': country.toUpperCase()},
useCacheBuster: useCacheBuster);
return lookupURLByQSP({
'bundleId': bundleId,
'country': country.toUpperCase(),
'lang': language
}, useCacheBuster: useCacheBuster);
}

/// Look up URL by id.
Expand Down
31 changes: 31 additions & 0 deletions lib/src/upgrader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,37 @@ class Upgrader with WidgetsBindingObserver {
state.countryCodeOverride ?? findCountryCode(locale: locale);
if (state.debugLogging) {
print('upgrader: countryCode: $country');
// The language code of the locale, defaulting to `en`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks old and is already in the master branch. Can you check your PR merge point to see that it points to the latest code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks old and is already in the master branch. Can you check your PR merge point to see that it points to the latest code.

Sorry @larryaasen I would be very happy to fix the merge conflicts but since I am not working on the project that uses this package I will need more time to check how the code is working and that my changes are working well and I am little bit busy these days with another projects so look in to the other similar PRs.

final language = languageCode ?? findLanguageCode();
if (debugLogging) {
print('upgrader: languageCode: $language');
}

// Get Android version from Google Play Store, or
// get iOS version from iTunes Store.
if (upgraderOS.isAndroid) {
await _getAndroidStoreVersion(country: country, language: language);
} else if (upgraderOS.isIOS) {
final iTunes = ITunesSearchAPI();
iTunes.debugLogging = debugLogging;
iTunes.client = client;
final response = await (iTunes
.lookupByBundleId(_packageInfo!.packageName, language: language,
country:country));

if (response != null) {
_appStoreVersion = iTunes.version(response);
_appStoreListingURL = iTunes.trackViewUrl(response);
_releaseNotes ??= iTunes.releaseNotes(response);
final mav = iTunes.minAppVersion(response);
if (mav != null) {
minAppVersion = mav.toString();
if (debugLogging) {
print('upgrader: ITunesResults.minAppVersion: $minAppVersion');
}
}
}
}
}

// Determine the language code of the locale, defaulting to `en`.
Expand Down
9 changes: 7 additions & 2 deletions test/itunes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ void main() {
expect(
iTunes.lookupURLByBundleId('com.google.Maps', useCacheBuster: false),
equals(
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US'));
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&lang=en'));
expect(
iTunes.lookupURLByBundleId('com.google.Maps',
useCacheBuster: false, language: 'ar'),
equals(
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&lang=ar'));
expect(iTunes.lookupURLById('585027354', useCacheBuster: false),
equals('https://itunes.apple.com/lookup?id=585027354&country=US'));
expect(
Expand All @@ -30,7 +35,7 @@ void main() {

// Test the URL using the cache buster and remove it from the URL
const testUrl =
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&_cb=';
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&lang=en&_cb=';
final url = iTunes
.lookupURLByBundleId('com.google.Maps', useCacheBuster: true)!
.substring(0, testUrl.length);
Expand Down
Loading