471,316 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

Japanese characters in alert

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=e...com%26rnum%3D2

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?
Jul 23 '05 #1
7 5577
VK
You have to use hex values, not decimal ones:
\uFFFF
Jul 23 '05 #2
Daniel wrote:
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=e...com%26rnum%3D2
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.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

"VK" <sc**********@yahoo.com> wrote in message
news:41***********************@news.freenet.de...
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(819 5)+' '
+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
Jul 23 '05 #4
I wrote:
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.

Jul 23 '05 #5
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>
--
Rob
Jul 23 '05 #6
RobG <rg***@iinet.net.auau> wrote in message news:<XH*****************@news.optus.net.au>...
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
Jul 23 '05 #7
Daniel wrote:
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
--
Stay the patient course. Of little worth is your ire. The network is down.
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Shelly | last post: by
8 posts views Thread by Daniel | last post: by
1 post views Thread by Sriv Chakravarthy | last post: by
2 posts views Thread by Robert M. Gary | last post: by
3 posts views Thread by Mitchell Thomas | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.