Skip to content

Commit

Permalink
create file config i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasferreiralimax committed Jun 24, 2024
1 parent 795cd95 commit 301a21a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gitman/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import i18n
import platform
import subprocess

def i18nConfig():
# Obter informações do sistema
system_info = platform.system()

if system_info == 'Windows':
# Para Windows, usando o módulo winreg para obter o idioma
import winreg

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Control Panel\\International", 0, winreg.KEY_READ)
system_lang, _ = winreg.QueryValueEx(key, "LocaleName")
winreg.CloseKey(key)

elif system_info == 'Darwin':
# Para macOS, usando o comando 'defaults' para obter o idioma
proc = subprocess.Popen(['defaults', 'read', '-g', 'AppleLocale'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = proc.communicate()
system_lang = out.strip().decode('utf-8')

else:
# Para Linux e outros sistemas baseados em Unix, usando 'locale' para obter o idioma
proc = subprocess.Popen(['locale'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = proc.communicate()
system_lang = out.split()[0].decode('utf-8').split('=')[1]

if system_lang:
system_lang = system_lang[:2]

i18n.load_path.append('gitman/translations')
i18n.set('fallback', 'en')
i18n.set('locale', system_lang)

0 comments on commit 301a21a

Please sign in to comment.