From 8ea3c4d54429976e9001b8cc4868b721e6747e3c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 17 Mar 2018 22:46:41 +0000 Subject: simplewallet: new --use-english-language-names flag On some Windows systems, displaying language names in their own languages freezes the display. --- src/mnemonics/chinese_simplified.h | 2 +- src/mnemonics/dutch.h | 2 +- src/mnemonics/electrum-words.cpp | 34 ++++++++++++++++++++++++++-------- src/mnemonics/electrum-words.h | 10 +++++++++- src/mnemonics/english.h | 2 +- src/mnemonics/english_old.h | 2 +- src/mnemonics/esperanto.h | 2 +- src/mnemonics/french.h | 2 +- src/mnemonics/german.h | 2 +- src/mnemonics/italian.h | 2 +- src/mnemonics/japanese.h | 2 +- src/mnemonics/language_base.h | 14 ++++++++++++-- src/mnemonics/lojban.h | 2 +- src/mnemonics/portuguese.h | 2 +- src/mnemonics/russian.h | 2 +- src/mnemonics/spanish.h | 2 +- src/simplewallet/simplewallet.cpp | 11 +++++++++-- src/simplewallet/simplewallet.h | 1 + 18 files changed, 70 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/mnemonics/chinese_simplified.h b/src/mnemonics/chinese_simplified.h index dd5548ba2..1ae8c89d6 100644 --- a/src/mnemonics/chinese_simplified.h +++ b/src/mnemonics/chinese_simplified.h @@ -72,7 +72,7 @@ namespace Language class Chinese_Simplified: public Base { public: - Chinese_Simplified(): Base("简体中文 (中国)", std::vector({ + Chinese_Simplified(): Base("简体中文 (中国)", "Chinese (simplified)", std::vector({ "的", "一", "是", diff --git a/src/mnemonics/dutch.h b/src/mnemonics/dutch.h index 43185cd1d..c9806f450 100644 --- a/src/mnemonics/dutch.h +++ b/src/mnemonics/dutch.h @@ -49,7 +49,7 @@ namespace Language class Dutch: public Base { public: - Dutch(): Base("Nederlands", std::vector({ + Dutch(): Base("Nederlands", "Dutch", std::vector({ "aalglad", "aalscholver", "aambeeld", diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp index f1fef2426..6a2a3e0c4 100644 --- a/src/mnemonics/electrum-words.cpp +++ b/src/mnemonics/electrum-words.cpp @@ -445,13 +445,9 @@ namespace crypto return bytes_to_words(src.data, sizeof(src), words, language_name); } - /*! - * \brief Gets a list of seed languages that are supported. - * \param languages The vector is set to the list of languages. - */ - void get_language_list(std::vector &languages) + std::vector get_language_list() { - std::vector language_instances({ + static const std::vector language_instances({ Language::Singleton::instance(), Language::Singleton::instance(), Language::Singleton::instance(), @@ -465,10 +461,20 @@ namespace crypto Language::Singleton::instance(), Language::Singleton::instance() }); - for (std::vector::iterator it = language_instances.begin(); + return language_instances; + } + + /*! + * \brief Gets a list of seed languages that are supported. + * \param languages The vector is set to the list of languages. + */ + void get_language_list(std::vector &languages, bool english) + { + const std::vector language_instances = get_language_list(); + for (std::vector::const_iterator it = language_instances.begin(); it != language_instances.end(); it++) { - languages.push_back((*it)->get_language_name()); + languages.push_back(english ? (*it)->get_english_language_name() : (*it)->get_language_name()); } } @@ -485,6 +491,18 @@ namespace crypto return word_list.size() != (seed_length + 1); } + std::string get_english_name_for(const std::string &name) + { + const std::vector language_instances = get_language_list(); + for (std::vector::const_iterator it = language_instances.begin(); + it != language_instances.end(); it++) + { + if ((*it)->get_language_name() == name) + return (*it)->get_english_language_name(); + } + return ""; + } + } } diff --git a/src/mnemonics/electrum-words.h b/src/mnemonics/electrum-words.h index 48ee378c0..856edb92a 100644 --- a/src/mnemonics/electrum-words.h +++ b/src/mnemonics/electrum-words.h @@ -106,8 +106,9 @@ namespace crypto /*! * \brief Gets a list of seed languages that are supported. * \param languages A vector is set to the list of languages. + * \param english whether to get the names in English or the language language */ - void get_language_list(std::vector &languages); + void get_language_list(std::vector &languages, bool english = false); /*! * \brief Tells if the seed passed is an old style seed or not. @@ -115,6 +116,13 @@ namespace crypto * \return true if the seed passed is a old style seed false if not. */ bool get_is_old_style_seed(std::string seed); + + /*! + * \brief Returns the name of a language in English + * \param name the name of the language in its own language + * \return the name of the language in English + */ + std::string get_english_name_for(const std::string &name); } } diff --git a/src/mnemonics/english.h b/src/mnemonics/english.h index d4a89ebbc..ee087674d 100644 --- a/src/mnemonics/english.h +++ b/src/mnemonics/english.h @@ -49,7 +49,7 @@ namespace Language class English: public Base { public: - English(): Base("English", std::vector({ + English(): Base("English", "English", std::vector({ "abbey", "abducts", "ability", diff --git a/src/mnemonics/english_old.h b/src/mnemonics/english_old.h index 8866c8d71..b31491646 100644 --- a/src/mnemonics/english_old.h +++ b/src/mnemonics/english_old.h @@ -51,7 +51,7 @@ namespace Language class EnglishOld: public Base { public: - EnglishOld(): Base("EnglishOld", std::vector({ + EnglishOld(): Base("EnglishOld", "English (old)", std::vector({ "like", "just", "love", diff --git a/src/mnemonics/esperanto.h b/src/mnemonics/esperanto.h index 21ee4c9f1..cb377a58e 100644 --- a/src/mnemonics/esperanto.h +++ b/src/mnemonics/esperanto.h @@ -58,7 +58,7 @@ namespace Language class Esperanto: public Base { public: - Esperanto(): Base("Esperanto", std::vector({ + Esperanto(): Base("Esperanto", "Esperanto", std::vector({ "abako", "abdiki", "abelo", diff --git a/src/mnemonics/french.h b/src/mnemonics/french.h index a472263b3..7eaf45650 100644 --- a/src/mnemonics/french.h +++ b/src/mnemonics/french.h @@ -49,7 +49,7 @@ namespace Language class French: public Base { public: - French(): Base("Français", std::vector({ + French(): Base("Français", "French", std::vector({ "abandon", "abattre", "aboi", diff --git a/src/mnemonics/german.h b/src/mnemonics/german.h index 01c483664..8eff43523 100644 --- a/src/mnemonics/german.h +++ b/src/mnemonics/german.h @@ -51,7 +51,7 @@ namespace Language class German: public Base { public: - German(): Base("Deutsch", std::vector({ + German(): Base("Deutsch", "German", std::vector({ "Abakus", "Abart", "abbilden", diff --git a/src/mnemonics/italian.h b/src/mnemonics/italian.h index f9536e2dd..d5ecb74f4 100644 --- a/src/mnemonics/italian.h +++ b/src/mnemonics/italian.h @@ -51,7 +51,7 @@ namespace Language class Italian: public Base { public: - Italian(): Base("Italiano", std::vector({ + Italian(): Base("Italiano", "Italian", std::vector({ "abbinare", "abbonato", "abisso", diff --git a/src/mnemonics/japanese.h b/src/mnemonics/japanese.h index 5b5884c3b..f3b3e4924 100644 --- a/src/mnemonics/japanese.h +++ b/src/mnemonics/japanese.h @@ -71,7 +71,7 @@ namespace Language class Japanese: public Base { public: - Japanese(): Base("日本語", std::vector({ + Japanese(): Base("日本語", "Japanese", std::vector({ "あいこくしん", "あいさつ", "あいだ", diff --git a/src/mnemonics/language_base.h b/src/mnemonics/language_base.h index 2124b8ea4..2b0c37c6b 100644 --- a/src/mnemonics/language_base.h +++ b/src/mnemonics/language_base.h @@ -82,6 +82,7 @@ namespace Language std::unordered_map word_map; /*!< hash table to find word's index */ std::unordered_map trimmed_word_map; /*!< hash table to find word's trimmed index */ std::string language_name; /*!< Name of language */ + std::string english_language_name; /*!< Name of language */ uint32_t unique_prefix_length; /*!< Number of unique starting characters to trim the wordlist to when matching */ /*! * \brief Populates the word maps after the list is ready. @@ -122,10 +123,11 @@ namespace Language } } public: - Base(const char *language_name, const std::vector &words, uint32_t prefix_length): + Base(const char *language_name, const char *english_language_name, const std::vector &words, uint32_t prefix_length): word_list(words), unique_prefix_length(prefix_length), - language_name(language_name) + language_name(language_name), + english_language_name(english_language_name) { } virtual ~Base() @@ -163,6 +165,14 @@ namespace Language { return language_name; } + /*! + * \brief Returns the name of the language in English. + * \return Name of the language. + */ + const std::string &get_english_language_name() const + { + return english_language_name; + } /*! * \brief Returns the number of unique starting characters to be used for matching. * \return Number of unique starting characters. diff --git a/src/mnemonics/lojban.h b/src/mnemonics/lojban.h index 723f1eac0..412531a23 100644 --- a/src/mnemonics/lojban.h +++ b/src/mnemonics/lojban.h @@ -56,7 +56,7 @@ namespace Language class Lojban: public Base { public: - Lojban(): Base("Lojban", std::vector({ + Lojban(): Base("Lojban", "Lojban", std::vector({ "backi", "bacru", "badna", diff --git a/src/mnemonics/portuguese.h b/src/mnemonics/portuguese.h index f68716962..0195389ce 100644 --- a/src/mnemonics/portuguese.h +++ b/src/mnemonics/portuguese.h @@ -72,7 +72,7 @@ namespace Language class Portuguese: public Base { public: - Portuguese(): Base("Português", std::vector({ + Portuguese(): Base("Português", "Portuguese", std::vector({ "abaular", "abdominal", "abeto", diff --git a/src/mnemonics/russian.h b/src/mnemonics/russian.h index 749191c9b..d5dd556ef 100644 --- a/src/mnemonics/russian.h +++ b/src/mnemonics/russian.h @@ -51,7 +51,7 @@ namespace Language class Russian: public Base { public: - Russian(): Base("русский язык", std::vector({ + Russian(): Base("русский язык", "Russian", std::vector({ "абажур", "абзац", "абонент", diff --git a/src/mnemonics/spanish.h b/src/mnemonics/spanish.h index 0c581128e..51f38fede 100644 --- a/src/mnemonics/spanish.h +++ b/src/mnemonics/spanish.h @@ -72,7 +72,7 @@ namespace Language class Spanish: public Base { public: - Spanish(): Base("Español", std::vector({ + Spanish(): Base("Español", "Spanish", std::vector({ "ábaco", "abdomen", "abeja", diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 54132d9ca..24397c65c 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -135,6 +135,7 @@ namespace const command_line::arg_descriptor arg_do_not_relay = {"do-not-relay", sw::tr("The newly created transaction will not be relayed to the monero network"), false}; const command_line::arg_descriptor arg_create_address_file = {"create-address-file", sw::tr("Create an address file for new wallets"), false}; const command_line::arg_descriptor arg_subaddress_lookahead = {"subaddress-lookahead", tools::wallet2::tr("Set subaddress lookahead sizes to :"), ""}; + const command_line::arg_descriptor arg_use_english_language_names = {"use-english-language-names", sw::tr("Display English language names"), false}; const command_line::arg_descriptor< std::vector > arg_command = {"command", ""}; @@ -2321,7 +2322,10 @@ bool simple_wallet::set_variable(const std::vector &args) { if (args.empty()) { - success_msg_writer() << "seed = " << m_wallet->get_seed_language(); + std::string seed_language = m_wallet->get_seed_language(); + if (m_use_english_language_names) + seed_language = crypto::ElectrumWords::get_english_name_for(seed_language); + success_msg_writer() << "seed = " << seed_language; success_msg_writer() << "always-confirm-transfers = " << m_wallet->always_confirm_transfers(); success_msg_writer() << "print-ring-members = " << m_wallet->print_ring_members(); success_msg_writer() << "store-tx-info = " << m_wallet->store_tx_info(); @@ -3108,6 +3112,7 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_ m_restore_height = command_line::get_arg(vm, arg_restore_height); m_do_not_relay = command_line::get_arg(vm, arg_do_not_relay); m_subaddress_lookahead = command_line::get_arg(vm, arg_subaddress_lookahead); + m_use_english_language_names = command_line::get_arg(vm, arg_use_english_language_names); m_restoring = !m_generate_from_view_key.empty() || !m_generate_from_spend_key.empty() || !m_generate_from_keys.empty() || @@ -3154,8 +3159,9 @@ std::string simple_wallet::get_mnemonic_language() std::vector language_list; std::string language_choice; int language_number = -1; - crypto::ElectrumWords::get_language_list(language_list); + crypto::ElectrumWords::get_language_list(language_list, m_use_english_language_names); std::cout << tr("List of available languages for your wallet's seed:") << std::endl; + std::cout << tr("If your display freezes, exit blind with ^C, then run again with --use-english-language-names") << std::endl; int ii; std::vector::iterator it; for (it = language_list.begin(), ii = 0; it != language_list.end(); it++, ii++) @@ -7422,6 +7428,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_do_not_relay); command_line::add_arg(desc_params, arg_create_address_file); command_line::add_arg(desc_params, arg_subaddress_lookahead); + command_line::add_arg(desc_params, arg_use_english_language_names); po::positional_options_description positional_options; positional_options.add(arg_command.name, -1); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index b2630c75e..d0d996aba 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -334,6 +334,7 @@ namespace cryptonote bool m_restoring; // are we restoring, by whatever method? uint64_t m_restore_height; // optional bool m_do_not_relay; + bool m_use_english_language_names; epee::console_handlers_binder m_cmd_binder; -- cgit v1.2.3