Encoding of multilanguage file

Upload core product.
Post Reply
import
Posts: 169
Joined: Sun Jan 27, 2008 8:10 pm

Encoding of multilanguage file

Post by import »

What is the encoding of multilanguage file? I wanted to translate JFileUpload to Russian, but I failed :(

import
Posts: 169
Joined: Sun Jan 27, 2008 8:10 pm

Re: Encoding of multilanguage file

Post by import »

Translate i18n.properties in russian and then use native2ascii Java tool to convert your file with \u unicode chars. If you don't know how to then send your file to support(at)jfileupload(dot)com and they will run native2ascii for you.

vlad
Posts: 82
Joined: Sun Jan 04, 2009 6:38 pm

Re: Encoding of multilanguage file

Post by vlad »

I'm having trouble translating the interface to Russian.

I've converted the UTF-8 file to ASCII:

Code: Select all

taskoutput.usage=\u00d0\u0178\u00d0\u00b5\u00d1\u20ac\u00d0\u00b5\u00d1\u201a\u00d0\u00b0\u00d1\u2030\u00d0\u00b8\u00d1\u201a\u00d0\u00b5 \u00d1\u201e\u00d0\u00b0\u00d0\u00b9\u00d0\u00bb\u00d1\u2039 \u00d1\ufffd \u00d0\u00b2\u00d0\u00b0\u00d1\u02c6\u00d0\u00b5\u00d0\u00b3\u00d0\u00be \u00d0\u00ba\u00d0\u00be\u00d0\u00bc\u00d0\u00bf\u00d1\u0152\u00d1\u017d\u00d1\u201a\u00d0\u00b5\u00d1\u20ac\u00d0\u00b0
but I get:

Code: Select all

Перетащите файлы � вашего компьютера
Any other language seems to work fine. Please help.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Encoding of multilanguage file

Post by support »

Did you specify the encoding for incoming file on native2ascii.exe command line ?

vlad
Posts: 82
Joined: Sun Jan 04, 2009 6:38 pm

Re: Encoding of multilanguage file

Post by vlad »

Thanks for the tip, it worked. I had a UTF-8 encoded file, so the following command worked for me:

Code: Select all

native2ascii.exe -encoding UTF-8 inputfilename.txt outputfilename.txt
.. if anybody else has this problem.

vlad
Posts: 82
Joined: Sun Jan 04, 2009 6:38 pm

Re: Encoding of multilanguage file

Post by vlad »

If you use PHP dynamically generated language files, you could use the following function to convert from UTF-8 to Unicode code points on the fly, without using Java's utility:

Code: Select all

function utf8_to_unicode($str) {
	$unicode = array();
	$values = array();
	$lookingFor = 1;
	
	for ($i = 0; $i < strlen($str); $i++ ) {
		if ($str[$i] == " ") {
			$unicode[] = " ";
		} else {
			$thisValue = ord( $str[ $i ] );
			if ( $thisValue < ord('A') ) {
				// exclude 0-9
				if ($thisValue >= ord('0') && $thisValue <= ord('9')) {
					// number
					$unicode[] = chr($thisValue);
				}
				else {
					$unicode[] = '\\'.dechex($thisValue);
				}
			} else {
				if ($thisValue < 128){
					$unicode[] = $str[ $i ];
				} else {
					if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
					$values[] = $thisValue;
					if ( count( $values ) == $lookingFor ) {
						$number = ( $lookingFor == 3 ) ?
						( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
						( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
						$number = dechex($number);
						$unicode[] = (strlen($number)==3)?"\\u0".$number:"\\u".$number;
						$values = array();
						$lookingFor = 1;
					} // if
				} // if
			}
		}
	} // for
	return implode("", $unicode);
}
P.S. It seems to me that would have been more professional if the Java applet would have simply supported UTF-8 characters, than having to use this workaround.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Encoding of multilanguage file

Post by support »

Thanks for the tip.

Post Reply