Advertisement
plirof2

Greekglish converters PHP,JS,Python3

Dec 26th, 2022 (edited)
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Greeklish / Greekglish
  2.  
  3. Search : https://github.com/search?p=2&q=greeklish&type=Repositories
  4.  
  5. ===========PHP============
  6. PHP : https://gist.github.com/teomaragakis/7580134
  7. https://github.com/konmavrakis/greek_to_greeklish/blob/master/script.php
  8. https://github.com/piliop/togreeklish  ++
  9.  
  10.  
  11.  
  12. //Replace Greek Chars with english
  13. function greeklish($str) {
  14.     //FIDE pre-process (here we put exceptions we might need)
  15. //  $greek = array('ΧΡ','Υ','Ύ');
  16. //  $english = array('CHR','U','U');
  17. //  $str = str_replace($greek, $english, $str);
  18.  
  19.   //letter    
  20.   $greek = array('α','ά','Ά','Α','β','Β','γ','Γ','δ','Δ','ε','έ','Ε','Έ','ζ','Ζ','η','ή','Η','θ','Θ',
  21.   'ι','ί','ϊ','ΐ','Ι','Ί','κ','Κ','λ','Λ','μ','Μ','ν','Ν','ξ','Ξ','ο','ό','Ο','Ό','π','Π','ρ','Ρ','σ',
  22.   'ς','Σ','τ','Τ','υ','ύ','Υ','Ύ','φ','Φ','χ','Χ','ψ','Ψ','ω','ώ','Ω','Ώ',' ');
  23.   $english = array('a', 'a','A','A','b','B','g','G','d','D','e','e','E','E','z','Z','i','i','I','th','Th',
  24.   'i','i','i','i','I','I','k','K','l','L','m','M','n','N','x','X','o','o','O','O','p','P' ,'r','R','s',
  25.   's','S','t','T','u','u','Y','Y','f','F','x','X','ps','Ps','o','o','O','O',' ');
  26.   $string = str_replace($greek, $english, $str);
  27.   return $string;
  28. }
  29.  
  30.  
  31. ===========Python 3 (help from chatgpt)===============
  32. import os
  33.  
  34. def custom_unidecode(char):
  35.     # Προσαρμογή της unidecode για ειδικές αντιστοιχίες
  36.     from_chars = ["ου", "ΟΥ", "Ού", "ού", "αυ", "ΑΥ", "Αύ", "αύ", "ευ", "ΕΥ", "Εύ", "εύ", "α", "Α", "ά", "Ά", "β", "Β", "γ", "Γ", "δ", "Δ", "ε", "Ε", "έ", "Έ", "ζ", "Ζ", "η", "Η", "ή", "Ή", "θ", "Θ", "ι", "Ι", "ί", "Ί", "ϊ", "ΐ", "Ϊ", "κ", "Κ", "λ", "Λ", "μ", "Μ", "ν", "Ν", "ξ", "Ξ", "ο", "Ο", "ό", "Ό", "π", "Π", "ρ", "Ρ", "σ", "Σ", "ς", "τ", "Τ", "υ", "Υ", "ύ", "Ύ", "ϋ", "ΰ", "Ϋ", "φ", "Φ", "χ", "Χ", "ψ", "Ψ", "ω", "Ω", "ώ", "Ώ"]
  37.     to_chars = ["ou", "ou", "ou", "ou", "au", "au", "au", "au", "eu", "eu", "eu", "eu", "a", "a", "a", "a", "b", "b", "g", "g", "d", "d", "e", "e", "e", "e", "z", "z", "i", "i", "i", "i", "th", "th", "i", "i", "i", "i", "i", "i", "i", "k", "k", "l", "l", "m", "m", "n", "n", "ks", "ks", "o", "o", "o", "o", "p", "p", "r", "r", "s", "s", "s", "t", "t", "y", "y", "y", "y", "y", "y", "y", "f", "f", "x", "x", "ps", "ps", "o", "o", "o", "o"]
  38.  
  39.     # Αντικατάσταση ειδικών χαρακτήρων
  40.     replacements = dict(zip(from_chars, to_chars))
  41.     return replacements.get(char, char)
  42.  
  43. def rename_files():
  44.     current_directory = os.getcwd()
  45.    
  46.     for filename in os.listdir(current_directory):
  47.         if os.path.isfile(os.path.join(current_directory, filename)):
  48.             # Αντικατάσταση ελληνικών χαρακτήρων με greekglish
  49.             new_filename = ''.join(custom_unidecode(char) for char in filename)
  50.            
  51.             # Μετονομασία του αρχείου
  52.             os.rename(os.path.join(current_directory, filename), os.path.join(current_directory, new_filename))
  53.            
  54.             print(f'Renamed: {filename} -> {new_filename}')
  55.  
  56. if __name__ == "__main__":
  57.     rename_files()
  58.  
  59.  
  60. ===========JAVASCRIPT===============
  61. JS : https://gist.github.com/kostasx/7516158
  62.  
  63. https://github.com/papasavva/Greeklish2Greek/blob/master/converter.js
  64.  
  65. https://github.com/kostasxyz/greeklish
  66.  
  67. https://github.com/kostasxyz/Skp-Greeklish-Slugs
  68.  
  69. https://github.com/attheodo/greeklishify/blob/master/greeklishify.js
  70.  
  71.  
  72. JAVASCRIPT
  73.  
  74. function string_to_slug(str) {
  75.  
  76. //https://gist.github.com/kostasx/7516158
  77.  str  = str.replace(/^\s+|\s+$/g, '') // TRIM WHITESPACE AT BOTH ENDS.
  78.           .toLowerCase();            // CONVERT TO LOWERCASE
  79.  
  80.  const from = [ "ου", "ΟΥ", "Ού", "ού", "αυ", "ΑΥ", "Αύ", "αύ", "ευ", "ΕΥ", "Εύ", "εύ", "α", "Α", "ά", "Ά", "β", "Β", "γ", "Γ", "δ", "Δ", "ε", "Ε", "έ", "Έ", "ζ", "Ζ", "η", "Η", "ή", "Ή", "θ", "Θ", "ι", "Ι", "ί", "Ί", "ϊ", "ΐ", "Ϊ", "κ", "Κ", "λ", "Λ", "μ", "Μ", "ν", "Ν", "ξ", "Ξ", "ο", "Ο", "ό", "Ό", "π", "Π", "ρ", "Ρ", "σ", "Σ", "ς", "τ", "Τ", "υ", "Υ", "ύ", "Ύ", "ϋ", "ΰ", "Ϋ", "φ", "Φ", "χ", "Χ", "ψ", "Ψ", "ω", "Ω", "ώ", "Ώ" ];
  81.  const to   = [ "ou", "ou", "ou", "ou", "au", "au", "au", "au", "eu", "eu", "eu", "eu", "a", "a", "a", "a", "b", "b", "g", "g", "d", "d", "e", "e", "e", "e", "z", "z", "i", "i", "i", "i", "th", "th", "i", "i", "i", "i", "i", "i", "i", "k", "k", "l", "l", "m", "m", "n", "n", "ks", "ks", "o", "o", "o", "o", "p", "p", "r", "r", "s", "s", "s", "t", "t", "y", "y", "y", "y", "y", "y", "y", "f", "f", "x", "x", "ps", "ps", "o", "o", "o", "o" ];
  82.  
  83.  for ( var i = 0; i < from.length; i++ ) {
  84.  
  85.     while( str.indexOf( from[i]) !== -1 ){
  86.  
  87.         str = str.replace( from[i], to[i] );    // CONVERT GREEK CHARACTERS TO LATIN LETTERS
  88.  
  89.     }
  90.  
  91.  }
  92.  
  93.  str = str.replace(/[^a-z0-9 -]/g, '') // REMOVE INVALID CHARS
  94.          .replace(/\s+/g, '-')        // COLLAPSE WHITESPACE AND REPLACE BY DASH -
  95.          .replace(/-+/g, '-');        // COLLAPSE DASHES
  96.  
  97.  return str;
  98. }
  99.  
  100.  
  101.  
  102. ---------- Forwarded message ---------
  103. From: giannos toula <giatoula@gmail.com>
  104. Date: Wed, Mar 20, 2013 at 10:58 PM
  105. Subject: greekglish_v09_20130320a.php
  106. To: JohnTrister.edu <trister12@yahoo.com>, JJ M <johnmail0+mycode@gmail.com>, <johnmail0@yahoo.gr>
  107.  
  108.  
  109. greekglish_v09_20130320a.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement