Skip to content

Instantly share code, notes, and snippets.

@yunusemre002
Last active March 6, 2022 21:33
Show Gist options
  • Save yunusemre002/eee6c4e261934c91a2aa4468195c34e9 to your computer and use it in GitHub Desktop.
Save yunusemre002/eee6c4e261934c91a2aa4468195c34e9 to your computer and use it in GitHub Desktop.
js-turkish-to-english.js
// It converts all lowercase or uppercase Turkish characters to English one on given text.
String.prototype.turkishToEnglish = function () {
return this
.replace(/Ğ/g, "G")
.replace(/ğ/g, "g")
.replace(/Ü/g, "U")
.replace(/ü/g, "u")
.replace(/Ş/g, "S")
.replace(/ş/g, "s")
.replace(/İ/g, "I")
.replace(/ı/g, "i")
.replace(/Ö/g, "O")
.replace(/ö/g, "o")
.replace(/Ç/g, "C")
.replace(/ç/g, "c");
};
// //Example
// let text = 'Şinasi bu akşam sağa sola çağrı atıp durdu. Bu Çocuk neden böyle... ğğĞĞÜÜüüŞŞşşÖÖööÇÇçç';
// console.log(text.turkishToEnglish())
// //output: Sinasi Bu aksam saga sola cagri atip durdu. Bu Cocuk neden boyle... ggGGUUuuSSssOOooCCcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment