-
Notifications
You must be signed in to change notification settings - Fork 2
Adds English support #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
from tkinter import messagebox | ||
import pickle | ||
import os | ||
|
||
import settings | ||
from minesweeper.languages.language import text_messages | ||
|
||
class Auth: | ||
def __init__(self): | ||
|
@@ -11,6 +12,7 @@ def __init__(self): | |
self.current_user = None | ||
self.users = [] | ||
|
||
self.text_messages = text_messages | ||
try: | ||
with open(self.__path, 'rb') as f: | ||
self.users = pickle.load(f) | ||
|
@@ -33,7 +35,7 @@ def sign_in(self, login, password): | |
if password == 'admin': | ||
return 'admin' | ||
else: | ||
return 'Невірний пароль admin-а' | ||
return self.text_messages[settings.language.lower()].auth.sign_in.invalid_admin_password | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking strings directly from the array could be tricky because every time you need to write The better way is to create a class, that will automatically provide the string with the right language. But I think that this implementation would require more work and maybe additional libraries. If you want to do it simpler, you can do it this way: assign the |
||
|
||
user = next((user for user in self.users if user.login == login), None) | ||
|
||
|
@@ -43,9 +45,9 @@ def sign_in(self, login, password): | |
self.current_user = user | ||
return self.current_user | ||
else: | ||
return 'Невірний пароль' | ||
return self.text_messages[settings.language.lower()].auth.sign_in.invalid_password | ||
else: | ||
if messagebox.askyesno('Авторизація', 'Створити нового гравця: {}, з паролем: {}?'.format(login, password)): | ||
if messagebox.askyesno(self.text_messages[settings.language.lower()].auth.sign_in.authorization, '{}{}{}{}?'.format(self.text_messages[settings.language.lower()].auth.sign_in.create_new_player, login, self.text_messages[settings.language.lower()].auth.sign_in.with_password, password)): | ||
self.current_user = self.__new_user(login, password) | ||
return self.current_user | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
en = { | ||
'update_time': { | ||
'time': 'Time' | ||
}, | ||
'menu_widget': { | ||
'entrance': 'Entrance', | ||
'mine': 'Min' | ||
}, | ||
'update_flags': 'Remaining flags', | ||
'end_on_mine': 'LOSS', | ||
'end_on_success': 'VICTORY', | ||
'on_exit': 'Save game?', | ||
|
||
'leader_board': { | ||
'back': 'Back', | ||
'win': 'WIN', | ||
'loss': 'LOSS' | ||
}, | ||
'login_screen': { | ||
'setup': { | ||
'who_are_you': 'Who are you?', | ||
'login': 'Login: ', | ||
'password': 'Password: ', | ||
'login_register': 'Login / Register' | ||
}, | ||
'on_login_tap': { | ||
'authorization': 'Authorization', | ||
'empty_fields': 'Fields cannot be empty' | ||
} | ||
}, | ||
|
||
'home_scr': { | ||
'new_game': 'New game', | ||
'continue_btn': 'Continue', | ||
'table_of_result': 'Table of results', | ||
'entrance': 'Entrance' | ||
}, | ||
|
||
'auth': { | ||
'sign_in': { | ||
'invalid_admin_password': 'Invalid admin password', | ||
'invalid_password': 'Invalid password', | ||
'authorization': 'Authorization', | ||
'create_new_player': 'Create a new player: ', | ||
'with_password': ', with password: ' | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from types import SimpleNamespace | ||
from minesweeper.languages.ur import ur | ||
from minesweeper.languages.en import en | ||
|
||
class NestedNamespace(SimpleNamespace): | ||
def __init__(self, dictionary, **kwargs): | ||
super().__init__(**kwargs) | ||
for key, value in dictionary.items(): | ||
if isinstance(value, dict): | ||
self.__setattr__(key, NestedNamespace(value)) | ||
else: | ||
self.__setattr__(key, value) | ||
|
||
global text_messages | ||
text_messages = {} | ||
text_messages.update({"ur": NestedNamespace(ur)}) | ||
text_messages.update({"en": NestedNamespace(en)}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
ur = { | ||
'update_time': { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think that these "levels" are useful. Maybe, if sometime in the future, I would like to use the 'Час' outside the update_time widget and this groping would confuse me. I would do everything in a flat structure without any groups. |
||
'time': 'Час' | ||
}, | ||
'menu_widget': { | ||
'entrance': 'Вихід', | ||
'mine': 'Мін' | ||
}, | ||
'update_flags': 'Залишилося флагів', | ||
'end_on_mine': 'ПРОГРАШ', | ||
'end_on_success': 'ПЕРЕМОГА', | ||
'on_exit': 'Зберегти гру?', | ||
|
||
'leader_board': { | ||
'back': 'Назад', | ||
'win': 'ВИГРАВ', | ||
'loss': 'ПРОГРАВ' | ||
}, | ||
'login_screen': { | ||
'setup': { | ||
'who_are_you': 'Хто ти?', | ||
'login': 'Логін: ', | ||
'password': 'Пароль: ', | ||
'login_register': 'Увійти / Зареєструватися' | ||
}, | ||
'on_login_tap': { | ||
'authorization': 'Авторизація', | ||
'empty_fields': 'Поля не можуть бути порожніми' | ||
} | ||
}, | ||
|
||
'home_scr': { | ||
'new_game': 'Нова гра', | ||
'continue_btn': 'Продовижити', | ||
'table_of_result': 'Таблиця результатів', | ||
'entrance': 'Вихід' | ||
}, | ||
|
||
'auth': { | ||
'sign_in': { | ||
'invalid_admin_password': 'Невірний пароль admin-а', | ||
'invalid_password': 'Невірний пароль', | ||
'authorization': 'Авторизація', | ||
'create_new_player': 'Створити нового гравця: ', | ||
'with_password': ', з паролем: ' | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
language="en" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating this variable inside each class is useless if you can use it directly from import.