0

I have the following code:

<input type="text" style="text-transform: uppercase" />

The string gets transformed to uppercase, but ü for example, will transform to Ü.
I want ü to transform to U, e.g. Gülay should become GULAY.
Does anyone have any idea how can I do this?

MathKimRobin
  • 1,268
  • 3
  • 21
  • 52
Gülay Uygun
  • 51
  • 10
  • Did I get that right, you want to transform umlaut U (Ü) to usual U ? – Axel Amthor Dec 16 '14 at 12:10
  • DEAR GULAY - CAN YOU REPHRASE THAT? – chiccodoro Dec 16 '14 at 12:10
  • ok. For example: My name is Gülay. I can transfer this text MY NAME İS GÜLAY. But I don't want to İ and Ü letters. I want MY NAME IS GULAY. – Gülay Uygun Dec 16 '14 at 12:18
  • could you please use markdown so that we could _see_ your text ?? – Axel Amthor Dec 16 '14 at 12:20
  • @GülayUygun - it seems that what you want is not uppercasing the `ü` to `Ü` but replacing the character with another one. I don't know exactly why you would want that (why should you want the "umlaut" when having lowercase text but not want it when you have uppercase text?), `text-transform: uppercase`, as the name says, transforms to uppercase. If you want to replace certain letters by others, you will need to curate your data before it goes to the view. – chiccodoro Dec 16 '14 at 13:55
  • http://stackoverflow.com/questions/1850232/turkish-case-conversion-in-javascript seems related – chiccodoro Dec 16 '14 at 13:57

2 Answers2

2
String.prototype.turkishToLower = function () {
var string = this;
var letters = {
  İ: "i", I: "i", ı: "i", Ş: "s", ş: "s", Ğ: "g", ğ: "g", Ü: "u", ü: "u", Ö: "o", ö: "o", Ç: "c", ç: "c",
};
string = string.replace(/(([İIıŞşĞğÜüÇçÖö]))/g, function (letter) {
  return letters[letter];
});
return string.toLowerCase();}


String.prototype.turkishToUpper = function(){
var string = this;
var letters = { "i": "I", "ş": "S", "ğ": "G", "ü": "U", "ö": "O", "ç": "C", "ı": "I" };
string = string.replace(/(([iışğüçö]))/g, function(letter){ return letters[letter]; });
return string.toUpperCase();}

use it "string".turkishToLower()

  • Modifying native types prototypes is rarely a good idea. But your code is working. Maybe you should consider creating a small object constructed with your string and use those two methods with it – MathKimRobin Sep 01 '20 at 15:07
1

If this data is comming from a database, I suggest you treat this on your server before you send to your view. But you can also use a javascript for that if you don't want this to happen on the server.

Check out this answer: Remove accents/diacritics in a string in JavaScript

You could use something like:

var finalString = removeDiacritics(initialString).toUpperCase();
Community
  • 1
  • 1
rodrigogq
  • 1,943
  • 1
  • 16
  • 25