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 » GetLanguageCode
GetLanguageCode [message #19685] Mon, 05 January 2009 17:34 Go to next message
White_Owl is currently offline  White_Owl
Messages: 27
Registered: January 2009
Location: New York
Promising Member
I have several localized texts in src.tpp and would like to load them in run-time according to the current user language.
The easiest way I can think of, is to do it with a code like this:
PromptOK(String("MyProject/src/About$") + GetLanguageCode(GetCurrentLanguage()));

And a function GetLanguageCode() is a slightly modified LNGasText():
String GetLanguageCode(int d)
{
	String result;
	int c = (d >> 15) & 31;
	if(c) {
		result.Cat(c + 'a' - 1);
		c = (d >> 10) & 31;
		if(c) {
			result.Cat(c + 'a' - 1);
			c = (d >> 5) & 31;
			if(c) {
				result.Cat('-');
				result.Cat(c + 'a' - 1);
				c = d & 31;
				if(c) result.Cat(c + 'a' - 1);
			}
		}
	}
	c = (d >> 20) & 255;
	return result;
}
The change is that it does not add charset name and returns lower-case language code, exactly as TPP editor set language codes for topics.

Am I inventing a wheel?
Re: GetLanguageCode [message #19686 is a reply to message #19685] Mon, 05 January 2009 19:59 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Maybe use this code:
String s = String("MyProject/src/"+Topic+"$") + String(ToLower(LNGAsText(GetCurrentLanguage()& 0xfffff)));


But I use extended form of help request
Vector<String> Topic = Split(topic, '#'); 
String s = String("MyProject/help/"+Topic[0]+"$") + String(ToLower(LNGAsText(GetCurrentLanguage()& 0xfffff)))+"#"+String(Topic[1]);


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: GetLanguageCode [message #19691 is a reply to message #19685] Mon, 05 January 2009 22:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
White_Owl wrote on Mon, 05 January 2009 11:34


The easiest way I can think of, is to do it with a code like this:
PromptOK(String("MyProject/src/About$") + GetLanguageCode(GetCurrentLanguage()));

}[/code]The change is that it does not add charset name and returns lower-case language code, exactly as TPP editor set language codes for topics.

Am I inventing a wheel?


You can use:

LNGAsTxt(SetLNGCharset(GetCurrentLanguage(), CHARSET_DEFAULT))

Mirek
Re: GetLanguageCode [message #19693 is a reply to message #19685] Mon, 05 January 2009 22:42 Go to previous messageGo to next message
White_Owl is currently offline  White_Owl
Messages: 27
Registered: January 2009
Location: New York
Promising Member
Well... After some tweaking I now load my QTF's like this:
Topic GetTopicLNG(const String &path) {
	return GetTopic(path + "$" + ToLower(LNGAsText(GetCurrentLanguage()).Left(5)));
}
....

PromptOK(GetTopicLNG("MyProject/src/About"));

May be some kind of language sensitive loading function should be in the default Topic library?
Re: GetLanguageCode [message #19698 is a reply to message #19693] Mon, 05 January 2009 23:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
White_Owl wrote on Mon, 05 January 2009 16:42

Well... After some tweaking I now load my QTF's like this:
Topic GetTopicLNG(const String &path) {
	return GetTopic(path + "$" + ToLower(LNGAsText(GetCurrentLanguage()).Left(5)));
}
....

PromptOK(GetTopicLNG("MyProject/src/About"));

May be some kind of language sensitive loading function should be in the default Topic library?


Sounds good Smile

Should there be used the trick to remove charset too?

Mirek
Re: GetLanguageCode [message #19707 is a reply to message #19698] Tue, 06 January 2009 15:54 Go to previous messageGo to next message
White_Owl is currently offline  White_Owl
Messages: 27
Registered: January 2009
Location: New York
Promising Member
luzr wrote on Mon, 05 January 2009 23:23

Should there be used the trick to remove charset too?
Yes. That is why I have .Left(5) from the result of LNGAsText().
Re: GetLanguageCode [message #19725 is a reply to message #19707] Wed, 07 January 2009 13:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
This would work, right?:

Topic GetTopicLNG(const String &path) {
	return GetTopic(path + "$" + ToLower(LNGAsTxt(SetLNGCharset(GetCurrentLanguage(), CHARSET_DEFAULT)));
}


Maybe we could add something like

int LNGNoCharset(int c)
{
    return SetLNGCharset(GetCurrentLanguage(), CHARSET_DEFAULT));
}


to avoid future confusion too Smile

Mirek
Re: GetLanguageCode [message #19727 is a reply to message #19725] Wed, 07 January 2009 16:50 Go to previous messageGo to next message
White_Owl is currently offline  White_Owl
Messages: 27
Registered: January 2009
Location: New York
Promising Member
luzr wrote on Wed, 07 January 2009 13:42

This would work, right?:
Looks like it. With some minor corrections of course Smile

Topic GetTopicLNG(const String &path) {
	return GetTopic(path + "$" + ToLower(LNGAsText(SetLNGCharset(GetCurrentLanguage(), CHARSET_DEFAULT))));
}


I am not sure about the second one though... May be with a longer name it would be more easy to use:
int GetCurrentLanguageIdWithDefaultCharset()
{
    return SetLNGCharset(GetCurrentLanguage(), CHARSET_DEFAULT));
}
But I do not actually see where this shortcut would be useful.
Re: GetLanguageCode [message #19743 is a reply to message #19727] Fri, 09 January 2009 08:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, now in Core.

Mirek
Previous Topic: how to add ISO10646 charset?
Next Topic: GetNativeLangName returns English for non-english languages
Goto Forum:
  


Current Time: Thu Mar 28 21:30:47 CET 2024

Total time taken to generate the page: 0.02004 seconds