language-translationgoogle-translation-api

GoogleAPI translation to sr-Latn translating to sr-Cyrilic


Serbian has 2 alphabets, Latin and Cyrillic. Is Latin supported and how to get it ?

According to this post: https://support.google.com/translate/thread/1836538/google-translate-to-serbian-latin?hl=en it should work with explicit longer language code instead of just 'sr' there are 'sr-Latn' and 'sr-Cyrl'. But even with sr-Latn it still translates in the cyrillic alphabet.


Solution

  • Maybe late but I solved this with function that replaces Cyrilic characters with Alphabetic.

    C# code below:

    private static string TranslateFromCyrToAlph(string str)
    {
        string[] rus_up = { "А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й",  "К", "Л", "Љ", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ",   "Ъ",   "Ы", "Ь", "Э", "Ю",  "Я", "Ћ", "Џ",  "Њ", "Ђ" };
        string[] lat_up = { "A", "B", "V", "G", "D", "E", "Yo", "Ž", "Z", "I", "Y", "K", "L","LJ", "M", "N", "O", "P", "R", "S", "T", "U", "F", "h", "C", "č", "š", "Shch", "\"", "Y", "'", "E", "Yu", "C", "Ć", "Dž", "Nj", "Đ"};
    
        string[] rus_low = { "а", "б", "в", "г", "д", "е", "ё",  "ж", "з", "и", "й", "к", "л", "љ", "м", "н",  "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ",    "ъ", "ы", "ь", "э",  "ю",  "я", "ћ", "џ", "њ",  "ђ" };
        string[] lat_low = { "a", "b", "v", "g", "d", "e", "yo", "ž", "z", "i", "y", "k", "l", "lj", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "c", "č", "š", "shch", "\"", "y", "'", "e", "yu", "c", "ć","dž", "nj", "đ" };
        for (int i = 0; i <= 36; i++)
        {
            str = str.Replace(rus_up[i], lat_up[i]);
            str = str.Replace(rus_low[i], lat_low[i]);
        }
        return str;
    }