Skip to content

Commit

Permalink
Update switch_lang.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TopaGeor authored Dec 13, 2018
1 parent 66b13c5 commit 80d6b8d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions thefuck/rules/switch_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from thefuck.utils import memoize, get_alias

target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''
#any new keyboard layout must be appended

source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''',
u'''йцукенгшщзхїфівапролджєячсмитьбю.ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,''',
u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰ‌ٔء><؟''',
u''';ςερτυθιοπ[]ασδφγηξκλ;΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''',
u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''',
u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''']


Expand All @@ -17,7 +18,6 @@ def _get_matched_layout(command):
cmd = command.script.split(' ')
for source_layout in source_layouts:
is_all_match = True

for cmd_part in cmd:
if not all([ch in source_layout or ch in '-_' for ch in cmd_part]):
is_all_match = False
Expand All @@ -35,6 +35,24 @@ def _switch(ch, layout):


def _switch_command(command, layout):
if (source_layouts.index(layout) == 3):#this is for the Greek keyboard
keyboardDic = {';':"q", 'ς':"w", 'ε':"e", 'ρ':"r", 'τ':"t", 'υ':"y", 'θ':"u", 'ι':"i", 'ο':"o", 'π':"p", '[':"[",
']':"]", 'α':"a", 'σ':"s", 'δ':"d", 'φ':"f", 'γ':"g", 'η':"h", 'ξ':"j", 'κ':"k", 'λ':"l", ';':";",
'΄':"'", 'ζ':"z", 'χ':"x", 'ψ':"c", 'ω':"v", 'β':"b", 'ν':"n", 'μ':"m", ',':",", '.':".", '/':"/",
':':"Q", '΅':"W", 'Ε':"E", 'Ρ':"R", 'Τ':"T", 'Υ':"Y", 'Θ':"U", 'Ι':"I", 'Ο':"O", 'Π':"P", '{':"{",
'}':"}", 'Α':"A", 'Σ':"S", 'Δ':"D", 'Φ':"F", 'Γ':"G", 'Η':"H", 'Ξ':"J", 'Κ':"K", 'Λ':"L", '¨':":",
'"':'"', 'Ζ':"Z", 'Χ':"X", 'Ψ':"C", 'Ω':"V", 'Β':"B", 'Ν':"N", 'Μ':"M", '<':"<", '>':">", '?':"?",
'ά':"a", 'έ':"e", 'ύ':"y", 'ί':"i", 'ό':"o", 'ή':'h', 'ώ':"v", 'Ά':"A", 'Έ':"E", 'Ύ':"Y", 'Ί':"I",
'Ό': "O", 'Ή': "H", 'Ώ': "V"}
newCommand = ""
for ch in command.script:
try:
newCommand += keyboardDic[ch]
except KeyError:#This character has no repressentation at the dictionary, so it is a symbol and therefore we can add him, now works only for spaces and for this symbol "-"
newCommand += ch

return(newCommand)

return ''.join(_switch(ch, layout) for ch in command.script)


Expand Down

0 comments on commit 80d6b8d

Please sign in to comment.