#!/usr/bin/env python
# -*- coding: utf-8 -*-

class Language:
    lang_dict = {}
    lang_dict['zh']={
        "https://ovo.ltd/projects/globalvim-en/":"https://ovo.ltd/projects/globalvim-en/",
        "No GeeKey HotKey selected, remain unchanged!":"未选择热键,原热键保持不变!",
        "\nShort stoke to perform {0}":"\n短按为{0}",
        '--geekey--spacing--':'--geekey--空挡--',
        '--geekey--recording--':'--geekey--录制--',
        '--geekey--spacing--recording--':'--geekey--空挡--录制--',
        'Keyboard State Cleared':'键盘状态重置',
        "Click to Clear Keyboard State":"点击重置键盘状态",
        "'block' mode blocks original function. While 'longblock' mode blocks only when pressed longer or in combo keys.":"'阻塞‘模式阻塞GeeKey键原功能。'长按阻塞'模式在长按或者组合键时阻塞。",
        'GeeKey Mode':'GeeKey 模式',
        'block':'阻塞',
        'longblock':'长按阻塞',
        'Click to select another GeeKey HotKey':'点击重设 GeeKey 热键',
        'GeeKey HotKey is set to {0}':'{0} 已被设置 GeeKey 热键',
        "Click Ok to set new GeeKey to {0}. Otherwize Click Cancel.":'单击确认将 {0} 设为新热键. 否则请点击取消.',
        'GeeKey HotKey':'GeeKey 热键',
        'Press Key as new GeeKey':'请按下新的 GeeKey 热键',
        'GlobalVim/GeeKey':'全局 Vim',
        'Save Layout':'保存布局',
        'enable vim mode':'启用vim模式',
        'exit vim mode':'退出vim模式',
        'substitution failed for: {0}':'替换失败: {0}',
        'substitution done':'替换完成',
        '{0} done':'{0} 完成',
        "Invalid search scope {0}":"搜索范围 {0} 不合法",
        'Error':'错误',
        'Another GlobalVim/GeeKey instance is running':'GlobalVim/GeeKey 已经启动,并处于运行状态中',
        '_title_this': '全局Vim/GeeKey热键',
        '_name': "名字",
        '_email': '邮箱',
        '_about': '关于',
        '_apply': '应用',
        '_hotkey': '热键',
        '_operation': '操作',
        '_help': '帮助',
        '_quit': '退出',
        '_about_message': """谢谢使用GlobalVim/GeeKey! 欢迎提出改进建议!\n有问题请致信einsxiao@hotmail.com.""",
        '_startup_with_system':'开机启动',
        '_text_to_key':"'{0}' 绑定的文本",
        '_function_to_key':"'{0}' 绑定的程序",
        '_macro_to_key':"'{0}' 绑定的操作序列",
        '_macro_to_key_text':"'Ctrl+GeeKey+{0}' 开始录制操作,Ctrl+GeeKey结束录制",
        '_support_tooltip_wechat':'微信扫码点赞, 点击显示log',
        '_previous':'上一条',
        '_next':'下一条',
        '_more':'更多',
        '_text_color_info':'绑定文本',
        '_edit_color_info':'绑定按键',
        '_macro_color_info':'绑定录制',
        '_function_color_info':'绑定程序',
        '_not_run_as_admin':'须以管理员权限重启程序,才能修改当前按键',
        '_tip_for_geekey':'GeeKey+X     -执行X的绑定;\nGeeKey+Space X     -执行X的空挡绑定{0}',
        '_tip_for_space':'GeeKey+Space X     -执行 X 绑定的空档绑定\nGeeKey+Space N X     -执行N次X\nGeeKey+Space Space     -弹出主界面',
        '_tip_for_tab':'GeeKey+Space Tab     -开启/关闭自动补全功能\n',
        '_tip_for_v':'GeeKey+v     -进入/退出vim模式\n',
        '_tip_for_q':'GeeKey+q X     -开始录制X的绑定宏\nGeeKey+q Space X     -开始录制X的空档绑定宏\nGeeKey+q     -结束当前录制\n',
        '_warning':'警告',
        '_notice':'注意',
        '_restart_to_function':'重启后更改才能生效',
        '_reboot_to_function':'重启后更改才能生效',
        '_layout':'键位布局{0}',
        '_startup':'开机启动',
        '_startshow':'程序启动时, 显示界面',
        '_doubleclickfix':'修复鼠标双击硬件错误',
        '_configure':'配置',
        '_language':'语言',
        '_general':'一般设置',
        '_account':'Eva账户',
        '_about':'关于GlobalVim/GeeKey',
        '_configure_menu':'配置(&C)\tCtrl+C',
        '_exit_menu':"退出(&E)",
        '_loadfrom_menu':"从文件导入(&L)\tCtrl+L",
        '_saveas_menu':"保存到文件(&S)\tCtrl+S",
        '_save_menu':"保存(&S)\tCtrl+Shift+S" ,
        '_tutorial_menu':"手册(&M)",
        '_about_menu':"关于(&A)" ,
        '_option_menu':"选项(&O)",
        '_layout_menu': "布局(&L)",
        'Open Layout':'打开布局',
        '_help_menu':"帮助(&H)",
        '_index_menu':"主页(&I)",
        '_function_path':'路径&&参数',
        '_repeat':'重复模式',
        '_repeat_enter':'进入重复模式，请输入数字',
        '_macro_record':'录制操作序列',
        '_macro_record_second':'录制Space操作序列',
        '_start_record':'开始录制 {0}, Ctrl+GeeKey结束录制',
        '_end_record':"{0} 的录制已经结束",
        '_autocomplete':'自动补全',
        '_autocomplete_on':'启动自动补全',
        '_autocomplete_off':'关闭自动补全',
        '_runasadmin':'程序启动时, 以管理员权限运行',
        '_key_swap_caution':'异常按键交换',
        '_key_swap_caution_content':'存在异常按键交换，程序可能会覆盖原有设置',
        "_new_version_available":"有可用新版本",
        "_new_version_detail":"        有更新版本的GlobalVim/GeeKey可用,点击更新到应用商店更新.        ",
        '_check_update':"""更新(&U)""",
        '_version_fine':'已经是最新版本',
        '_version_fine_detail':'当前版本已经是最新版本.',
        'OK':'确认',
        'Cancel':'取消',
        'Update':'更新',
        '_to_index':'查看主页',
        '_network_unavailable_detail':'GlobalVim/GeeKey连接服务器失败,您可以尝试点击下面按钮访问主页检查是否有更新.',
        '_network_unavailable':'网络不可用',
        '_command_not_found':'未知命令 {0}',
        'Unknown command':'未知命令',
        '_startvim':'程序启动时, 开启 vim 模式',
        'Geekey Enabled':'启用GeeKey',
        'Enable GeeKey HotKey system':'启用GeeKey热键系统',
        '_print_key_event':'打印键盘事件到日志窗口',
        '_start_autocomplete':'程序启动时,启用自动补全',
        'visual':'可视',
        'insert':'插入',
        'normal':'常规',
        'vim enabled':'vim 已启用',
        'vim disabled':'vim 已退出',
        'Command failed':'命令错误',
        'Command not processed':'命令未处理',
        'Key {0} set to type {1}':'按键 {0} 被设置为类型 {1}',
        """Double click to hide this log window.""": """双击隐藏此日志窗口.""",
        'value for {0} of type {1} set to:\n{2}':"{0} 被设为类型 {1} 且值为:\n{2}",
        "Keytype for key {0} not set. Try delete default.ini to fix":"{0} 的按键类型未设置, 请尝试删除 default.ini 来修复问题.",
        "Check update failed for: {0}":'更新检查错误: {0}',
        "config file {0} does not exists":"配置文件 {0} 不存在",
        "Load config error for: {0} \nTry delete default.ini to fix.":"加载配置文件错误: {0}\n请尝试删除default.ini来修复问题.",
        "Save config error for: {0}":"保存配置错误: {0}",
        'cmd "{0}" processed by self-defined macro':"命令 {0} 被自定义宏 处理",
        'nothing in register {0}':'寄存器 {0} 中没有内容',
        "command {0} not found.":"命令 {0} 未找到",
        'executing {0}':'执行 {0}',
        'executing {0} failed':'{0} 执行失败',
        'evaluation failed for: {0}':'求值失败: {0}',
        "recording {0} end":"{0} 录制结束",
        'Registers':'寄存器',
        'save':'保存',
        'save done':'保存完成',
        "recording ":"录制 ",
        "command {0} not found. You can bind your own operation to vim_cmd_map_{0} item in default.ini":"命令 {0} 未找到. 您可以将操作内容绑定到default.ini中的vim_cmd_map_{0}项",
        '':'',
    }
    lang_dict['en']={
        '_start_autocomplete':'Enable Auto Complete when startup',
        '_print_key_event':'Print keyboard event to Log window',
        '_startvim':'Start up wiith vim mode enabled.',
        '_to_index':'Check on HomePage',
        '_network_unavailable_detail':'GlobalVim/GeeKey failed to connect to the server. You can try check whether new version available from homepage by click button below.',
        '_network_unavailable':'Network Unavailable',
        '_notice':'Notice',
        'OK':'OK',
        'Cancel':'Cancel',
        'Update':'Update',
        '_version_fine_detail':'The current application is already the newest version.',
        '_version_fine':'Already the newest version',
        "_new_version_available":"New Version Available",
        '_new_version_detail':"        There is a new version of GlobalVim/GeeKey available there. Click 'update' to visit App Store.        ",
        '_key_swap_caution_content':'There is abnormal key swap which may be overriden',
        '_key_swap_caution':'Abnormal Key Swap',
        '_autocomplete':'Auto Complete',
        '_autocomplete_on':'Auto Complete On',
        '_autocomplete_off':'Auto Complete Off',
        '_runasadmin':'Run as Administor when startup',
        '_macro_record':'Record Operation Sequence',
        '_macro_record_second':'Record Spacing Operation Sequence',
        '_start_record':'Start Recroding {0}; Ctrl+GeeKey to Stop',
        '_end_record':"Recording for {0} Ended",
        '_repeat':'Repeat Mode',
        '_repeat_enter':'Enter Repeat Mode; Please input a Numberr',
        '_function_path':'Path&&Arguments',
        '_help_menu': "&Help",
        '_index_menu':"&Index",
        '_layout_menu': "&Layout" ,
        '_option_menu':"&Options",
        '_about_menu':"&About",
        '_tutorial_menu':"&Manual",
        '_save_menu':"&Save\tCtrl+Shift+S",
        '_saveas_menu':"&Save To File\tCtrl+S",
        '_loadfrom_menu':"&Load From\tCtrl+L",
        '_exit_menu':"&Exit",
        '_configure_menu':'&Configure\tCtrl+C',
        '_about':'About GlobalVim/GeeKey',
        '_account':'Eva Account',
        '_general':'General',
        '_language':'Language',
        '_configure':'Configure',
        '_startup':'Run when PC boots',
        '_startshow':'Show main panel when application startup',
        '_doubleclickfix':'Fix mouse double click error of hardware',
        '_layout':'Keyboard Layout {0}',
        '_restart_to_function':'Only after reboot the change can take effect',
        '_reboot_to_function':'Only after reboot the change can take effect',
        '_title_this':'GlobalVim/GeeKey',
        '_name':'Name',
        '_email':'Email',
        '_apply':'Apply',
        '_hotkey':'Hotkey',
        '_operation':'Operation',
        '_warning':'Warning',
        '_help':'Help',
        '_quit':'Quit',
        '_check_update':'Check &Update',
        '_about_message':"""Thank you for using GlobalVim/GeeKey! \nSuggestions are welcomed to improve this tool.\nAny questions please contact einsxiao@hotmail.com""",
        '_startup_with_system':'Startup with System',
        '_text_to_key':"Text of '{0}'",
        '_function_to_key':"Command bound to '{0}'",
        '_macro_to_key':"Operation sequence recorded bound to '{0}'",
        '_macro_to_key_text':"'Ctrl+GeeKey+{0}' to start recording operation; Ctrl+GeeKey to stop.",
        '_support_tooltip_wechat':'Scan QR code with WeChat to support. Click to show the log.',
        '_previous':'Prior',
        '_next':'Next',
        '_more':'More',
        '_text_color_info':'Keys to insert text bound.',
        '_edit_color_info':'Quick Keys to act like the specific key bound.',
        '_macro_color_info':'Macro Keys to replay all keyboard and mouse actions recorded.',
        '_function_color_info':'Application Keys will launch the bound application immediately.',
        '_not_run_as_admin':'Please restart as Admin to make current key change.',
        '_tip_for_geekey':'GeeKey+X     -exceute binding of X\nGeeKey+Space X     -exceute spacing binding of X{0}',
        '_tip_for_space':'GeeKey+Space X     -execute spacing binding of X\nGeeKey+Space N X     -execute X for N times\nGeeKey+Space Space     -raise and active main panel\n',
        '_tip_for_tab':'GeeKey+Space Tab     -Enable/Disable auto-complete\n',
        '_tip_for_v':'GeeKey+v  :Enter/Exit vim mode\n',
        '_tip_for_q':'GeeKey+q X     -start recording binding macro of X\nGeeKey+q Space X     -start recording spacing binding macro of X\nGeeKey+q     -end current recording\n',
        '':'',
    }
    lang_config = 'zh' ;
    def lang(self,term,*args,**kwargs):
        try:
            text = term
            if term in self.lang_dict[ self.lang_config ]:
                text = self.lang_dict[ self.lang_config ][ term ];
            elif term in self.lang_dict['en']:
                text = self.lang_dict['en'][ term ]
            else: text = term
            text = text.format( *args, **kwargs )
        except Exception as e:
            #print('lang error for:',e)
            pass
        return text

    def set_language(self,lan):
        if lan in ('English','en','en_US'):
            self.lang_config = 'en'
        else:
            self.lang_config = 'zh'
        pass

    def add_lang(self,lan,dic):
        if lan in self.lang_dict:
            self.lang_dict[lan].update(dic)
        else:
            self.lang_dict['en'].update(dic)
            pass
        pass
    pass

