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 » U++ Library support » U++ Libraries and TheIDE: i18n, Unicode and Internationalization » Translation in static members
Translation in static members [message #31111] Sat, 05 February 2011 14:58 Go to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

Is it possible to translate test in static member of a class?

Consider this simplified code:
#include <Core/Core.h>
using namespace Upp;

#define TFILE <test/test.t>
#include <Core/t.h>

struct test{
	static const char* str;
	const char* str2;
	test():str(t_("translation")){};
};
const char* test::str=t_("translation");

CONSOLE_APP_MAIN{
	SetLanguage(GetSystemLNG());
	test t;
	DUMP(t.str); // doesn't translate
	DUMP(t.str2); // works fine
	DUMP(t_("translation")); // works fine
}


I believe the problem is that the static member is initialized earlier than the translations. Is there some reasonable workaround? Or is the only solution to make the member non-static?

Thanks,
Honza
Re: Translation in static members [message #31112 is a reply to message #31111] Sat, 05 February 2011 18:29 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

I'll answer myself Smile

The simplest and probably correct solution is to use t_GetLngString() whenever using the static member, instead when initializing it:
#include <Core/Core.h>
using namespace Upp;

#define TFILE <test/test.t>
#include <Core/t.h>

//simple shorthand, to keep code nice looking
#define _t(X) t_GetLngString(X)

struct test{
	static const char* str;
};
const char* test::str=tt_("translation");

CONSOLE_APP_MAIN{
	SetLanguage(GetSystemLNG());
	test t;
	DUMP(_t(t.str)); //<- added _t() to translate the string at runtime
}

The _t macro is quite handy thing. It would actually work with t_ as well, but that confuses theide when syncing the translations. Maybe there could be some shorthand for t_GetLngString added in the U++, what do you think?

Honza
Re: Translation in static members [message #31113 is a reply to message #31112] Sat, 05 February 2011 18:38 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

dolik.rce wrote on Sat, 05 February 2011 19:29

I'll answer myself Smile

The simplest and probably correct solution is to use t_GetLngString() whenever using the static member, instead when initializing it:
#include <Core/Core.h>
using namespace Upp;

#define TFILE <test/test.t>
#include <Core/t.h>

//simple shorthand, to keep code nice looking
#define _t(X) t_GetLngString(X)

struct test{
	static const char* str;
};
const char* test::str=tt_("translation");

CONSOLE_APP_MAIN{
	SetLanguage(GetSystemLNG());
	test t;
	DUMP(_t(t.str)); //<- added _t() to translate the string at runtime
}

The _t macro is quite handy thing. It would actually work with t_ as well, but that confuses theide when syncing the translations. Maybe there could be some shorthand for t_GetLngString added in the U++, what do you think?

Honza


This is very simple:

if you have static property than you can address only: ClassName::StaticPropertyName or from method of class by simple StaticPropertyName.

Hope if this help you!
Re: Translation in static members [message #31278 is a reply to message #31112] Fri, 18 February 2011 12:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
dolik.rce wrote on Sat, 05 February 2011 12:29

I'll answer myself Smile

The simplest and probably correct solution is to use t_GetLngString() whenever using the static member, instead when initializing it:
#include <Core/Core.h>
using namespace Upp;

#define TFILE <test/test.t>
#include <Core/t.h>

//simple shorthand, to keep code nice looking
#define _t(X) t_GetLngString(X)

struct test{
	static const char* str;
};
const char* test::str=tt_("translation");

CONSOLE_APP_MAIN{
	SetLanguage(GetSystemLNG());
	test t;
	DUMP(_t(t.str)); //<- added _t() to translate the string at runtime
}

The _t macro is quite handy thing. It would actually work with t_ as well, but that confuses theide when syncing the translations. Maybe there could be some shorthand for t_GetLngString added in the U++, what do you think?

Honza


I guess calling t_GetLngString or GetLngString here is not a big problem, as IME static texts are not that frequent.

However, if we decided on shortcat synonyme, it would be better done as inline function - no need to use macro here Wink

Mirek

[Updated on: Fri, 18 February 2011 12:38]

Report message to a moderator

Re: Translation in static members [message #31285 is a reply to message #31278] Fri, 18 February 2011 16:08 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

Whatever, in this case there is no difference between inline function and macro Smile

I don't even require it in upp, I can write shortcut into my project. As you say, it is not very common case. I just wanted to note that such shortcut might be handy and to note the problem and solution here in case someone else ever runs into this situation in the future.

Honza
Previous Topic: What you didn't know about theide..
Next Topic: There are too short lines after synchronization. t files.
Goto Forum:
  


Current Time: Wed Nov 20 08:27:02 CET 2019

Total time taken to generate the page: 0.02043 seconds