Japanese characters in alert

D

Daniel

I`m trying to show japanese characters in an alert, like;

alert('実装されていませ');

This doesn't work as shown in this post:
http://groups.google.com/groups?hl=...07%24Xl.400929%40twister.rdc-kc.rr.com&rnum=2

This post implyes that it's possible to use the \uXXXX notation
instead. But is this notation using the same codes? Can I transform
this
alert('実装されていませ');

into this?
alert('\u23455\u35013\u12373\u12428\u12390\u12356\u12414\u12379');

It doesn't seem to work. Does anyone have an idea?
 
G

Grant Wagner

Daniel said:
I`m trying to show japanese characters in an alert, like;

alert('実装されていませ');

This doesn't work as shown in this post:
http://groups.google.com/groups?hl=...07%24Xl.400929%40twister.rdc-kc.rr.com&rnum=2
This post implyes that it's possible to use the \uXXXX notation
instead. But is this notation using the same codes? Can I transform
this
alert('実装されていませ');

into this?
alert('\u23455\u35013\u12373\u12428\u12390\u12356\u12414\u12379');

It doesn't seem to work. Does anyone have an idea?

<script type="text/javascript">
var s = '実装されていませ';
// s = 'ABC';
s = s.replace(
/&#(\d+);/g,
function($1, $2) {
return String.fromCharCode($2);
}
);

alert(s);
</script>

You want to turn the string of character entities into a string of actual characters based on those character entity values, which is what the code above does. It generates the string as requested (which can be confirmed by uncommenting the second assignment to
-s-), but I don't know if it actually works or not, I don't have Japanese language support installed.
 
N

nutso fasst

VK said:
You have to use hex values, not decimal ones:
\uFFFF

That only seems to work for 8-bit characters. It seems that 16-bit
characters require String.fromCharCode(). For example, excepting the fact
that antediluvian MSIE doesn't support all the Unicode characters (Moz FF
does), this works:

alert(String.fromCharCode(8220)+'For having lived long, I have experienced
many instances\n'
+'of being obliged, by better information or fuller consideration,\n'
+'to change opinions, even on important subjects, which\n'
+'I once thought right but found to be
otherwise.'+String.fromCharCode(8221)+'\n'
+String.fromCharCode(8195)+String.fromCharCode(8195)+' '
+String.fromCharCode(8212)+' Benjamin Franklin,
1706'+String.fromCharCode(8211)+'1790');

This doesn't:

alert('\u8220For having lived long, I have experienced many instances\n'
+'of being obliged, by better information or fuller consideration,\n'
+'to change opinions, even on important subjects, which\n'
+'I once thought right but found to be otherwise.\u8221\n'
+'\u8195\u8195 \u8212 Benjamin Franklin, 1706\u82111790');

(For the typographically-unperceptive: the above contains left/right double
quotes, em spaces, an em dash, and an en dash)

There must be a better way than using String.fromCharCode() for a language
that is all 16-bit characters.

nf
 
N

nutso fasst

I said:
This doesn't:

alert('\u8220For having lived long, I have experienced many instances\n'

Oops, sorry. I didn't convert decimal numbers to hex. Actually works fine
when done right.
 
R

RobG

Grant Wagner wrote:
[...]
You want to turn the string of character entities into a string of actual characters based on those character entity values, which is what the code above does. It generates the string as requested (which can be confirmed by uncommenting the second assignment to
-s-), but I don't know if it actually works or not, I don't have Japanese language support installed.

FWIW, I added Japanese language support & rebooted - some characters
appeared that could well be Japanese. It 'worked' in IE and Firefox.
However, I have no idea what you have written or whether the correct
characters appeared.

<div style="border: 1px solid red; width: 30em; text-align: center;">
<script type="text/javascript">
var s =
'実装されていませ';
s = s.replace(
/&#(\d+);/g,
function($1, $2) {
return String.fromCharCode($2);
}
);
document.write(s);
</script>
</div>
 
D

Daniel

RobG said:
Grant Wagner wrote:
[...]
You want to turn the string of character entities into a string of actual characters based on those character entity values, which is what the code above does. It generates the string as requested (which can be confirmed by uncommenting the second assignment to
-s-), but I don't know if it actually works or not, I don't have Japanese language support installed.

FWIW, I added Japanese language support & rebooted - some characters
appeared that could well be Japanese. It 'worked' in IE and Firefox.
However, I have no idea what you have written or whether the correct
characters appeared.

<div style="border: 1px solid red; width: 30em; text-align: center;">
<script type="text/javascript">
var s =
'実装されていませ';
s = s.replace(
/&#(\d+);/g,
function($1, $2) {
return String.fromCharCode($2);
}
);
document.write(s);
</script>
</div>


Hi Rob and everyone else!

Thanks a bunch for your answers. I haven't installed japanese
characters. So it doesn't work in ie, but in firefox - like a dream!


/Daniel
 
T

Thomas 'PointedEars' Lahn

Daniel said:
Can I transform this
alert('実装されていませ');

into this?
alert('\u23455\u35013\u12373\u12428\u12390\u12356\u12414\u12379');

It doesn't seem to work. Does anyone have an idea?

"&#" in SGML must be followed by the decimal code point representation,
"\u" in ECMAScript compliant implementations by the hexadecimal code point
representation (like "&#x...." in SGML). 23455 != 0x23455 = 144469.

Although String.fromCharCode() does that conversion in a way, it is
unnecessary and therefore inefficient here. Do the conversion yourself
once instead and type the appropriate code point representation. You
should test if Unicode literals are supported by an implementation with
testing the length of the literal "\u0815" (you may use any four-digit
hexadecimal number here); if it is larger than 1, Unicode literals are
not supported by the implementation, thus you cannot provide message
boxes in the respective language.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top