Writing arabic letters in Java [closed]

前提是你 提交于 2019-12-13 08:24:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!