Skip to content

Commit b46f004

Browse files
Enhancement/update locale (Baseflow#223)
* 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
1 parent 81d9199 commit b46f004

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed

geocoding/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.0.0
2+
3+
* **BREAKING CHANGES**:
4+
- 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.
5+
- Updates documentation related to setting the locale.
6+
- Added `setLocaleIdentifier` to the example app.
7+
- Updates `geocoding_ios` version to 3.0.0.
8+
19
## 2.2.2
210

311
- Updates documentation for isPresent().

geocoding/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import 'package:geocoding/geocoding.dart';
5757
List<Placemark> placemarks = await placemarkFromCoordinates(52.2165157, 6.9437819);
5858
```
5959

60-
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:
60+
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:
6161

6262
Locale identifier | Description
6363
----------------- | -----------

geocoding/example/lib/main.dart

+25
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
136136
});
137137
}),
138138
),
139+
const Padding(
140+
padding: EdgeInsets.only(top: 8),
141+
),
142+
Center(
143+
child: ElevatedButton(
144+
child: Text('Set locale en_US'),
145+
onPressed: () {
146+
setLocaleIdentifier("en_US").then((_) {
147+
setState(() {});
148+
});
149+
})),
150+
const Padding(
151+
padding: EdgeInsets.only(top: 8),
152+
),
153+
Center(
154+
child: ElevatedButton(
155+
child: Text('Set locale nl_NL'),
156+
onPressed: () {
157+
setLocaleIdentifier("nl_NL").then((_) {
158+
setState(() {});
159+
});
160+
})),
161+
const Padding(
162+
padding: EdgeInsets.only(top: 8),
163+
),
139164
Expanded(
140165
child: SingleChildScrollView(
141166
child: Container(

geocoding/lib/geocoding.dart

+17-16
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ export 'package:geocoding_platform_interface/geocoding_platform_interface.dart';
1010
/// However in some situations where the supplied address could not be
1111
/// resolved into a single [Location], multiple [Location] instances may be
1212
/// returned.
13-
///
14-
/// Optionally you can specify a locale in which the results are returned.
15-
/// When not supplied the currently active locale of the device will be used.
16-
/// The `localeIdentifier` should be formatted using the syntax:
17-
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
1813
Future<List<Location>> locationFromAddress(
19-
String address, {
20-
String? localeIdentifier,
21-
}) =>
14+
String address,
15+
) =>
2216
GeocodingPlatform.instance!.locationFromAddress(
2317
address,
2418
);
@@ -30,21 +24,28 @@ Future<List<Location>> locationFromAddress(
3024
/// However in some situations where the supplied coordinates could not be
3125
/// resolved into a single [Placemark], multiple [Placemark] instances may be
3226
/// returned.
33-
///
34-
/// Optionally you can specify a locale in which the results are returned.
35-
/// When not supplied the currently active locale of the device will be used.
36-
/// The `localeIdentifier` should be formatted using the syntax:
37-
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
3827
Future<List<Placemark>> placemarkFromCoordinates(
3928
double latitude,
40-
double longitude, {
41-
String? localeIdentifier,
42-
}) =>
29+
double longitude,
30+
) =>
4331
GeocodingPlatform.instance!.placemarkFromCoordinates(
4432
latitude,
4533
longitude,
4634
);
4735

36+
/// Overrides default locale
37+
///
38+
/// You can specify a locale in which the results are returned.
39+
/// When not used the current active locale of the device will be used.
40+
/// The `localeIdentifier` should be formatted using the syntax:
41+
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
42+
Future<void> setLocaleIdentifier(
43+
String localeIdentifier,
44+
) =>
45+
GeocodingPlatform.instance!.setLocaleIdentifier(
46+
localeIdentifier,
47+
);
48+
4849
/// Returns true if there is a geocoder implementation present that may return results.
4950
/// If true, there is still no guarantee that any individual geocoding attempt will succeed.
5051
///

geocoding/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: geocoding
22
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
3-
version: 2.2.2
3+
version: 3.0.0
44
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding
55
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues
66

@@ -14,7 +14,7 @@ dependencies:
1414

1515
geocoding_platform_interface: ^3.0.0
1616
geocoding_android: ^3.0.0
17-
geocoding_ios: ^2.0.0
17+
geocoding_ios: ^3.0.0
1818

1919
dev_dependencies:
2020
flutter_test:

geocoding/test/geocoding_test.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,16 @@ class MockGeocodingPlatform extends Mock
4848
GeocodingPlatform {
4949
@override
5050
Future<List<Location>> locationFromAddress(
51-
String address, {
52-
String? localeIdentifier,
53-
}) async {
51+
String address,
52+
) async {
5453
return [mockLocation];
5554
}
5655

5756
@override
5857
Future<List<Placemark>> placemarkFromCoordinates(
5958
double latitude,
60-
double longitude, {
61-
String? localeIdentifier,
62-
}) async {
59+
double longitude,
60+
) async {
6361
return [mockPlacemark];
6462
}
6563
}

0 commit comments

Comments
 (0)