6

I have string a="L1-23Миграција од VPN и промена на брзина ACTELIS Agregator alternativna 8-/208";

I would like for every my string to check if there are some Cyrillic letters in string and to convert them to English:

Output should look:

L1-23Migracija od VPN i promena na brzina ACTELIS Agregator alternativna 8-/208

Thanks!

Veljko
  • 1,708
  • 12
  • 40
  • 80
  • Which encoding is the string in? – Ivaylo Strandjev Jun 05 '12 at 07:43
  • Did you do this for Bulgarian letters? It is similar I must do it for Macedonian letters – Veljko Jun 05 '12 at 07:55
  • 1
    I have only implemented such thing with switch. I am almost sure there is no pre-written library as the transliteration can possibly be different for different languages. After all you only have to write 30 cases in a switch statement and you will have what you want. – Ivaylo Strandjev Jun 05 '12 at 07:59
  • 30 + 30 (small and upper letters yes?) OK I think it is acceptable. Can you please give me some code for that? Thanks!!! – Veljko Jun 05 '12 at 08:00
  • And just one question- how do you different on example English "C" I suppose this is the S also in Bulgarian language? So how to tell it to if this is English C (like word "Case") do not convert and if it is Cyrillic C then to change it to S (on example Ситуација should be Situacija). – Veljko Jun 05 '12 at 08:03
  • I don't have the code I have written - I did this for the last time about 10 years ago. It should be pretty straight-forward how to write it. – Ivaylo Strandjev Jun 05 '12 at 08:04
  • OK can you answer me on second question I think it might be big problem – Veljko Jun 05 '12 at 08:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12150/discussion-between-izomorphius-and-dejan) – Ivaylo Strandjev Jun 05 '12 at 08:15
  • There is an **official transliteration on a per language basis**. For [Macedonian](https://en.wikipedia.org/wiki/Romanization_of_Macedonian) – Joop Eggen Feb 11 '19 at 14:35

1 Answers1

1

I found this method here on stackoverflow Transliteration from Cyrillic to Latin ICU4j java, it is for converting cyrillic(Russian) to latin (but you can convert it the other way around if needed). I tweaked it a bit so it's compatible for Macedonian Cyrillic(I believe that's what you need). Here it is:

public static String convertCyrilic(String message){
    char[] abcCyr =   {' ','а','б','в','г','д','ѓ','е', 'ж','з','ѕ','и','ј','к','л','љ','м','н','њ','о','п','р','с','т', 'ќ','у', 'ф','х','ц','ч','џ','ш', 'А','Б','В','Г','Д','Ѓ','Е', 'Ж','З','Ѕ','И','Ј','К','Л','Љ','М','Н','Њ','О','П','Р','С','Т', 'Ќ', 'У','Ф', 'Х','Ц','Ч','Џ','Ш','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','/','-'};
    String[] abcLat = {" ","a","b","v","g","d","]","e","zh","z","y","i","j","k","l","q","m","n","w","o","p","r","s","t","'","u","f","h", "c",";", "x","{","A","B","V","G","D","}","E","Zh","Z","Y","I","J","K","L","Q","M","N","W","O","P","R","S","T","KJ","U","F","H", "C",":", "X","{", "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","/","-"};
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < message.length(); i++) {
        for (int x = 0; x < abcCyr.length; x++ ) {
            if (message.charAt(i) == abcCyr[x]) {
                builder.append(abcLat[x]);
            }
        }
    }
    return builder.toString();
}

And then just use

String converted = convertCyrillic(a);
Zozinski
  • 73
  • 8