I just pushed another update, where I write the total only once as suggested by 
Kaputtnik. I still need to clean up the Python script incl. the regex.

Diff comments:

> 
> === modified file 'src/ui_fsmenu/options.cc'
> --- src/ui_fsmenu/options.cc  2017-09-11 16:59:41 +0000
> +++ src/ui_fsmenu/options.cc  2017-10-14 16:12:18 +0000
> @@ -432,7 +421,7 @@
>       language_dropdown_.add(_("Try system language"), "", nullptr, 
> current_locale == "");
>       language_dropdown_.add("English", "en", nullptr, current_locale == 
> "en");
>  
> -     // Add translation directories to the list
> +     // Add translation directories to the list. We use a vector so we can 
> call std::sort on it.

The key to sort for is coming off Transifex, and I don't trust it not to 
produce hash collisions, ever. For example, Japanese is "Nihongo" to make sure 
that it will be sorted under n. If we went with the locale code "ja", we would 
end up under j, which is awkward for Japanese speakers. I have added another 
comment.

>       std::vector<LanguageEntry> entries;
>       std::string selected_locale;
>  
> @@ -484,6 +475,67 @@
>       }
>  }
>  
> +/**
> + * Updates the language statistics message according to the currently 
> selected locale.
> + * @param include_system_lang We only want to include the system lang if it 
> matches the Widelands
> + * locale.
> + */
> +void FullscreenMenuOptions::update_language_stats(bool include_system_lang) {
> +     int percent = 100;
> +     std::string message = "";
> +     if (language_dropdown_.has_selection()) {
> +             std::string locale = language_dropdown_.get_selected();
> +             // Empty locale means try system locale
> +             if (locale.empty() && include_system_lang) {
> +                     std::vector<std::string> parts;
> +                     boost::split(parts, i18n::get_locale(), 
> boost::is_any_of("."));
> +                     if (language_entries_.count(parts[0]) == 1) {
> +                             locale = parts[0];
> +                     } else {
> +                             boost::split(parts, parts[0], 
> boost::is_any_of("@"));
> +                             if (language_entries_.count(parts[0]) == 1) {
> +                                     locale = parts[0];
> +                             } else {
> +                                     boost::split(parts, parts[0], 
> boost::is_any_of("_"));
> +                                     if (language_entries_.count(parts[0]) 
> == 1) {
> +                                             locale = parts[0];
> +                                     }
> +                             }
> +                     }
> +             }
> +
> +             // If we have the locale, grab the stats and set the message
> +             if (language_entries_.count(locale) == 1) {
> +                     try {
> +                             const LanguageEntry& entry = 
> language_entries_[locale];
> +                             Profile prof("i18n/translation_stats.conf");
> +                             Section& s = prof.get_safe_section(locale);
> +                             percent = floor(100.f * s.get_int("translated") 
> / s.get_int("total"));
> +                             if (percent == 100) {
> +                                     message = (boost::format(_("The 
> translation into %s is complete.")) %
> +                                                               
> entry.descname)
> +                                                                      .str();
> +                             } else {
> +                                     message = (boost::format(_("The 
> translation into %s is %d%% complete.")) %
> +                                                               
> entry.descname % percent)
> +                                                                      .str();
> +                             }
> +                     } catch (...) {
> +                     }
> +             }
> +     }
> +
> +     // We will want some help with incomplete translations
> +     if (percent <= 90) {

OK, done.

> +             message = message + " " +
> +                       (boost::format(_("If you wish to help us translate, 
> please visit %s")) %
> +                        "<font 
> underline=1>widelands.org/wiki/TranslatingWidelands</font>")
> +                          .str();
> +     }
> +     // Make font a bit smaller so the link will fit at 800x600 resolution.
> +     translation_info_.set_text(as_uifont(message, 12));
> +}
> +
>  void FullscreenMenuOptions::clicked_apply() {
>       
> end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kApplyOptions);
>  }


-- 
https://code.launchpad.net/~widelands-dev/widelands/translation_stats/+merge/332029
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/translation_stats.

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to