[android] Add setting for change map language #8237

Merged
krozhdestvenski merged 2 commits from map_lang_v2 into master 2024-11-06 19:14:24 +00:00
krozhdestvenski commented 2024-05-20 12:23:55 +00:00 (Migrated from github.com)

This solution is equivalent to organicmaps/organicmaps#8187.
But now we use global namespace languages for get map locale instead of contex using.

This solution is equivalent to https://git.omaps.dev/organicmaps/organicmaps/pulls/8187. But now we use global namespace languages for get map locale instead of contex using.
biodranik (Migrated from github.com) reviewed 2024-05-20 12:23:55 +00:00
biodranik (Migrated from github.com) reviewed 2024-05-20 12:53:06 +00:00
@ -53,6 +53,7 @@ ReadManager::ReadManager(ref_ptr<ThreadsCommutator> commutator, MapDataProvider
, m_counter(0)
biodranik (Migrated from github.com) commented 2024-05-20 12:53:06 +00:00

Why is it "en" instead of a system-defined one?

Why is it "en" instead of a system-defined one?
krozhdestvenski (Migrated from github.com) reviewed 2024-05-20 13:14:26 +00:00
@ -53,6 +53,7 @@ ReadManager::ReadManager(ref_ptr<ThreadsCommutator> commutator, MapDataProvider
, m_counter(0)
krozhdestvenski (Migrated from github.com) commented 2024-05-20 13:14:26 +00:00

as a default international language.
but you are right. the best way - using languages::GetCurrentNorm() for initialization.
i updated main PR.

as a default international language. but you are right. the best way - using languages::GetCurrentNorm() for initialization. i updated main PR.
biodranik (Migrated from github.com) reviewed 2024-05-20 19:59:58 +00:00
biodranik (Migrated from github.com) commented 2024-05-20 19:36:55 +00:00

Does it make sense to call Save inside Set and only have Set call here for simplicity?

Does it make sense to call Save inside Set and only have Set call here for simplicity?
biodranik (Migrated from github.com) commented 2024-05-20 19:46:27 +00:00

MapLocale term was not used before in the code, it's better to avoid introducing it.

    std::string languageCode;
    if (!settings::Get(settings::kMapLanguageCode, languageCode) || languageCode.empty());
      languageCode = languages::GetCurrentNorm(); 
    
    return jni::ToJavaString(env, languageCode);
MapLocale term was not used before in the code, it's better to avoid introducing it. ```suggestion std::string languageCode; if (!settings::Get(settings::kMapLanguageCode, languageCode) || languageCode.empty()); languageCode = languages::GetCurrentNorm(); return jni::ToJavaString(env, languageCode); ```
biodranik (Migrated from github.com) commented 2024-05-20 19:57:15 +00:00

I've get lost a bit. Why is the drape implementation present in the alternative implementation? Can we avoid passing any messages in Drape at all?

I've get lost a bit. Why is the drape implementation present in the alternative implementation? Can we avoid passing any messages in Drape at all?
biodranik (Migrated from github.com) commented 2024-05-20 19:54:03 +00:00

This is not our code style.

void Framework::SetMapLocale(std::string const & locale)
This is not our code style. ```suggestion void Framework::SetMapLocale(std::string const & locale) ```
biodranik (Migrated from github.com) commented 2024-05-20 19:54:13 +00:00

JNI code can directly call settings::Set, why is this wrapper needed?

JNI code can directly call settings::Set, why is this wrapper needed?
biodranik (Migrated from github.com) commented 2024-05-20 19:54:18 +00:00

Is this wrapper really needed?

Is this wrapper really needed?
biodranik (Migrated from github.com) commented 2024-05-20 19:53:19 +00:00

No need in extra line.

No need in extra line.
biodranik (Migrated from github.com) commented 2024-05-20 19:53:33 +00:00

Merge two into one?

Merge two into one?
biodranik (Migrated from github.com) commented 2024-05-20 19:52:31 +00:00

This retrieves a system locale language code. What happens if it doesn't match the supported language in the coding/string_utf8_multilang.cpp ?

This retrieves a system locale language code. What happens if it doesn't match the supported language in the coding/string_utf8_multilang.cpp ?
biodranik (Migrated from github.com) commented 2024-05-20 19:53:05 +00:00
  if (!settings::Get(settings::kMapLocale, locale) || locale.empty())
```suggestion if (!settings::Get(settings::kMapLocale, locale) || locale.empty()) ```
biodranik (Migrated from github.com) commented 2024-05-20 19:47:50 +00:00
char const * kMapLanguageCode = "MapLanguageCode";
```suggestion char const * kMapLanguageCode = "MapLanguageCode"; ```
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 07:11:54 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 07:11:54 +00:00
  1. This would violate the single responsibility principle
  2. This would violate pattern that already used in framework (see Framework::Save3dMode)
1. This would violate the single responsibility principle 2. This would violate pattern that already used in framework (see Framework::Save3dMode)
biodranik (Migrated from github.com) reviewed 2024-05-21 07:33:03 +00:00
biodranik (Migrated from github.com) commented 2024-05-21 07:33:03 +00:00

Our main pattern in OM is simplicity, fewer lines of code doing the same are preferred over more lines of code. It's easier to read, debug, modify. Less chance of making a mistake.

Applying patterns blindly everywhere may not be the best strategy.

Our main pattern in OM is simplicity, fewer lines of code doing the same are preferred over more lines of code. It's easier to read, debug, modify. Less chance of making a mistake. Applying patterns blindly everywhere may not be the best strategy.
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 07:57:02 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 07:57:01 +00:00

the term "locale" also appears in the code(see search/processor.cpp). but "Language Code" is more common.
i'll rename it.

the term "locale" also appears in the code(see search/processor.cpp). but "Language Code" is more common. i'll rename it.
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 07:57:24 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 07:57:24 +00:00

i'll rename it.

i'll rename it.
biodranik (Migrated from github.com) reviewed 2024-05-21 08:10:18 +00:00
biodranik (Migrated from github.com) commented 2024-05-21 08:10:18 +00:00

Isn't that different? Search engine accepts system locale (the language of the system). While we're talking about a list of languages supported in the osm data.

Isn't that different? Search engine accepts system locale (the language of the system). While we're talking about a list of _languages_ supported in the osm data.
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 08:38:38 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 08:38:38 +00:00

I added a handler for this situation

I added a handler for this situation
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 08:40:24 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 08:40:24 +00:00

fixed

fixed
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 08:41:46 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 08:41:46 +00:00

see comment uppier

see comment uppier
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 08:41:53 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 08:41:53 +00:00

fixed

fixed
krozhdestvenski (Migrated from github.com) reviewed 2024-05-21 08:44:14 +00:00
krozhdestvenski (Migrated from github.com) commented 2024-05-21 08:44:14 +00:00

fixed

fixed
biodranik (Migrated from github.com) reviewed 2024-05-28 13:10:10 +00:00
biodranik (Migrated from github.com) commented 2024-05-28 13:10:10 +00:00

⬆️

⬆️
biodranik (Migrated from github.com) reviewed 2024-05-30 06:19:43 +00:00
biodranik (Migrated from github.com) commented 2024-05-30 06:11:46 +00:00

Are these changes necessary? Is it an accidental indentation change?

Are these changes necessary? Is it an accidental indentation change?
biodranik (Migrated from github.com) commented 2024-05-30 06:12:25 +00:00

Can this call be moved into the framework's call?

Can this call be moved into the framework's call?
@ -101,3 +112,4 @@
updateMapLanguageCodeSummary();
}
@Override
biodranik (Migrated from github.com) commented 2024-05-30 06:13:18 +00:00

Empty line?

Empty line?
@ -40,6 +40,7 @@
<string name="pref_power_management" translatable="false">PowerManagment</string>
biodranik (Migrated from github.com) commented 2024-05-30 06:14:37 +00:00

This should be properly translated later, when everything else is fixed.

This should be properly translated later, when everything else is fixed.
biodranik (Migrated from github.com) commented 2024-05-30 06:15:35 +00:00

Please double-check that you follow our style guide. It is described in docs folder.

bool StringUtf8Multilang::IsServiceLang(std::string_view lang)
{
  return lang == kLanguages[kDefaultCode].m_code
Please double-check that you follow our style guide. It is described in docs folder. ```suggestion bool StringUtf8Multilang::IsServiceLang(std::string_view lang) { return lang == kLanguages[kDefaultCode].m_code ```
@ -94,0 +104,4 @@
[](StringUtf8Multilang::Lang const & lang) { return lang.m_code != StringUtf8Multilang::kReservedLang; });
return langs;
}();
biodranik (Migrated from github.com) commented 2024-05-30 06:15:04 +00:00

Why?

Why?
biodranik (Migrated from github.com) commented 2024-05-30 06:19:24 +00:00

Is this whole drape code/message really needed? I don't see that m_mapLanguageCode is used anywhere.

There should be a way to initiate map redrawing in the framework, @vng right?

Is this whole drape code/message really needed? I don't see that `m_mapLanguageCode` is used anywhere. There should be a way to initiate map redrawing in the framework, @vng right?
biodranik (Migrated from github.com) reviewed 2024-05-31 08:26:16 +00:00
biodranik (Migrated from github.com) commented 2024-05-31 08:26:15 +00:00

⬆️

⬆️
biodranik (Migrated from github.com) reviewed 2024-06-09 22:31:43 +00:00
biodranik (Migrated from github.com) left a comment

This PR may also help with debugging on the desktop. @Ferenc- maybe you or some other Linux/Mac contributor can add a setting?

Here the drape code changes should be removed and replaced with Framework::InvalidateRect (you may try to pass mercator::Bounds::FullRect)

This PR may also help with debugging on the desktop. @Ferenc- maybe you or some other Linux/Mac contributor can add a setting? Here the drape code changes should be removed and replaced with `Framework::InvalidateRect` (you may try to pass `mercator::Bounds::FullRect`)
biodranik (Migrated from github.com) commented 2024-06-09 22:24:26 +00:00

Can any drape modification be avoided?

Can any drape modification be avoided?
biodranik (Migrated from github.com) reviewed 2024-06-10 20:16:42 +00:00
biodranik (Migrated from github.com) left a comment

Thanks!

@kirylkaveryn would it be hard to add the same setting on iOS and test it?

Thanks! @kirylkaveryn would it be hard to add the same setting on iOS and test it?
biodranik (Migrated from github.com) commented 2024-06-10 20:15:57 +00:00

Is it duplicated in several places?

Is it duplicated in several places?
biodranik (Migrated from github.com) commented 2024-06-10 20:15:04 +00:00
void Framework::SetMapLanguageCode(std::string const & languageCode)
```suggestion void Framework::SetMapLanguageCode(std::string const & languageCode) ```
biodranik (Migrated from github.com) commented 2024-06-10 20:15:21 +00:00

Good that you found an easy way )

Good that you found an easy way )
Jean-BaptisteC (Migrated from github.com) approved these changes 2024-06-18 06:16:34 +00:00
Jean-BaptisteC (Migrated from github.com) left a comment

Pixel 6 - Android 14

✅ Pixel 6 - Android 14
biodranik (Migrated from github.com) reviewed 2024-06-18 07:52:35 +00:00
biodranik (Migrated from github.com) commented 2024-06-18 07:52:34 +00:00

Can this check be moved into nativeGetSupportedLanguages(bool returnServiceLanguages) ?

Can this check be moved into `nativeGetSupportedLanguages(bool returnServiceLanguages)` ?
biodranik (Migrated from github.com) reviewed 2024-06-24 21:34:18 +00:00
biodranik (Migrated from github.com) left a comment

Thanks a lot for your efforts! We're almost there. A few comments after testing/reviewing.

Thanks a lot for your efforts! We're almost there. A few comments after testing/reviewing.
biodranik (Migrated from github.com) commented 2024-06-24 21:05:16 +00:00

Should it be removed?

Should it be removed?
biodranik (Migrated from github.com) commented 2024-06-24 18:29:36 +00:00

Where is it used?

Where is it used?
biodranik (Migrated from github.com) commented 2024-06-24 18:27:57 +00:00

Should it be removed?

Should it be removed?
biodranik (Migrated from github.com) commented 2024-06-24 18:29:00 +00:00
  public static native Language[] nativeGetSupportedLanguages(boolean alsoIncludeServiceLanguages);

Otherwise it reads as "return only service languages".

