Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan for languages #40056

Merged
merged 6 commits into from
May 3, 2020
Merged

Scan for languages #40056

merged 6 commits into from
May 3, 2020

Conversation

akirashirosawa
Copy link
Contributor

@akirashirosawa akirashirosawa commented May 1, 2020

Summary

SUMMARY: None

Purpose of change

I have to constantly switch languages for testing, and it’s very annoying to scroll through them all. I thought it would be nice if displayed only languages ​​for which there is a translation. Then I found this in the code: TODO: scan for languages like we do for tilesets. So, let's do it!

Describe the solution

Scan for languages like we do for tilesets. Added lang info to the PATH_INFO added actual_lang_options near lang_options. Completely replace lang_options by actual_lang_options. Added probably forgotten brake in for cycle.

Describe alternatives you've considered

Reuse lang info, that I added to PATH_INFO on the translations.cpp:

// Step 2. Bind to gettext domain.
    std::string locale_dir;
#if defined(__ANDROID__)
    // HACK: Since we're using libintl-lite instead of libintl on Android, we hack the locale_dir to point directly to the .mo file.
    // This is because of our hacky libintl-lite bindtextdomain() implementation.
    auto env = getenv( "LANGUAGE" );
    locale_dir = std::string( PATH_INFO::base_path() + "lang/mo/" + ( env ? env : "none" ) +
                              "/LC_MESSAGES/cataclysm-dda.mo" );
#elif (defined(__linux__) || (defined(MACOSX) && !defined(TILES)))
    if( !PATH_INFO::base_path().empty() ) {
        locale_dir = PATH_INFO::base_path() + "share/locale";
    } else {
        locale_dir = "lang/mo";
    }
#else
    locale_dir = "lang/mo";
#endif

But, there are some scary __ANDROID__ HACKs and some strange defined(__linux__) || (defined(MACOSX) && !defined(TILES)) instead of #if defined(DATA_DIR_PREFIX) that in path_info.cpp.

Testing

Language option displays only available languages (for which there is a translation in .mo files).

Additional context

I am using lambda expressions in C++ for the first time, it would be nice if more experienced contributor checked the code.

src/options.h Outdated Show resolved Hide resolved
src/options.cpp Outdated Show resolved Hide resolved
src/options.cpp Outdated Show resolved Hide resolved
src/options.h Outdated Show resolved Hide resolved
src/options.cpp Outdated Show resolved Hide resolved
src/options.cpp Outdated Show resolved Hide resolved
akirashirosawa and others added 2 commits May 2, 2020 00:30
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Translation I18n labels May 3, 2020
@ZhilkinSerg ZhilkinSerg merged commit ae30117 into CleverRaven:master May 3, 2020
@akirashirosawa akirashirosawa deleted the scan-for-languages branch May 4, 2020 08:29
@RedShakespeare
Copy link
Contributor

Cannot work well with Android OS...Hope for some fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Translation I18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants