Re: [Cppcms-users] forms - select_base::msg patch
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-07-19 08:34:06
|
>________________________________ > From: kpeo <sla...@ya...> >To: "cpp...@li..." <cpp...@li...> >Sent: Wednesday, July 18, 2012 1:59 PM >Subject: [Cppcms-users] forms - select_base::msg patch > >Hello all! > >Sometimes we need to return a message, attached to selectable widget. >For example, we have a content structure and form inside it with selectable widget, that has a displayed text (message) for every options. >As i understand, original API can't return a message - just id (int or string). The problem with message that it is locale dependent. That is why you can specify some general id you know is constant and unique. So getting the message is problematic and in fact your implementation contains an error. As for example if you want to call return elements_[i].tr_option; you need to convert it according to locale (otherwise it by default is converted according to global locale) > Shure, we can use id = message, but what if message > is not unique or we need less alphabets for option's > storing? We also may want to display this option as > message in content structure and store this option as id. > Well, we can use own component (map or kind of enum) to > store id-to-text mapping, but we already have one in original library. > > So, i decide to write this little patch for src/form.cpp and cppcms/form.h. > Shure, you can use it freely at your own risk, as me ;) And i'll be glad to see any criticism about it. > > Suggest, may be after reviewing by maintainers and if this patch looks > useful - it will be included in new revisions o f framework. > If you want to get message according to id you need to pass a locale parameter and even localization domain to convert it. std::string msg(std::locale const &l) std::string msg(std::locale const &l,std::string const &domain) But I think it is bad idea in general... So it would probably be better to return the booster::locale::message or std::string like bool selected_message_is_localized(); booster::locale::message selected_localized_message(); std::string selected_message(); bool message_is_localized(int num); booster::locale::message localized_message(int num); std::string message(int num); bool message_is_localized(std::string const &id); booster::locale::message localized_message(std::string const &id); std::string message(std::string const &id); And each one of the (selected_)?(localized_)?_message() would throw an error if the type is not correct >Regards, >kpeo >------------------------------------------------------------------------------ >Live Security Virtual Conference >Exclusive live event will cover all the ways today's security and >threat landscape has changed and how IT managers can respond. Discussions >will include endpoint security, mobile security and the latest in malware >threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |