Translit { public static String toWeakerTranslit(String text) { final StringBuilder builder = new StringBuilder(replaceChars(text, weakerCharTable)); Map<String, Pair<String, String>> pairsToReplace = new ImmutableMap.Builder<String, Pair<String, String>>() .put("ый", Pair.of("yi", "yy")) .put("ищ", Pair.of("ish", "ishch")) .build(); pairsToReplace.forEach((search, replacements) -> { if (containsIgnoreCase(text, search)) { String replaced = builder.toString().replaceAll( "(?i)" + replacements.getKey(), replacements.getValue() ); builder.replace(0, builder.length(), replaced); } }); return builder.toString(); } private  Translit(); static String toTranslit(String text); static String toWeakerTranslit(String text);  }
@Test public void toWeakerTranslitOnCyrillic() throws Exception { String expected = "Ochen nu oshen dlinnaya stroka s Raznymi simvolami russkogo alfavita. Y"; String actual = toWeakerTranslit("Очень ну ощень длинная строка с Разными символами русского алфавита. Ы"); assertEquals(expected, actual); }
@Test public void toWeakerTranslitOnLatin() throws Exception { assertEquals("this one must be 'left' as is. YI!!!", toWeakerTranslit("this one must be 'left' as is. YI!!!")); }