Skip to content

[localization] Add better support for Chinese languages (fix #877)#878

Merged
LukasPaczos merged 3 commits intomapbox:masterfrom
zhao-gang:fix-877
Mar 22, 2019
Merged

[localization] Add better support for Chinese languages (fix #877)#878
LukasPaczos merged 3 commits intomapbox:masterfrom
zhao-gang:fix-877

Conversation

@zhao-gang
Copy link
Copy Markdown
Contributor

This PR aims to add better support for Chinese languages in localization plugin. With this change the plugin can support more types of Android system Chinese Locales and has better support for mapbox-streets-v8's new name_zh_Hant Traditional Chinese labels.

Copy link
Copy Markdown
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

What do you think about adding various Chinese languages statically during MapLocale initialization with the most precise scenario, which would be the streets-v8 branch? This way, we could check if the provided language will work with the current source when setting the language, for example when setting the name_zh-Hant for streets-v6 we'd convert it to name_zh. Similarly to what we have in place here, but reversed. This approach would also work regardless of the style changes in the runtime (that might introduce new sources).

Also, CI is failing because of the inlined variables:

> Task :plugin-localization:checkstyle FAILED
[ant:checkstyle] [ERROR] /root/code/plugin-localization/src/main/java/com/mapbox/mapboxsdk/plugins/localization/LocalizationPlugin.java:143:5: Each variable declaration must be in its own statement. [MultipleVariableDeclarations]
[ant:checkstyle] [ERROR] /root/code/plugin-localization/src/main/java/com/mapbox/mapboxsdk/plugins/localization/LocalizationPlugin.java:144:5: Each variable declaration must be in its own statement. [MultipleVariableDeclarations]

if (!mapLanguage.equals(MapLocale.ENGLISH)) {
if (mapLanguage.equals(MapLocale.CHINESE)) {
// in streets v8 tiles chinese is declared as "name_zh-Hant" instead of "name_zh"
mapLanguage = MapLocale.CHINESE_V8;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is still needed, otherwise, we'll break the compatibility of MapLocale.CHINESE with streets-v8 sources.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be ignored if the proposed solution is implemented.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the current implementation, this is still needed.

@zhao-gang
Copy link
Copy Markdown
Contributor Author

@LukasPaczos Hi. I think your suggestion is reasonable and have made the changes you requested. Also rebased this PR to current master.

Locale PRC is the same as Locale CHINA as they are both aliases for
Locale SIMPLIFIED_CHINESE. Changed Locale PRC to Locale TAIWAN so we
can support Traditional Chinese locale. Traditional Chinese locale is
supported in mapbox-streets-v8 as name_zh-Hant.
Different mapbox-streets source versions have different levels/types
of support for Chinese languages. Android system's Chinese Locales
also changed in different android versions. Add support for above
conditions.
Copy link
Copy Markdown
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for addressing the comments. Last 2 below and we should be ready to merge.

if (!mapLanguage.equals(MapLocale.ENGLISH)) {
if (mapLanguage.equals(MapLocale.CHINESE)) {
// in streets v8 tiles chinese is declared as "name_zh-Hant" instead of "name_zh"
mapLanguage = MapLocale.CHINESE_V8;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the current implementation, this is still needed.

for (Source source : style.getSources()) {
if (sourceIsFromMapbox(source)) {
boolean isStreetsV8 = sourceIsStreetsV8(source);
boolean isStreetsV7 = sourceIsStreetsV7(source);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This check can be moved to line 242, otherwise, it's going to be redundant for streets-v8 sources.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have made above two changes(name_zh should be changed to name_zh_Hans in streets v8, as they both represent Simplified Chinese). I also changed Locale.CHINA's default MapLocale to MapLocale.CHINESE_HANS, since in streets v8 Simplified Chinese should use name_zh_Hans.

Copy link
Copy Markdown
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

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

🎉

@LukasPaczos LukasPaczos merged commit a28d093 into mapbox:master Mar 22, 2019
@zhao-gang zhao-gang deleted the fix-877 branch March 23, 2019 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants