-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
795cd95
commit 301a21a
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |