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 » Community » Newbie corner » Translations in header file
Translations in header file [message #46453] Thu, 12 May 2016 10:30 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
I am "internationalizating" my application and found a problem

I have this .h file containing an enum class and a static array:

enum class Reason_idx : int {
	PRICE = 0,
	DELIVERY = 1,
	COMPLIANCE = 2,
	CERTIFICATES = 3,
	NumReason = 4
};
static const char* const REASON[] = {
	t_("Price"),
	t_("Delivery"),
	t_("Technical compliance"),
	t_("Certificates")
};


Whenever I need them (e.g. to fill in a droplist) I use something like that:

for (int i = 0; i < (int)Reason_idx::NumReason; i++)
	OpReason.Add(Reason[i]);


I put those in a header file because they are related to a database (they are the possible values of a table) and so I use the same file across a number of applications that connect to that database. The problem is that those string are never translated. Other parts of the applications (labels, messages) are properly translated. Those strings have a translation in the .t file of the application.
Someone has hints?
Regards,
Gio
Re: Translations in header file [message #46460 is a reply to message #46453] Thu, 12 May 2016 19:20 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Since your translation should be done in runtime, you can do it this way:

static const char* const Reason[] = {
	"Price",
	"Delivery",
	"Technical compliance",
	"Certificates"
};

[...]

for (int i = 0; i < __countof(Reason); i++)
	OpReason.Add(t_(Reason[i]));

[Updated on: Thu, 12 May 2016 20:30]

Report message to a moderator

Re: Translations in header file [message #46467 is a reply to message #46460] Fri, 13 May 2016 09:28 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Thanks, it worked like a charm... by the way, I thought that syntax ( t_(Reason[i]) ) was illegal.

[Updated on: Fri, 13 May 2016 09:29]

Report message to a moderator

Re: Translations in header file [message #46470 is a reply to message #46467] Fri, 13 May 2016 19:21 Go to previous message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Giorgio wrote on Fri, 13 May 2016 09:28
I thought that syntax ( t_(Reason[i]) ) was illegal.


It is fine as long as t_ argument is constant literal - in your code it is.
Previous Topic: What is SegtorMap?
Next Topic: Problems with AddPick operator| in Vector
Goto Forum:
  


Current Time: Thu Mar 28 16:45:48 CET 2024

Total time taken to generate the page: 0.01375 seconds