Advertisement
nicolaslagios

Greek to Greeklish Javascript Function by Nicolas Lagios

Aug 3rd, 2023
1,326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.35 KB | Source Code | 0 0
  1. //Greek to Greeklish Javascript Function by Nicolas Lagios - Rocket Path P.C.
  2. function replaceGreekCharacters(txt) {
  3.     const greekToLatinMap = {
  4.       //μικρά ελληνικά
  5.       "α": "a","β": "b",
  6.       "γ": "g","δ": "d",
  7.       "ε": "e","ζ": "z",
  8.       "η": "h","θ": "th",
  9.       "ι": "i","κ": "k",
  10.       "λ": "l","μ": "m",
  11.       "ν": "n","ξ": "x",
  12.       "ο": "o","π": "p",
  13.       "ρ": "r","σ": "s",
  14.       "τ": "t","υ": "y",
  15.       "φ": "ph","χ": "ch",
  16.       "ψ": "ps","ω": "w",
  17.      
  18.       //μικρά με τόνους
  19.       "ά": "a","έ": "e",
  20.       "ή": "h","ί": "i",
  21.       "ό": "o","ύ": "y",
  22.       "ώ": "w",
  23.  
  24.       //κεφαλαία ελληνικά
  25.       "Α": "A","Β": "B",
  26.       "Γ": "G","Δ": "D",
  27.       "Ε": "E","Ζ": "Z",
  28.       "Η": "H","Ρ": "TH",
  29.       "Ι": "I","Κ": "K",
  30.       "Λ": "L","Μ": "M",
  31.       "Ν": "N","Ξ": "X",
  32.       "Ο": "O","Π": "P",
  33.       "Ρ": "R","Σ": "S",
  34.       "Τ": "T","Υ": "Y",
  35.       "Φ": "PH","Χ": "CH",
  36.       "Ψ": "PS","Ω": "W",
  37.      
  38.       //κεφαλαία με τόνους
  39.       "Ά": "A","Έ": "E",
  40.       "Ή": "H","Ί": "I",
  41.       "Ό": "O","Ύ": "Y",
  42.       "Ώ": "W",
  43.     };
  44.     for (const greekCharacter in greekToLatinMap) {
  45.         txt = txt.replace(greekCharacter, greekToLatinMap[greekCharacter]);
  46.     }
  47.     return txt;
  48.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement