问题
I want to make it possible to write in Arabic in my server. It works but from left to right so I used that StringUtils.reverse(_text) now my text is written from RTL but the problem is this:
the text is written separately ( e x a m p l e )
In my logger
Log.LogChat(_type.name(), activeChar.getName(), _target, _text);
the chat is written correctly in my log.txt, but in the game it's written with spaces
// arabic chat
Say2 cs = new Say2(activeChar.getObjectId(), _type, activeChar.getName(), StringUtils.reverse(_text));
Does anyone know why?
回答1:
You do NOT want to "reverse the string"!
Instead, you want to translate your application's text to Arabic ... and you want that text displayed in Arabic. Which will automatically handle Right-to-Left.
You want to utilize Java "locales".
Check out these links:
How to add locale for Arabic
http://www.oracle.com/technetwork/articles/javase/locale-140624.html
http://docs.oracle.com/javase/tutorial/i18n/locale/create.html
https://blogs.oracle.com/geertjan/entry/tips_for_arabic_java_desktop
回答2:
in simple,in your game, use a jtextcomponent class and set the locale to arabic.
for more details see: http://docs.oracle.com/javase/tutorial/i18n/text/bidi.html
来源:https://stackoverflow.com/questions/20846492/writing-arabic-letters-in-java