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 |
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
|
|
|
Goto Forum:
Current Time: Sat May 11 14:49:45 CEST 2024
Total time taken to generate the page: 0.02336 seconds
|