Native UI and language support

7 posts / 0 new
Last post
Makis
Makis's picture
Offline
Mobile Conjurer
Joined: 1 Jun 2011
Posts:
Native UI and language support

Hello,

I was experimenting a bit with the examples, MAUI and NativeUI ones. I was trying to use labels with English, German, French and Greek language.

For the MAUI, after a tip from Sam, using the Notepad++ i figured out how to create labels correctly.

In case someone need it in the future, for supporting Greek German French for example, i created the .mof file using the BMFont Generator, including all the characters i need.

Then with Notepad++ you choose:
Plugins->Converter->Conversion panel.
In the ASCII box you type any special character you need like, ç, à, é, ö, click insert, make sure the encoding is "Encode in ANSI", copy text and paste it in the source code, where you type the label text.

Now the question is in the Native UI, with the same reasoning, do i need to load a particular font containing those special characters, from device?

If you type the text,in NativeUIDemo, in different language i get the UTF-8 error message. Like the one you get in MAUI if you don't follow the above procedure.

For example in the NativeUIDemo, lets say in the color list, i wanted to write words in different languages, like:

(In the place of Red, Green, Blue text etc )

Französisch
Française
Γαλλικά
and so on
(meaning French, in German, French and Greek language)

Does NativeUI support this? An example could be helpful.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Yeah, its a funny one because the native labels obviously do support multi-language settings. You certainly don't need to change the native font, but the MoSync methods for setting properties take a const char* which will still be single byte characters.  I don't know of a way to set the native code page or anything, so I'd expect the same restrictions, unless someone knows any better.?

Makis
Makis's picture
Offline
Mobile Conjurer
Joined: 1 Jun 2011
Posts:

The procedure with Notepad++ doesn't seem to work with Native UI. When i try it, emulator starts, application launch but then i get a black screen and returning to android menu. I tried it with every Native Demo and with 2.2, 2.3.3 android emulators.

So if we want multi-language support what will be another route to take, using the NativeUI? Do we have any example of multi language NativeUI application, in Mosync examples or GitHub i missed?

David Hoffmann
00091701's picture
Offline
Mobile Conjurer
Joined: 22 Oct 2011
Posts:

Hi is there any solution for this problem now?

For my NativeUI App I need german umlauts too.

Regards,
David

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

There are some people in MoSync looking at this problem for a long-term fix. I've had issues again with it recently (it was working, and then it stopped). I found out that my problem was caused by reading in the text from XML.

MoSync MTXml parser does support UTF-8. If you called the method 'feedProcess' instead of 'feed' it will convert UTF-8 characters into ANSI characters, using (I think) the 1252 codepage. It may even support UTF-16 now, with wide character support, but I've not tested it myself. with 'feedWide'.

This is the code from MTXml which does the conversion. You can use this to your strings into compatible ones with the right characters. This works for me in AMUI/MAUI and I'll try it later with NativeUI.

//processes UTF-8 of the data if the CONTEXT says the document uses that encoding.
//also processes standard entities if(ent).
//return <0 on error.
//if any data was successfully processed, return the length of it.
//remainsLen = 0;
//if any data remains, set remainsLen to the length of it and set sCurPtr to the start of it.
#endif
//for some functions, remaining data will mean error.
//remainsLen is partially used as "refLen" and "utf8Len" inside this function.

//todo, maybe: improve performance at the cost of code size
//by making this function a template on ent, sUtf8 and sWideBuf.
static int _proc(char* data, int* remainsLen, bool ent) {
	char* dst = data;
	wchar_t* wdst = sWideBuf;
	char* src = data;
	*remainsLen = 0;
	while(*src != 0 ) {
		int res = 0;
		if(ent && *src == '&') {	//reference
			src++;
			res = parseRef(src, remainsLen);
			if(res == PEC_INCOMPLETE) {
				sCurPtr = src - 1;
				break;
			} else if(res < 0 )
				return res;
			if(res > 0xFF && !sWideBuf) {
				res = sContext->unicodeCharacter(sContext, res);
				if(res == 0 )
					return PEC_OUTSIDE;
			}
		} else if(sUtf8) {	//normal character
			if(sWideBuf) {
				res = convertUtf8ToUnicode(src, remainsLen);
			} else {
				res = convertUtf8ToLatin1(src, remainsLen);
			}
			if(res == PEC_INCOMPLETE) {
				sCurPtr = src;
				break;
			} else if(res < 0 )
				return res;
		}
		if(res != 0 ) {
			if(sWideBuf) {
				*(wdst++) = (wchar_t)res;
			} else {
				*(dst++) = (char)res;
			}
			src += *remainsLen;
			*remainsLen = 0;
		} else {
			if(sWideBuf) {
				*(wdst++) = *(src++);
			} else {
				*(dst++) = *(src++);
			}
		}
	}
	if(sWideBuf) {
		*wdst = 0;
		return wdst - sWideBuf;
	} else {
		*dst = 0;
		return dst - data;
	}
}

//todo: optimize. maybe use mbtowc().
static int convertUtf8ToUnicode(const char* utf8, int* pnBytes) {
	char b = utf8[0];
	if(b & 0x80 ) {
		int nBytes = 0, unicode, i;
		do {
			nBytes++;
			b <<= 1;
		} while(b & 0x80);
		if(nBytes > 4) {
			//printf("CU8b: %i", nBytes);
			return PEC_INVALID;
		}
		unicode = (b >> nBytes) << ((nBytes-1) * 6);
		for(i=0; i<nBytes-1; i++) {
			if(utf8[i+1] == 0 ) {
				*pnBytes = i+1;
				return PEC_INCOMPLETE;
			}
			unicode |= (utf8[i+1] & 0x3F) << ((nBytes-2-i) * 6);
		}
		*pnBytes = nBytes;
		return unicode;
	} else {
		*pnBytes = 1;
		return b;
	}
}

static int convertUtf8ToLatin1(const char* utf8, int* pnBytes) {
	int unicode = convertUtf8ToUnicode(utf8, pnBytes);
	if(unicode > 0xFF) {
		//0xFEFF is ZERO WIDTH NO-BREAK SPACE, an encoding signature.
		if(unicode == 0xFEFF) {
			unicode = ' ';	//not a proper translation, but it shouldn't cause any problems.
		} else {
			//printf("CU8u: %i", unicode);
			unicode = sContext->unicodeCharacter(sContext, unicode);
			if(unicode == 0 )
				return PEC_OUTSIDE;
		}
	}
	return unicode;
}

 

 

David Hoffmann
00091701's picture
Offline
Mobile Conjurer
Joined: 22 Oct 2011
Posts:

It works with this workaround...

http://jira.mosync.com/browse/MOSYNC-1735

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

I'm pleased you've got a workaround, but its still not working for me. My text is in a UTF-8 XML document. It is being processed correctly, and everything tells me that the text readable, but it still crashes on character codes > 127.