# -*- encoding: utf-8 -*-

target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''

source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''']


def _get_matched_layout(command):
    for source_layout in source_layouts:
        if all([ch in source_layout or ch in '-_'
                for ch in command.script.split(' ')[0]]):
            return source_layout


def match(command, settings):
    return 'not found' in command.stderr and _get_matched_layout(command)


def _switch(ch, layout):
    if ch in layout:
        return target_layout[layout.index(ch)]
    else:
        return ch


def get_new_command(command, settings):
    matched_layout = _get_matched_layout(command)
    return ''.join(_switch(ch, matched_layout) for ch in command.script)


@@ -201,16 +201,91 @@
 %D0%A2%D0%AC%D0%91%D0%AE,'''
+, u'''%D8%B6%D8%B5%D8%AB%D9%82%D9%81%D8%BA%D8%B9%D9%87%D8%AE%D8%AD%D8%AC%DA%86%D8%B4%D8%B3%DB%8C%D8%A8%D9%84%D8%A7%D8%AA%D9%86%D9%85%DA%A9%DA%AF%D8%B8%D8%B7%D8%B2%D8%B1%D8%B0%D8%AF%D9%BE%D9%88./%D9%92%D9%8C%D9%8D%D9%8B%D9%8F%D9%90%D9%8E%D9%91%5D%5B%7D%7B%D8%A4%D8%A6%D9%8A%D8%A5%D8%A3%D8%A2%D8%A9%C2%BB%C2%AB:%D8%9B%D9%83%D9%93%DA%98%D9%B0%E2%80%8C%D9%94%D8%A1%3E%3C%D8%9F'''
 %5D%0A%0A%0Adef 

add persian language to switch lang rule refs #28