Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: phonetic to cyrillic converter

  1. #1
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default phonetic to cyrillic converter

    Hello forum! I've been working on adding Russian support to my game, and I feel that I should share my code for converting phonetic Russian into Cyrillic. Example: Privjet Rossii --> Привет России. So far I have added Phonetic String --> Cyrillic String, Int Array --> Cyrillic String, and I'm working on KeyCode --> Cyrillic char. (for typing ingame) I feel that this little program will make programming in Russian alot easier.

    Here are a few examples on how to use it:

    russianConverterr rt = new russianConverter();
     
    String phoneticExample = rt.enToRuSTR("Privjet Rossii"); //convert  Privjet Rossii to  Привет России
     
    int sample = {0,1,2,3};
    String intArrayExample = rt.enToRuINT(sample);  //convert {0,1,2,3} to АБВГ
     
    String unicodes[] = rc.getAllCyrillicUni(); //returns all cyrillic unicodes.

    Even if you don't use this, realize how long it took me to add all Cyrillic Unicodes!

    PLEASE NOTE: The returned strings contain unicodes which will show up as "?" in terminal/CMD, but will work fine for everything else.

    Here is the code:
    public class russianConverter {
    	String returnMessage;
    	int i;
    	String[] ruAlpha = {
    			"\u0410","\u0411","\u0412","\u0413","\u0414","\u0415","\u0416","\u0417","\u0418","\u0419",
    			"\u041A","\u041B","\u041C","\u041D","\u041E","\u041F","\u0420","\u0421","\u0422","\u0423",
    			"\u0424","\u0425","\u0426","\u0427","\u0428","\u0429","\u042A","\u042B","\u042C","\u042D",
    			"\u042E","\u042F","\u0430","\u0431","\u0432","\u0433","\u0434","\u0435","\u0436","\u0437",
    			"\u0438","\u0439","\u043A","\u043B","\u043C","\u043D","\u043E","\u043F","\u0440","\u0441",
    			"\u0442","\u0443","\u0444","\u0445","\u0446","\u0447","\u0448","\u0449","\u044A","\u044B",
    			"\u044C","\u044D","\u044E","\u044F"
    			};
     
    	public String[] getAllCyrillicUni(){
    		return ruAlpha;
    	}
     
    	public String enToRuINT(int[] message){
    		returnMessage= "";
     
    		for(i=0;i<message.length;i++)
    			returnMessage += ruAlpha[message[i]];
     
    		return returnMessage;
    	}
     
    	public String enToRuSTR(String message){
    		return message
    		.replace("YERU", "\u042B")
    		.replace("yeru", "\u044B")
    		.replace("TS", "\u0426")
    		.replace("CH", "\u0427")
    		.replace("SHA", "\u0428")
    		.replace("SHCHA", "\u0429")
    		.replace("SI", "\u0419")
    		.replace("JE", "\u0415")
    		.replace("ZH", "\u0416")
    		.replace("YU", "\u042E")
    		.replace("YA", "\u042F")
    		.replace("yu", "\u044E")
    		.replace("ya", "\u044F")
    		.replace("je", "\u0435")
    		.replace("zh", "\u0436")
    		.replace("si", "\u0439")
    		.replace("ch", "\u0447")
    		.replace("sha", "\u0448")
    		.replace("shcha", "\u0449")
    		.replace("A", "\u0410")
    		.replace("B", "\u0411")
    		.replace("V", "\u0412")
    		.replace("G", "\u0413")
    		.replace("D", "\u0414")
    		.replace("Z", "\u0417")
    		.replace("I", "\u0418")
    		.replace("K", "\u041A")
    		.replace("L", "\u041B")
    		.replace("M", "\u041C")
    		.replace("N", "\u041D")
    		.replace("O", "\u041E")
    		.replace("P", "\u041F")
    		.replace("R", "\u0420")
    		.replace("S", "\u0421")
    		.replace("T", "\u0422")
    		.replace("U", "\u0423")
    		.replace("F", "\u0424")
    		.replace("H", "\u0425")
    		.replace("''", "\u042A")
    		.replace("'", "\u042C")
    		.replace("E", "\u042D")
    		.replace("a", "\u0430")
    		.replace("b", "\u0431")
    		.replace("v", "\u0432")
    		.replace("g", "\u0433")
    		.replace("d", "\u0434")
    		.replace("z", "\u0437")
    		.replace("i", "\u0438")
    		.replace("k", "\u043A")
    		.replace("l", "\u043B")
    		.replace("m", "\u043C")
    		.replace("n", "\u043D")
    		.replace("o", "\u043E")
    		.replace("p", "\u043F")
    		.replace("r", "\u0440")
    		.replace("s", "\u0441")
    		.replace("t", "\u0442")
    		.replace("u", "\u0443")
    		.replace("f", "\u0444")
    		.replace("h", "\u0445")
    		.replace("ts", "\u0446")
    		.replace("''", "\u044A")
    		.replace("'", "\u044C")
    		.replace("e", "\u044D");
     
    	}
    }
    Last edited by Brt93yoda; September 4th, 2010 at 02:47 AM.


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: phonetic to cyrillic converter

    Has anyone messed around with it at all?

Similar Threads

  1. Piglatin Converter
    By jross21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2010, 12:09 PM