ChoiceWithValueDisplay: Allow translation of the value

This commit is contained in:
Henrik Rydgard 2014-07-21 18:42:25 +02:00
parent 9d8d64b321
commit 4195da289c
3 changed files with 11 additions and 4 deletions

View File

@ -37,6 +37,9 @@ class I18NCategory {
public:
I18NCategory(const char *name) : name_(name) {}
const char *T(const char *key, const char *def = 0);
const char *T(const std::string &key) {
return T(key.c_str(), nullptr);
}
const std::map<std::string, std::string> &Missed() const {
return missedKeyLog_;

View File

@ -458,7 +458,10 @@ void ChoiceWithValueDisplay::Draw(UIContext &dc) {
dc.SetFontStyle(dc.theme->uiFont);
if (sValue_ != nullptr) {
valueText << *sValue_;
if (category_)
valueText << category_->T(*sValue_);
else
valueText << *sValue_;
} else if (iValue_ != nullptr) {
valueText << *iValue_;
}

View File

@ -271,16 +271,17 @@ private:
class ChoiceWithValueDisplay : public UI::Choice {
public:
ChoiceWithValueDisplay(int *value, const std::string &text, LayoutParams *layoutParams = 0)
: Choice(text, layoutParams), iValue_(value) { sValue_ = nullptr; }
: Choice(text, layoutParams), iValue_(value), category_(nullptr) { sValue_ = nullptr; }
ChoiceWithValueDisplay(std::string *value, const std::string &text, LayoutParams *layoutParams = 0)
: Choice(text, layoutParams), sValue_(value) { iValue_ = nullptr; }
ChoiceWithValueDisplay(std::string *value, const std::string &text, I18NCategory *category, LayoutParams *layoutParams = 0)
: Choice(text, layoutParams), sValue_(value), category_(category) { iValue_ = nullptr; }
void Draw(UIContext &dc);
private:
int *iValue_;
std::string *sValue_;
I18NCategory *category_;
};
} // namespace UI