Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Helper for internazionalize arrays of literals
Helper for internazionalize arrays of literals [message #24302] Sat, 09 January 2010 14:59 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Starting to internationalize an app, I faced to this problem :
char *myTable =
{
    "ONE",
    "TWO",
    "THREE"
};

which can't be internationalized by aid of 't_' macro. It can be done with 'tt_' macro, but it need patched code to retrieve the internationalized string with GetLngString macro.
So I've thought about a better way, and coded this :
class StringTable : public Vector<String>
{
	public:
		StringTable &operator,(const char *s) { Add(s); return *this; }
		const char *operator[](int i) { ASSERT(i < GetCount()); return ~At(i); }
};

#define STRINGTABLE(s) StringTable s; INITBLOCK { s,
#define ENDTABLE ; }


This allows to define a character table like that :

STRINGTABLE(myTable)
    t_("One"),
    t_("Two"),
    t_("Three")
ENDTABLE;


Access is as before with myTable[], so no need to code changes; as a small benefit, the string translation is done at load time just once, and not every time the string is needed.
What do you think about ? Do you know a better way to achieve the same purpose ?

Ciao

Max

[Updated on: Sat, 09 January 2010 15:45]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: GCC compilation options
Next Topic: Template class factory
Goto Forum:
  


Current Time: Sun Apr 28 00:42:17 CEST 2024

Total time taken to generate the page: 0.02442 seconds