Skip to content

Commit 4ff7689

Browse files
author
Langston Smith
authored
Adding Vietnamese and Italian support to Localization Plugin (#1098)
1 parent b92a751 commit 4ff7689

File tree

3 files changed

+99
-39
lines changed

3 files changed

+99
-39
lines changed

app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/localization/LocalizationActivity.kt

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,38 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {
2727
Toast.makeText(this, R.string.change_language_instruction, Toast.LENGTH_LONG).show()
2828
mapView.onCreate(savedInstanceState)
2929
mapView.getMapAsync(this)
30+
}
3031

31-
fabLocalize.setOnClickListener {
32-
mapIsLocalized = if (mapIsLocalized) {
33-
localizationPlugin?.setMapLanguage(MapLocale(MapLocale.FRENCH))
34-
Toast.makeText(this, R.string.map_not_localized, Toast.LENGTH_SHORT).show()
35-
false
36-
} else {
37-
localizationPlugin?.matchMapLanguageWithDeviceDefault()
38-
Toast.makeText(this, R.string.map_localized, Toast.LENGTH_SHORT).show()
39-
true
32+
override fun onMapReady(mapboxMap: MapboxMap) {
33+
mapboxMap.setStyle(Style.MAPBOX_STREETS) { style ->
34+
this.mapboxMap = mapboxMap
35+
localizationPlugin = LocalizationPlugin(mapView, mapboxMap, style).also { localizationPlugin ->
36+
localizationPlugin.matchMapLanguageWithDeviceDefault()
4037
}
41-
}
4238

43-
fabCamera.setOnClickListener {
44-
val locale = nextMapLocale
45-
localizationPlugin?.setMapLanguage(locale)
46-
localizationPlugin?.setCameraToLocaleCountry(locale, 25)
47-
}
39+
fabLocalize.setOnClickListener {
40+
mapIsLocalized = if (mapIsLocalized) {
41+
localizationPlugin?.setMapLanguage(MapLocale(MapLocale.FRENCH))
42+
Toast.makeText(this, R.string.map_not_localized, Toast.LENGTH_SHORT).show()
43+
false
44+
} else {
45+
localizationPlugin?.matchMapLanguageWithDeviceDefault()
46+
Toast.makeText(this, R.string.map_localized, Toast.LENGTH_SHORT).show()
47+
true
48+
}
49+
}
4850

49-
fabStyles.setOnClickListener {
50-
mapboxMap?.setStyle(Style.Builder().fromUri(Utils.nextStyle))
51-
}
52-
}
51+
fabCamera.setOnClickListener {
52+
val locale = nextMapLocale
53+
localizationPlugin?.apply {
54+
setMapLanguage(locale)
55+
setCameraToLocaleCountry(locale, 25)
56+
}
57+
}
5358

54-
override fun onMapReady(mapboxMap: MapboxMap) {
55-
this.mapboxMap = mapboxMap
56-
mapboxMap.setStyle(Style.MAPBOX_STREETS) {
57-
localizationPlugin = LocalizationPlugin(mapView, mapboxMap, it)
58-
localizationPlugin?.matchMapLanguageWithDeviceDefault()
59+
fabStyles.setOnClickListener {
60+
mapboxMap.setStyle(Style.Builder().fromUri(Utils.nextStyle))
61+
}
5962
}
6063
}
6164

@@ -145,6 +148,14 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {
145148
localizationPlugin?.setMapLanguage(MapLocale.KOREAN)
146149
return true
147150
}
151+
R.id.vietnamese -> {
152+
localizationPlugin?.setMapLanguage(MapLocale.VIETNAMESE)
153+
return true
154+
}
155+
R.id.italian -> {
156+
localizationPlugin?.setMapLanguage(MapLocale.ITALIAN)
157+
return true
158+
}
148159
R.id.local -> {
149160
localizationPlugin?.setMapLanguage(MapLocale.LOCAL_NAME)
150161
return true
@@ -159,7 +170,10 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {
159170

160171
companion object {
161172

162-
private val LOCALES = arrayOf(MapLocale.CANADA, MapLocale.GERMANY, MapLocale.CHINA, MapLocale.US, MapLocale.CANADA_FRENCH, MapLocale.JAPAN, MapLocale.KOREA, MapLocale.FRANCE, MapLocale.SPAIN)
173+
private val LOCALES = arrayOf(MapLocale.CANADA, MapLocale.GERMANY, MapLocale.CHINA,
174+
MapLocale.US, MapLocale.CANADA_FRENCH, MapLocale.JAPAN, MapLocale.KOREA,
175+
MapLocale.FRANCE, MapLocale.SPAIN, MapLocale.VIETNAM, MapLocale.ITALY, MapLocale.UK
176+
)
163177

164178
private var index: Int = 0
165179

app/src/main/res/menu/menu_languages.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@
5858
android:title="Korean"
5959
app:showAsAction="never"/>
6060

61+
<item
62+
android:id="@+id/vietnamese"
63+
android:title="Vietnamese"
64+
app:showAsAction="never"/>
65+
66+
<item
67+
android:id="@+id/italian"
68+
android:title="Italian"
69+
app:showAsAction="never"/>
70+
6171
<item
6272
android:id="@+id/local"
6373
android:title="Local names"

plugin-localization/src/main/java/com/mapbox/mapboxsdk/plugins/localization/MapLocale.java

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ public final class MapLocale {
106106
*/
107107
public static final String KOREAN = "name_ko";
108108

109+
/**
110+
* Vietnamese (if available)
111+
*/
112+
public static final String VIETNAMESE = "name_vi";
113+
114+
/**
115+
* Italy (if available)
116+
*/
117+
public static final String ITALIAN = "name_it";
118+
109119
@Retention(SOURCE)
110120
@StringDef( {LOCAL_NAME, ARABIC, CHINESE, SIMPLIFIED_CHINESE, TRADITIONAL_CHINESE, ENGLISH,
111-
FRENCH, GERMAN, JAPANESE, KOREAN, PORTUGUESE, RUSSIAN, SPANISH})
121+
FRENCH, GERMAN, JAPANESE, KOREAN, PORTUGUESE, RUSSIAN, SPANISH, VIETNAMESE, ITALIAN})
112122
public @interface Languages {
113123
}
114124

@@ -117,96 +127,110 @@ public final class MapLocale {
117127
*/
118128

119129
/**
120-
* USA Bounding box excluding Hawaii and Alaska extracted from Open Street Map
130+
* Approximate USA bounding box, excluding Hawaii and Alaska
121131
*/
122132
static final LatLngBounds USA_BBOX = new LatLngBounds.Builder()
123133
.include(new LatLng(49.388611, -124.733253))
124134
.include(new LatLng(24.544245, -66.954811)).build();
125135

126136
/**
127-
* UK Bounding Box extracted from Open Street Map
137+
* Approximate UK bounding box
128138
*/
129139
static final LatLngBounds UK_BBOX = new LatLngBounds.Builder()
130140
.include(new LatLng(59.360249, -8.623555))
131141
.include(new LatLng(49.906193, 1.759)).build();
132142

133143
/**
134-
* Canada Bounding Box extracted from Open Street Map
144+
* Approximate Canada bounding box
135145
*/
136146
static final LatLngBounds CANADA_BBOX = new LatLngBounds.Builder()
137147
.include(new LatLng(83.110626, -141.0))
138148
.include(new LatLng(41.67598, -52.636291)).build();
139149

140150
/**
141-
* China Bounding Box extracted from Open Street Map
151+
* Approximate China bounding box
142152
*/
143153
static final LatLngBounds CHINA_BBOX = new LatLngBounds.Builder()
144154
.include(new LatLng(53.56086, 73.557693))
145155
.include(new LatLng(15.775416, 134.773911)).build();
146156

147157
/**
148-
* Taiwan Bounding Box extracted from Open Street Map
158+
* Approximate Taiwan bounding box
149159
*/
150160
static final LatLngBounds TAIWAN_BBOX = new LatLngBounds.Builder()
151161
.include(new LatLng(26.389444, 118.115255566105))
152162
.include(new LatLng(21.733333, 122.107778)).build();
153163

154164
/**
155-
* Germany Bounding Box extracted from Open Street Map
165+
* Approximate Germany bounding box
156166
*/
157167
static final LatLngBounds GERMANY_BBOX = new LatLngBounds.Builder()
158168
.include(new LatLng(55.055637, 5.865639))
159169
.include(new LatLng(47.275776, 15.039889)).build();
160170

161171
/**
162-
* Korea Bounding Box extracted from Open Street Map
172+
* Approximate Korea bounding box
163173
*/
164174
static final LatLngBounds KOREA_BBOX = new LatLngBounds.Builder()
165175
.include(new LatLng(38.612446, 125.887108))
166176
.include(new LatLng(33.190945, 129.584671)).build();
167177

168178
/**
169-
* Japan Bounding Box extracted from Open Street Map
179+
* Approximate Japan bounding box
170180
*/
171181
static final LatLngBounds JAPAN_BBOX = new LatLngBounds.Builder()
172182
.include(new LatLng(45.52314, 122.93853))
173183
.include(new LatLng(24.249472, 145.820892)).build();
174184

175185
/**
176-
* France Bounding Box extracted from Open Street Map
186+
* Approximate France bounding box
177187
*/
178188
static final LatLngBounds FRANCE_BBOX = new LatLngBounds.Builder()
179189
.include(new LatLng(51.092804, -5.142222))
180190
.include(new LatLng(41.371582, 9.561556)).build();
181191

182192
/**
183-
* Russian Bounding box extracted from Open Street Map
193+
* Approximate Russian bounding box
184194
*/
185195
static final LatLngBounds RUSSIA_BBOX = new LatLngBounds.Builder()
186196
.include(new LatLng(81.856903, -168.997849))
187197
.include(new LatLng(41.185902, 19.638861)).build();
188198

189199
/**
190-
* Spain Bounding box extracted from Open Street Map
200+
* Approximate Spain bounding box
191201
*/
192202
static final LatLngBounds SPAIN_BBOX = new LatLngBounds.Builder()
193203
.include(new LatLng(27.4335426, -18.3936845))
194204
.include(new LatLng(43.9933088, 4.5918885)).build();
195205

196206
/**
197-
* Portugal Bounding box extracted from Open Street Map
207+
* Approximate Portugal bounding box
198208
*/
199209
static final LatLngBounds PORTUGAL_BBOX = new LatLngBounds.Builder()
200210
.include(new LatLng(27.4335426, -18.3936845))
201211
.include(new LatLng(42.280468655, -6.3890876937)).build();
202212

203213
/**
204-
* Brazil Bounding box extracted from Open Street Map
214+
* Approximate Brazil bounding box
205215
*/
206216
static final LatLngBounds BRAZIL_BBOX = new LatLngBounds.Builder()
207217
.include(new LatLng(5.2842873, -33.8689056))
208218
.include(new LatLng(-28.6341164, -73.9830625)).build();
209219

220+
/**
221+
* Approximate Vietnam bounding box
222+
*/
223+
static final LatLngBounds VIETNAM_BBOX = new LatLngBounds.Builder()
224+
.include(new LatLng(8.383333, 102.216667))
225+
.include(new LatLng(23.666667, 109.466667)).build();
226+
227+
/**
228+
* Approximate Italy bounding box
229+
*/
230+
static final LatLngBounds ITALY_BBOX = new LatLngBounds.Builder()
231+
.include(new LatLng(36.619987291,6.7499552751))
232+
.include(new LatLng(47.1153931748,18.4802470232)).build();
233+
210234
/*
211235
* Some MapLocales already defined (these match with the predefined ones in the Locale class)
212236
*/
@@ -291,6 +315,16 @@ public final class MapLocale {
291315
*/
292316
public static final MapLocale BRAZIL = new MapLocale(PORTUGUESE, BRAZIL_BBOX);
293317

318+
/**
319+
* Useful constant for country.
320+
*/
321+
public static final MapLocale VIETNAM = new MapLocale(VIETNAMESE, VIETNAM_BBOX);
322+
323+
/**
324+
* Useful constant for country.
325+
*/
326+
public static final MapLocale ITALY = new MapLocale(ITALIAN, ITALY_BBOX);
327+
294328
/**
295329
* Maps out the Matching pair of {@link Locale} and {@link MapLocale}. In other words, if I have a
296330
* {@link Locale#CANADA}, this should be matched up with {@link MapLocale#CANADA}.
@@ -313,6 +347,8 @@ public final class MapLocale {
313347
LOCALE_SET.put(new Locale("es", "ES"), SPAIN);
314348
LOCALE_SET.put(new Locale("pt", "PT"), PORTUGAL);
315349
LOCALE_SET.put(new Locale("pt", "BR"), BRAZIL);
350+
LOCALE_SET.put(new Locale("vi", "VN"), VIETNAM);
351+
LOCALE_SET.put(Locale.ITALY, MapLocale.ITALY);
316352

317353
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
318354
Locale zh_CN_Hans = new Locale.Builder().setLanguage("zh").setRegion("CN").setScript("Hans").build();

0 commit comments

Comments
 (0)