- Saved searches
- Use saved searches to filter your results more quickly
- License
- massita99/iuliia-java
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.MD
- Транслитерация с кириллицы на латиницу
- Saved searches
- Use saved searches to filter your results more quickly
- License
- Homyakin/iuliia-java
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Java кириллица в латиницу
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Transliterate Cyrillic → Latin in every possible way
License
massita99/iuliia-java
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.MD
Transliterate Cyrillic → Latin in every possible way
This is the port of the incredible python library iuliia made by @nalgeon
Transliteration means representing Cyrillic data (mainly names and geographic locations) with Latin letters. It is used for international passports, visas, green cards, driving licenses, mail and goods delivery etc.
Iuliia makes transliteration as easy as:
import io.github.massita99.Iuliia; import io.github.massita99.Schemas; public class Application < public static void main(String[] args) < System.out.println(Iulia.translate("Юлия", Schemas.forName("yandex_maps"))); //OR: System.out.println(Iulia.translate("Юлия", Schemas.AllSchemas.YANDEX_MAPS)); > > >> Yuliya
- 20 transliteration schemas (rule sets), including all main international and Russian standards.
- Correctly implements not only the base mapping, but all the special rules for letter combinations and word endings (AFAIK, Iuliia is the only library which does so).
- Simple API and zero third-party dependencies.
dependencies < implementation 'io.github.massita99:iuliia-java:0.2' >
dependency> groupId>io.github.massita99groupId> artifactId>iuliia-javaartifactId> version>0.2version> dependency>
schemas folder is the git submodule from general repository.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Make sure to add or update tests as appropriate.
Транслитерация с кириллицы на латиницу
Всем привет! Надо сделать транслитерацию с кириллицы на латиницу. В принципе несложно,
если для такого: Лилия->Liliya, Яблоко->Yabloko.
Но если все буквы заглавные — ЯБЛОКО->YaBLOKO и это не есть хорошо (есть хорошо — YABLOKO).
Или бывает и такое ХоРоШо- KhoRoSho (а надо бы KHoRoSHo).
Так вот, как это воссоздать. Может быть использовав getChars — мысль такая: если после текущего символа следует
заглавная, то пишем все заглавные) Но что-то мутновато как-то. Может ли кто, предложить что-нибудь?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
import java.util.*; import java.lang.*; import java.io.*; class Translit { private static final MapString, String> letters = new HashMapString, String>(); static { letters.put("А", "A"); letters.put("Б", "B"); letters.put("В", "V"); letters.put("Г", "G"); letters.put("Д", "D"); letters.put("Е", "E"); letters.put("Ё", "E"); letters.put("Ж", "Zh"); letters.put("З", "Z"); letters.put("И", "I"); letters.put("Й", "I"); letters.put("К", "K"); letters.put("Л", "L"); letters.put("М", "M"); letters.put("Н", "N"); letters.put("О", "O"); letters.put("П", "P"); letters.put("Р", "R"); letters.put("С", "S"); letters.put("Т", "T"); letters.put("У", "U"); letters.put("Ф", "F"); letters.put("Х", "Kh"); letters.put("Ц", "C"); letters.put("Ч", "Ch"); letters.put("Ш", "Sh"); letters.put("Щ", "Sch"); letters.put("Ъ", "'"); letters.put("Ы", "Y"); letters.put("Ъ", "'"); letters.put("Э", "E"); letters.put("Ю", "Yu"); letters.put("Я", "Ya"); letters.put("а", "a"); letters.put("б", "b"); letters.put("в", "v"); letters.put("г", "g"); letters.put("д", "d"); letters.put("е", "e"); letters.put("ё", "e"); letters.put("ж", "zh"); letters.put("з", "z"); letters.put("и", "i"); letters.put("й", "i"); letters.put("к", "k"); letters.put("л", "l"); letters.put("м", "m"); letters.put("н", "n"); letters.put("о", "o"); letters.put("п", "p"); letters.put("р", "r"); letters.put("с", "s"); letters.put("т", "t"); letters.put("у", "u"); letters.put("ф", "f"); letters.put("х", "h"); letters.put("ц", "c"); letters.put("ч", "ch"); letters.put("ш", "sh"); letters.put("щ", "sch"); letters.put("ъ", "'"); letters.put("ы", "y"); letters.put("ъ", "'"); letters.put("э", "e"); letters.put("ю", "yu"); letters.put("я", "ya"); } public static String toTranslit(String text) { StringBuilder sb = new StringBuilder(text.length()); for (int i = 0; itext.length(); i++) { String l = text.substring(i, i+1); if (letters.containsKey(l)) { sb.append(letters.get(l)); } else { sb.append(l); } } return sb.toString(); } public static void main(String[] args) { String test = "Яблоко, ЯБЛОКО, ХОРОШО, ХоРоШо"; System.out.println("toTranslit(test) = " + toTranslit(test)); } }
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Transliterate Cyrillic → Latin in every possible way (Java version)
License
Homyakin/iuliia-java
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Transliterate Cyrillic → Latin in every possible way
Transliteration means representing Cyrillic data (mainly names and geographic locations) with Latin letters. It is used for international passports, visas, green cards, driving licenses, mail and goods delivery etc.
- 20 transliteration schemas (rule sets), including all main international and Russian standards.
- Correctly implements not only the base mapping, but all the special rules for letter combinations and word endings (AFAIK, Iuliia is the only library which does so).
- Simple API.
For schema details and other information, see https://dangry.ru/iuliia (in Russian).
https://mvnrepository.com/artifact/ru.homyakin/iuliia-java --> dependency> groupId>ru.homyakingroupId> artifactId>iuliia-javaartifactId> version>1.8version> dependency>
implementation 'ru.homyakin:iuliia-java:1.8'
Transliterate using specified schema:
import ru.homyakin.iuliia.Schemas; import ru.homyakin.iuliia.Translator; public class Clazz < public static void test() < var translator = new Translator(Schemas.ICAO_DOC_9303); translator.translate("Юлия"); //Iuliia > >
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Make sure to add or update tests as appropriate.
Java кириллица в латиницу
Надо перевести текст в латиницу
Всем привет Друзья
vsem privet druzьya
Выполняется все это через Scanner.
Как сделать что бы читал > Всем привет Друзья< из txt файла,потом после перевода заменил текст на латиницу >vsem privet druzьya
import java.util.Scanner; public class Translater < public static void main ( String [] args ) // asks the user to select which translation (latyn to english or english to latyn) and then prompts user to enter the text to be translated < Scanner input = new Scanner( System.in ); System.out.println( "Enter sentence" ); String english = input.nextLine(); System.out.println( stringTolatyn( english ) ); >public static String encode (String toEncode) < String latyn = toEncode; if (toEncode.equalsIgnoreCase("а")) latyn = "a"; if (toEncode.equalsIgnoreCase("б")) latyn = "b"; if (toEncode.equalsIgnoreCase("в")) latyn = "v"; if (toEncode.equalsIgnoreCase("г")) latyn = "g"; if (toEncode.equalsIgnoreCase("д")) latyn = "d"; if (toEncode.equalsIgnoreCase("е")) latyn = "e"; if (toEncode.equalsIgnoreCase("ж")) latyn = "zh"; if (toEncode.equalsIgnoreCase("з")) latyn = "z"; if (toEncode.equalsIgnoreCase("и")) latyn = "i"; if (toEncode.equalsIgnoreCase("й")) latyn = "j"; if (toEncode.equalsIgnoreCase("к")) latyn = "k"; if (toEncode.equalsIgnoreCase("л")) latyn = "l"; if (toEncode.equalsIgnoreCase("м")) latyn = "m"; if (toEncode.equalsIgnoreCase("н")) latyn = "n"; if (toEncode.equalsIgnoreCase("о")) latyn = "o"; if (toEncode.equalsIgnoreCase("п")) latyn = "p"; if (toEncode.equalsIgnoreCase("р")) latyn = "r"; if (toEncode.equalsIgnoreCase("с")) latyn = "s"; if (toEncode.equalsIgnoreCase("т")) latyn = "t"; if (toEncode.equalsIgnoreCase("у")) latyn = "u"; if (toEncode.equalsIgnoreCase("ф")) latyn = "f"; if (toEncode.equalsIgnoreCase("х")) latyn = "x"; if (toEncode.equalsIgnoreCase("ц")) latyn = "c"; if (toEncode.equalsIgnoreCase("ч")) latyn = "ch"; if (toEncode.equalsIgnoreCase("ш")) latyn = "sh"; if (toEncode.equalsIgnoreCase("щ")) latyn = "shh"; if (toEncode.equalsIgnoreCase("ы")) latyn = "y"; if (toEncode.equalsIgnoreCase("э")) latyn = "e"; if (toEncode.equalsIgnoreCase("ю")) latyn = "yu"; if (toEncode.equalsIgnoreCase("я")) latyn = "ya"; return latyn; >public static String stringTolatyn( String text ) < String newText = ""; String selectedChar; String convertedChar; for (int i = 0; i < text.length(); i++) < //Select the next character selectedChar = text.charAt(i) + ""; // Convert the character convertedChar = encode(selectedChar); if (convertedChar.equalsIgnoreCase("")) // "|" separates each word represented in latyn code < newText = newText + " "; //создер арасындагы танба >// Add the converted text, and add a space else < newText = newText + convertedChar; if (!convertedChar.equalsIgnoreCase("")) < newText = newText + ""; >> > return newText; > >
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Translate < private static Mapmap = new HashMap() < < put('а', "a"); put('б', "b"); put('в', "v"); put('г', "g"); put('д', "d"); put('е', "e"); put('ж', "zh"); put('з', "z"); put('и', "i"); put('й', "j"); put('к', "k"); put('л', "l"); put('м', "m"); put('н', "n"); put('о', "o"); put('п', "p"); put('р', "r"); put('с', "s"); put('т', "t"); put('у', "u"); put('ф', "f"); put('х', "x"); put('ц', "c"); put('ч', "ch"); put('ш', "sh"); put('щ', "shh"); put('ы', "y"); put('э', "e"); put('ю', "yu"); put('я', "ya"); >>; public static void main(String[] args) < try (FileInputStream fis = new FileInputStream(new File("test_rus.txt"))) < Scanner scanner = new Scanner(fis); for (; scanner.hasNext(); ) < String line = scanner.nextLine(); for (int i = 0; i < line.length(); i++) < char ch = line.charAt(i); if (!map.containsKey(ch)) < System.out.print(ch); continue; >System.out.print(map.get(ch)); > > > catch (IOException e) < e.printStackTrace(); >> >
«Keep it simple» — придерживайтесь простоты!
Уильям Оккам — «Не следует множить сущее без необходимости»
Сложность — враг простоты и удобства!
Это транслитерация называется.
Да, совсем не похоже. Но пусть будет так.
Немного подправил.
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import static java.lang.System.out; public class Translate < private static final String TEST_RUS_TXT = "test_rus.txt"; private static Mapmap = new HashMap() < < put('а', "a"); put('б', "b"); put('в', "v"); put('г', "g"); put('д', "d"); put('е', "e"); put('ж', "zh"); put('з', "z"); put('и', "i"); put('й', "j"); put('к', "k"); put('л', "l"); put('м', "m"); put('н', "n"); put('о', "o"); put('п', "p"); put('р', "r"); put('с', "s"); put('т', "t"); put('у', "u"); put('ф', "f"); put('х', "x"); put('ц', "c"); put('ч', "ch"); put('ш', "sh"); put('щ', "shh"); put('ы', "y"); put('э', "e"); put('ю', "yu"); put('я', "ya"); >>; public static void main(String[] args) < try (FileInputStream fis = new FileInputStream(new File(TEST_RUS_TXT))) < Scanner scanner = new Scanner(fis); for (; scanner.hasNext(); ) < String line = scanner.nextLine(); final int LENGTH = line.length(); for (int i = 0; i < LENGTH; i++) < char ch = Character.toLowerCase(line.charAt(i)); out.print((!map.containsKey(ch)) ? ch : map.get(ch)); >out.println(); > > catch (IOException e) < e.printStackTrace(); >> >
«Keep it simple» — придерживайтесь простоты!
Уильям Оккам — «Не следует множить сущее без необходимости»
Сложность — враг простоты и удобства!