Skip to content

Commit

Permalink
Enhancement/update locale (#223)
Browse files Browse the repository at this point in the history
* updates documentation regarding setting the locale. And changes function signature where the locale changes are applied. Adds setting the locale to the example app.

* added setting the locale
  • Loading branch information
TimHoogstrate committed Mar 13, 2024
1 parent 81d9199 commit b46f004
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 25 deletions.
8 changes: 8 additions & 0 deletions geocoding/CHANGELOG.md
@@ -1,3 +1,11 @@
## 3.0.0

* **BREAKING CHANGES**:
- Locale is no longer part of the `locationFromAddress` and `placemarkFromAddress`, but should be set first by `setLocaleIdentifier`. This was already implemented on Android but is now working similarly on iOS.
- Updates documentation related to setting the locale.
- Added `setLocaleIdentifier` to the example app.
- Updates `geocoding_ios` version to 3.0.0.

## 2.2.2

- Updates documentation for isPresent().
Expand Down
2 changes: 1 addition & 1 deletion geocoding/README.md
Expand Up @@ -57,7 +57,7 @@ import 'package:geocoding/geocoding.dart';
List<Placemark> placemarks = await placemarkFromCoordinates(52.2165157, 6.9437819);
```

Both the `locationFromAddress` and `placemarkFromCoordinates` accept an optional `localeIdentifier` parameter. This parameter can be used to enforce the results to be formatted (and translated) according to the specified locale. The `localeIdentifier` should be formatted using the syntax: [languageCode]_[countryCode]. Use the [ISO 639-1 or ISO 639-2](http://www.loc.gov/standards/iso639-2/php/English_list.php) standard for the language code and the 2 letter [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard for the country code. Some examples are:
The setLocaleIdentifier with the `localeIdentifier` parameter can be used to enforce the results to be formatted (and translated) according to the specified locale. The `localeIdentifier` should be formatted using the syntax: [languageCode]_[countryCode]. Use the [ISO 639-1 or ISO 639-2](http://www.loc.gov/standards/iso639-2/php/English_list.php) standard for the language code and the 2 letter [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard for the country code. Some examples are:

Locale identifier | Description
----------------- | -----------
Expand Down
25 changes: 25 additions & 0 deletions geocoding/example/lib/main.dart
Expand Up @@ -136,6 +136,31 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
});
}),
),
const Padding(
padding: EdgeInsets.only(top: 8),
),
Center(
child: ElevatedButton(
child: Text('Set locale en_US'),
onPressed: () {
setLocaleIdentifier("en_US").then((_) {
setState(() {});
});
})),
const Padding(
padding: EdgeInsets.only(top: 8),
),
Center(
child: ElevatedButton(
child: Text('Set locale nl_NL'),
onPressed: () {
setLocaleIdentifier("nl_NL").then((_) {
setState(() {});
});
})),
const Padding(
padding: EdgeInsets.only(top: 8),
),
Expanded(
child: SingleChildScrollView(
child: Container(
Expand Down
33 changes: 17 additions & 16 deletions geocoding/lib/geocoding.dart
Expand Up @@ -10,15 +10,9 @@ export 'package:geocoding_platform_interface/geocoding_platform_interface.dart';
/// However in some situations where the supplied address could not be
/// resolved into a single [Location], multiple [Location] instances may be
/// returned.
///
/// Optionally you can specify a locale in which the results are returned.
/// When not supplied the currently active locale of the device will be used.
/// The `localeIdentifier` should be formatted using the syntax:
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
Future<List<Location>> locationFromAddress(
String address, {
String? localeIdentifier,
}) =>
String address,
) =>
GeocodingPlatform.instance!.locationFromAddress(
address,
);
Expand All @@ -30,21 +24,28 @@ Future<List<Location>> locationFromAddress(
/// However in some situations where the supplied coordinates could not be
/// resolved into a single [Placemark], multiple [Placemark] instances may be
/// returned.
///
/// Optionally you can specify a locale in which the results are returned.
/// When not supplied the currently active locale of the device will be used.
/// The `localeIdentifier` should be formatted using the syntax:
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
Future<List<Placemark>> placemarkFromCoordinates(
double latitude,
double longitude, {
String? localeIdentifier,
}) =>
double longitude,
) =>
GeocodingPlatform.instance!.placemarkFromCoordinates(
latitude,
longitude,
);

/// Overrides default locale
///
/// You can specify a locale in which the results are returned.
/// When not used the current active locale of the device will be used.
/// The `localeIdentifier` should be formatted using the syntax:
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
Future<void> setLocaleIdentifier(
String localeIdentifier,
) =>
GeocodingPlatform.instance!.setLocaleIdentifier(
localeIdentifier,
);

/// Returns true if there is a geocoder implementation present that may return results.
/// If true, there is still no guarantee that any individual geocoding attempt will succeed.
///
Expand Down
4 changes: 2 additions & 2 deletions geocoding/pubspec.yaml
@@ -1,6 +1,6 @@
name: geocoding
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
version: 2.2.2
version: 3.0.0
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues

Expand All @@ -14,7 +14,7 @@ dependencies:

geocoding_platform_interface: ^3.0.0
geocoding_android: ^3.0.0
geocoding_ios: ^2.0.0
geocoding_ios: ^3.0.0

dev_dependencies:
flutter_test:
Expand Down
10 changes: 4 additions & 6 deletions geocoding/test/geocoding_test.dart
Expand Up @@ -48,18 +48,16 @@ class MockGeocodingPlatform extends Mock
GeocodingPlatform {
@override
Future<List<Location>> locationFromAddress(
String address, {
String? localeIdentifier,
}) async {
String address,
) async {
return [mockLocation];
}

@override
Future<List<Placemark>> placemarkFromCoordinates(
double latitude,
double longitude, {
String? localeIdentifier,
}) async {
double longitude,
) async {
return [mockPlacemark];
}
}

0 comments on commit b46f004

Please sign in to comment.