Add a command-line option to show incomplete translations in the language list

This commit is contained in:
Celtic Minstrel 2018-05-19 15:55:50 -04:00
parent 5e28c13b87
commit fc74e782b7
5 changed files with 26 additions and 3 deletions

View file

@ -19,6 +19,7 @@
#include "lexical_cast.hpp"
#include "log.hpp" // for logger, set_strict_severity, etc
#include "serialization/string_utils.hpp" // for split
#include "utils/general.hpp" // for clamp
#include <boost/any.hpp> // for any
#include <boost/program_options/cmdline.hpp>
@ -146,6 +147,7 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
// Options are sorted alphabetically by --long-option.
po::options_description general_opts("General options");
general_opts.add_options()
("all-translations", "Show all translations, even incomplete ones.")
("bunzip2", po::value<std::string>(), "decompresses a file (<arg>.bz2) in bzip2 format and stores it without the .bz2 suffix. <arg>.bz2 will be removed.")
("bzip2", po::value<std::string>(), "compresses a file (<arg>) in bzip2 format, stores it as <arg>.bz2 and removes <arg>.")
("clock", "Adds the option to show a clock for testing the drawing timer.")
@ -193,6 +195,7 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
("script", po::value<std::string>(), "(experimental) file containing a lua script to control the client")
("server,s", po::value<std::string>()->implicit_value(std::string()), "connects to the host <arg> if specified or to the first host in your preferences.")
("strict-validation", "makes validation errors fatal")
("translations-over", po::value<unsigned int>(), "Specify the standard for determining whether a translation is complete.")
("unsafe-scripts", "makes the \'package\' package available to lua scripts, so that they can load arbitrary packages. Do not do this with untrusted scripts! This action gives lua the same permissions as the wesnoth executable.")
("userconfig-dir", po::value<std::string>(), "sets the path of the user config directory to $HOME/<arg> or My Documents\\My Games\\<arg> for Windows. You can specify also an absolute path outside the $HOME or My Documents\\My Games directory. Defaults to $HOME/.config/wesnoth on X11 and to the userdata-dir on other systems.")
("userconfig-path", "prints the path of the user config directory and exits.")
@ -481,6 +484,10 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
windowed = true;
if (vm.count("with-replay"))
with_replay = true;
if(vm.count("all-translations"))
translation_percent = 0;
else if(vm.count("translations-over"))
translation_percent = utils::clamp<unsigned int>(vm["translations-over"].as<unsigned int>(), 0, 100);
}
void commandline_options::parse_log_domains_(const std::string &domains_string, const int severity)

View file

@ -213,6 +213,8 @@ public:
bool windowed;
/// True if --with-replay was given on the command line. Shows replay of the loaded file.
bool with_replay;
/// Non-empty if --all-translations or --translations-over is given on the command line.
boost::optional<unsigned int> translation_percent;
private:
void parse_log_domains_(const std::string &domains_string, const int severity);
void parse_log_strictness (const std::string &severity);

View file

@ -262,6 +262,8 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
video().set_fullscreen(false);
if (cmdline_opts_.with_replay && load_data_)
load_data_->show_replay = true;
if(cmdline_opts_.translation_percent)
set_min_translation_percent(*cmdline_opts_.translation_percent);
std::cerr
<< "\nData directory: " << filesystem::sanitize_path(game_config::path)

View file

@ -46,7 +46,7 @@ namespace {
// This should be enabled for stable releases.
#ifdef ENABLE_TRANSLATION_COMPLETION_FILTERING
const int MIN_TRANSLATION_PERCENT = 80;
int min_translation_percent = 80;
#endif
}
@ -122,13 +122,23 @@ language_list get_languages()
// sort order.
std::sort(known_languages.begin(), known_languages.end());
#ifdef ENABLE_TRANSLATION_COMPLETION_FILTERING
if(min_translation_percent == 0) {
return known_languages;
}
language_list result;
std::copy_if(known_languages.begin(), known_languages.end(), std::back_inserter(result),
[](const language_def& lang) { return lang.percent >= MIN_TRANSLATION_PERCENT; });
[](const language_def& lang) { return lang.percent >= min_translation_percent; });
return result;
#endif
#else
return known_languages;
#endif
}
void set_min_translation_percent(int percent) {
min_translation_percent = percent;
}
static void wesnoth_setlocale(int category, const std::string& slocale,

View file

@ -100,3 +100,5 @@ void init_textdomains(const config& cfg);
bool init_strings(const config& cfg);
bool load_language_list();
void set_min_translation_percent(int percent);