```suggestion public static native Language[] nativeGetSupportedLanguages(boolean alsoIncludeServiceLanguages); ``` Otherwise it reads as "return only service languages".
biodranik (Migrated from github.com) commented 2024-06-24 18:30:17 +00:00
  public void setListener(Listener listener)
  {
```suggestion public void setListener(Listener listener) { ```
biodranik (Migrated from github.com) commented 2024-06-24 18:57:00 +00:00
StringUtf8Multilang::Languages const & StringUtf8Multilang::GetSupportedLanguages(bool alsoIncludeServiceLanguages)
```suggestion StringUtf8Multilang::Languages const & StringUtf8Multilang::GetSupportedLanguages(bool alsoIncludeServiceLanguages) ```
biodranik (Migrated from github.com) commented 2024-06-24 21:08:35 +00:00

Can these variables be made static const, global (above the function), and initialized by lambdas?

Can these variables be made static const, global (above the function), and initialized by lambdas?
biodranik (Migrated from github.com) commented 2024-06-24 18:33:43 +00:00

Make it more consistent?

  [map_language]
Make it more consistent? ```suggestion [map_language] ```
biodranik (Migrated from github.com) commented 2024-06-24 18:51:41 +00:00
  1. This code is called way too often. Looks like a part of Drape should be reused to request the actual setting only when necessary, in ReadManager::Restart, and then pass the value via the EngineContext, similarly, as you did it before.

  2. Can it be simplified so that int8_t is stored in the settings instead of std::string, and then it should be enough to:

      int8_t languageCode = StringUtf8Multilang::kDefaultCode;
      settings::Get(settings::kMapLanguageCode, languageCode);
      // Use languageCode
1. This code is called way too often. Looks like a part of Drape should be reused to request the actual setting only when necessary, in `ReadManager::Restart`, and then pass the value via the EngineContext, similarly, as you did it before. 2. Can it be simplified so that `int8_t` is stored in the settings instead of `std::string`, and then it should be enough to: ``` int8_t languageCode = StringUtf8Multilang::kDefaultCode; settings::Get(settings::kMapLanguageCode, languageCode); // Use languageCode ```
biodranik (Migrated from github.com) commented 2024-06-24 18:40:16 +00:00

This change should be removed.

This change should be removed.
biodranik (Migrated from github.com) commented 2024-06-24 18:46:46 +00:00
    return {StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kDefaultCode)};
```suggestion return {StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kDefaultCode)}; ```
biodranik (Migrated from github.com) commented 2024-06-24 18:48:09 +00:00

Remove indentation below by negating the if:

  if (settings::Get(settings::kMapLanguageCode, languageCode) && !languageCode.empty())
    return languageCode;
Remove indentation below by negating the if: ```suggestion if (settings::Get(settings::kMapLanguageCode, languageCode) && !languageCode.empty()) return languageCode; ```
pastk approved these changes 2024-10-07 18:35:08 +00:00
@ -94,0 +107,4 @@
static const StringUtf8Multilang::Languages languagesWithoutService = []()
{
StringUtf8Multilang::Languages langs;

nit:
different formatting between languagesWithoutService (opening bracket on next line) and allLanguages (op bracket on the same line)

nit: different formatting between `languagesWithoutService` (opening bracket on next line) and `allLanguages` (op bracket on the same line)

prob a drape re-init will be required then (e.g. similar to gl/vk change)?
which is probably ok as map lang won't be changed often

prob a drape re-init will be required then (e.g. similar to gl/vk change)? which is probably ok as map lang won't be changed often
vng (Migrated from github.com) reviewed 2024-10-24 01:29:34 +00:00
vng (Migrated from github.com) left a comment

Please, check my comments, rebase and make 2 commits:

  • Actual changes
  • "[strings] Regenerated."
Please, check my comments, rebase and make 2 commits: - Actual changes - "[strings] Regenerated."
vng (Migrated from github.com) commented 2024-10-24 01:21:11 +00:00

nit: includeServiceLangs

nit: includeServiceLangs
vng (Migrated from github.com) commented 2024-10-24 01:21:03 +00:00

nit: includeServiceLangs

nit: includeServiceLangs
@ -39,0 +42,4 @@
if (existingLanguages.contains(lang.code))
continue;
languages.add(lang);
vng (Migrated from github.com) commented 2024-10-24 01:22:02 +00:00

Possible returned nil is ok here?

Possible returned nil is ok here?
@ -45,1 +52,4 @@
public void setListener(Listener listener)
{
this.mListener = listener;
vng (Migrated from github.com) commented 2024-10-24 01:20:48 +00:00

Why it is better than previous?

Why it is better than previous?
vng (Migrated from github.com) commented 2024-10-24 01:23:09 +00:00

nit: includeServiceLangs

nit: includeServiceLangs
vng (Migrated from github.com) commented 2024-10-24 01:19:58 +00:00

nit: includeServiceLangs

nit: includeServiceLangs
vng (Migrated from github.com) commented 2024-10-24 01:23:35 +00:00

void SetMapLangIndex(int8_t mapLangIndex);

void SetMapLangIndex(int8_t mapLangIndex);
vng (Migrated from github.com) commented 2024-10-24 01:19:31 +00:00

void SetMapLangIndex(int8_t mapLangIndex);

void SetMapLangIndex(int8_t mapLangIndex);
vng (Migrated from github.com) commented 2024-10-24 01:24:09 +00:00

SetMapLangIndexMessage(int8_t mapLangIndex)

SetMapLangIndexMessage(int8_t mapLangIndex)
vng (Migrated from github.com) commented 2024-10-24 01:24:36 +00:00

SetMapLangIndex(int8_t mapLangIndex)

SetMapLangIndex(int8_t mapLangIndex)
vng (Migrated from github.com) commented 2024-10-24 01:24:50 +00:00

void SetMapLangIndex(int8_t mapLangIndex);

void SetMapLangIndex(int8_t mapLangIndex);
This repo is archived. You cannot comment on pull requests.
No labels
Accessibility
Accessibility
Address
Address
Android
Android
Android Auto
Android Auto
Android Automotive (AAOS)
Android Automotive (AAOS)
API
API
AppGallery
AppGallery
AppStore
AppStore
Battery and Performance
Battery and Performance
Blocker
Blocker
Bookmarks and Tracks
Bookmarks and Tracks
Borders
Borders
Bug
Bug
Build
Build
CarPlay
CarPlay
Classificator
Classificator
Community
Community
Core
Core
CrashReports
CrashReports
Cycling
Cycling
Desktop
Desktop
DevEx
DevEx
DevOps
DevOps
dev_sandbox
dev_sandbox
Directions
Directions
Documentation
Documentation
Downloader
Downloader
Drape
Drape
Driving
Driving
Duplicate
Duplicate
Editor
Editor
Elevation
Elevation
Enhancement
Enhancement
Epic
Epic
External Map Datasets
External Map Datasets
F-Droid
F-Droid
Fonts
Fonts
Frequently User Reported
Frequently User Reported
Fund
Fund
Generator
Generator
Good first issue
Good first issue
Google Play
Google Play
GPS
GPS
GSoC
GSoC
iCloud
iCloud
Icons
Icons
iOS
iOS
Legal
Legal
Linux Desktop
Linux Desktop
Linux packaging
Linux packaging
Linux Phone
Linux Phone
Mac OS
Mac OS
Map Data
Map Data
Metro
Metro
Navigation
Navigation
Need Feedback
Need Feedback
Night Mode
Night Mode
NLnet 2024-06-281
NLnet 2024-06-281
No Feature Parity
No Feature Parity
Opening Hours
Opening Hours
Outdoors
Outdoors
POI Info
POI Info
Privacy
Privacy
Public Transport
Public Transport
Raw Idea
Raw Idea
Refactoring
Refactoring
Regional
Regional
Regression
Regression
Releases
Releases
RoboTest
RoboTest
Route Planning
Route Planning
Routing
Routing
Ruler
Ruler
Search
Search
Security
Security
Styles
Styles
Tests
Tests
Track Recording
Track Recording
Translations
Translations
TTS
TTS
UI
UI
UX
UX
Walk Navigation
Walk Navigation
Watches
Watches
Web
Web
Wikipedia
Wikipedia
Windows
Windows
Won't fix
Won't fix
World Map
World Map
No project
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: organicmaps/organicmaps-tmp#8237
No description provided.