Skip to content

Instantly share code, notes, and snippets.

@xacnio
Created April 11, 2022 18:04
Show Gist options
  • Save xacnio/b742e21cdb4a7676c5ce0d75e26ac398 to your computer and use it in GitHub Desktop.
Save xacnio/b742e21cdb4a7676c5ce0d75e26ac398 to your computer and use it in GitHub Desktop.
Golang - Turkish characters to english characters
func TurkishToEnglish(text string) string {
var text2 = []rune(text)
chars := map[rune]rune{
'ğ': 'g', 'Ğ': 'G', 'Ü': 'U', 'ü': 'u', 'ş': 's', 'Ş': 'S', 'Ö': 'O', 'ö': 'o', 'ç': 'c', 'Ç': 'C', 'İ': 'I', 'ı': 'i',
}
for i := 0; i < len(text2); i++ {
if val, ok := chars[text2[i]]; ok {
text2[i] = val
}
}
return string(text2)
}
// Example
// text := "Gökkuşağı, Türkçe, İngilizce, Ölüm, Çevik"
// newText := TurkishToEnglish(text);
// fmt.Println(newText) // Gokkusagi, Turkce, Ingilizce, Olum, Cevik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment