Skip to content

Instantly share code, notes, and snippets.

@jafar260698
Created October 13, 2021 07:55
Show Gist options
  • Save jafar260698/b1b0c9963521dbff8a1606393f2ca7f2 to your computer and use it in GitHub Desktop.
Save jafar260698/b1b0c9963521dbff8a1606393f2ca7f2 to your computer and use it in GitHub Desktop.
import 'package:inspektor/utils/translatorModel.dart';
class TranslatorHelper {
static List<CodeNameDto>? latin;
static List<CodeNameDto>? cyrillic;
static void init() {
latin = [];
latin!.add(CodeNameDto("o'", "ў"));
latin!.add(new CodeNameDto("o`", "ў"));
latin!.add(new CodeNameDto("g'", "ғ"));
latin!.add(new CodeNameDto("g`", "ғ"));
latin!.add(new CodeNameDto("'", "ъ"));
latin!.add(new CodeNameDto("`", "ъ"));
latin!.add(new CodeNameDto("sh", "ш"));
latin!.add(new CodeNameDto("ch", "ч"));
latin!.add(new CodeNameDto("yo", "ё"));
latin!.add(new CodeNameDto("yu", "ю"));
latin!.add(new CodeNameDto("ya", "я"));
latin!.add(new CodeNameDto("ye", "е"));
latin!.add(new CodeNameDto("ts", "ц"));
latin!.add(new CodeNameDto("a", "а"));
latin!.add(new CodeNameDto("b", "б"));
latin!.add(new CodeNameDto("d", "д"));
latin!.add(new CodeNameDto("e", "е"));
latin!.add(new CodeNameDto("f", "ф"));
latin!.add(new CodeNameDto("g", "г"));
latin!.add(new CodeNameDto("h", "ҳ"));
latin!.add(new CodeNameDto("i", "и"));
latin!.add(new CodeNameDto("j", "ж"));
latin!.add(new CodeNameDto("k", "к"));
latin!.add(new CodeNameDto("l", "л"));
latin!.add(new CodeNameDto("m", "м"));
latin!.add(new CodeNameDto("n", "н"));
latin!.add(new CodeNameDto("o", "о"));
latin!.add(new CodeNameDto("p", "п"));
latin!.add(new CodeNameDto("q", "қ"));
latin!.add(new CodeNameDto("r", "р"));
latin!.add(new CodeNameDto("s", "с"));
latin!.add(new CodeNameDto("t", "т"));
latin!.add(new CodeNameDto("u", "у"));
latin!.add(new CodeNameDto("v", "в"));
latin!.add(new CodeNameDto("x", "х"));
latin!.add(new CodeNameDto("y", "й"));
latin!.add(new CodeNameDto("z", "з"));
cyrillic = [];
cyrillic!.add(new CodeNameDto("ў", "o'"));
cyrillic!.add(new CodeNameDto("ғ", "g'"));
cyrillic!.add(new CodeNameDto("ъ", "'"));
cyrillic!.add(new CodeNameDto("ш", "sh"));
cyrillic!.add(new CodeNameDto("ч", "ch"));
cyrillic!.add(new CodeNameDto("ё", "yo"));
cyrillic!.add(new CodeNameDto("ю", "yu"));
cyrillic!.add(new CodeNameDto("я", "ya"));
cyrillic!.add(new CodeNameDto("э", "e"));
cyrillic!.add(new CodeNameDto("ц", "s"));
cyrillic!.add(new CodeNameDto("а", "a"));
cyrillic!.add(new CodeNameDto("б", "b"));
cyrillic!.add(new CodeNameDto("д", "d"));
cyrillic!.add(new CodeNameDto("е", "e"));
cyrillic!.add(new CodeNameDto("ф", "f"));
cyrillic!.add(new CodeNameDto("г", "g"));
cyrillic!.add(new CodeNameDto("ҳ", "h"));
cyrillic!.add(new CodeNameDto("и", "i"));
cyrillic!.add(new CodeNameDto("ж", "j"));
cyrillic!.add(new CodeNameDto("к", "k"));
cyrillic!.add(new CodeNameDto("л", "l"));
cyrillic!.add(new CodeNameDto("м", "m"));
cyrillic!.add(new CodeNameDto("н", "n"));
cyrillic!.add(new CodeNameDto("о", "o"));
cyrillic!.add(new CodeNameDto("п", "p"));
cyrillic!.add(new CodeNameDto("қ", "q"));
cyrillic!.add(new CodeNameDto("р", "r"));
cyrillic!.add(new CodeNameDto("с", "s"));
cyrillic!.add(new CodeNameDto("т", "t"));
cyrillic!.add(new CodeNameDto("у", "u"));
cyrillic!.add(new CodeNameDto("в", "v"));
cyrillic!.add(new CodeNameDto("х", "x"));
cyrillic!.add(new CodeNameDto("й", "y"));
cyrillic!.add(new CodeNameDto("з", "z"));
cyrillic!.add(new CodeNameDto("Ў", "O'"));
cyrillic!.add(new CodeNameDto("Ғ", "G'"));
cyrillic!.add(new CodeNameDto("Ш", "Sh"));
cyrillic!.add(new CodeNameDto("Ч", "Ch"));
cyrillic!.add(new CodeNameDto("Ё", "Yo"));
cyrillic!.add(new CodeNameDto("Ю", "Yu"));
cyrillic!.add(new CodeNameDto("Я", "Ya"));
cyrillic!.add(new CodeNameDto("Э", "E"));
cyrillic!.add(new CodeNameDto("Ц", "S"));
cyrillic!.add(new CodeNameDto("А", "A"));
cyrillic!.add(new CodeNameDto("Б", "B"));
cyrillic!.add(new CodeNameDto("Д", "D"));
cyrillic!.add(new CodeNameDto("Е", "E"));
cyrillic!.add(new CodeNameDto("Ф", "F"));
cyrillic!.add(new CodeNameDto("Г", "G"));
cyrillic!.add(new CodeNameDto("Ҳ", "H"));
cyrillic!.add(new CodeNameDto("И", "I"));
cyrillic!.add(new CodeNameDto("Ж", "J"));
cyrillic!.add(new CodeNameDto("К", "K"));
cyrillic!.add(new CodeNameDto("Л", "L"));
cyrillic!.add(new CodeNameDto("М", "M"));
cyrillic!.add(new CodeNameDto("Н", "N"));
cyrillic!.add(new CodeNameDto("О", "O"));
cyrillic!.add(new CodeNameDto("П", "P"));
cyrillic!.add(new CodeNameDto("Қ", "Q"));
cyrillic!.add(new CodeNameDto("Р", "R"));
cyrillic!.add(new CodeNameDto("С", "S"));
cyrillic!.add(new CodeNameDto("Т", "T"));
cyrillic!.add(new CodeNameDto("У", "U"));
cyrillic!.add(new CodeNameDto("В", "V"));
cyrillic!.add(new CodeNameDto("Х", "X"));
cyrillic!.add(new CodeNameDto("Й", "Y"));
cyrillic!.add(new CodeNameDto("З", "Z"));
}
static Future<String> transliterateToLatin(String text) async{
String trans = "";
if (text != null) {
trans = text;
for (var dto in cyrillic!) {
trans = trans.replaceAll(dto.code!, dto.name!);
}
}
return trans;
}
static Future<String> transliterateToCyrillic(String text) async {
String trans = "";
if (text != null) {
trans = text.toLowerCase();
for (var dto in latin!) {
trans = trans.replaceAll(dto.code!, dto.name!);
}
}
return trans;
}
}
class CodeNameDto {
final String? code;
final String? name;
CodeNameDto(this.code, this.name);
}
// Proektda SplashScreenda yoki main.dart pageda buildni ichiga qo'shib ketish kerak.
@override
Widget build(BuildContext context) {
TranslatorHelper.init();
return Scaffold();
}
@Hasanjon1996
Copy link

Assalomu alaykum
TextFormFieldga lotincha yozsa krelchani agar krelcha yozsa lotinchani topib berishi kerak shuni text form fieldga qanday ko'rsatsam bo'ladi

@jafar260698
Copy link
Author

Assalomu alaykum TextFormFieldga lotincha yozsa krelchani agar krelcha yozsa lotinchani topib berishi kerak shuni text form fieldga qanday ko'rsatsam bo'ladi

transliterateToLatin metodini chaqirsayiz bo'ldi, TextFormFieldni ichidayam chaqirsayiz ishlaydi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment