Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tuneit
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
tuneit
Commits
e3154b72
Commit
e3154b72
authored
2 months ago
by
Roman Alifanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
multilingual support in modules
parent
e56b697c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
22 deletions
+68
-22
main.py
src/settings/main.py
+56
-11
yml_tools.py
src/settings/tools/yml_tools.py
+12
-11
No files found.
src/settings/main.py
View file @
e3154b72
from
gi.repository
import
Adw
,
Gtk
import
os
import
gettext
import
locale
from
.backends
import
backend_factory
from
.daemon_client
import
dclient
...
...
@@ -13,20 +17,34 @@ from .widgets.service_dialog import ServiceNotStartedDialog
dialog_presented
=
False
class
Setting
:
def
__init__
(
self
,
setting_data
):
self
.
name
=
setting_data
[
'name'
]
def
__init__
(
self
,
setting_data
,
module
):
self
.
_
=
module
.
get_translation
self
.
name
=
self
.
_
(
setting_data
[
'name'
])
self
.
root
=
setting_data
.
get
(
'root'
,
False
)
self
.
backend
=
setting_data
.
get
(
'backend'
)
self
.
params
=
setting_data
.
get
(
'params'
,
{})
self
.
type
=
setting_data
[
'type'
]
self
.
help
=
setting_data
.
get
(
'help'
,
""
)
self
.
help
=
setting_data
.
get
(
'help'
,
None
)
if
self
.
help
is
not
None
:
self
.
help
=
self
.
_
(
self
.
help
)
self
.
key
=
setting_data
.
get
(
'key'
)
self
.
default
=
setting_data
.
get
(
'default'
)
self
.
gtype
=
setting_data
.
get
(
'gtype'
,
[])
self
.
map
=
setting_data
.
get
(
'map'
)
if
self
.
map
is
None
:
self
.
map
=
self
.
_default_map
()
self
.
data
=
setting_data
.
get
(
'data'
,
{})
if
isinstance
(
self
.
map
,
dict
)
and
self
.
type
==
'choice'
:
self
.
map
=
{
self
.
_
(
key
)
if
isinstance
(
key
,
str
)
else
key
:
value
for
key
,
value
in
self
.
map
.
items
()
}
if
len
(
self
.
gtype
)
>
2
:
self
.
gtype
=
self
.
gtype
[
0
]
...
...
@@ -124,30 +142,50 @@ class Setting:
print
(
f
"Бекенд {self.backend} не зарегистрирован."
)
return
backend
class
Module
:
def
__init__
(
self
,
module_data
):
self
.
name
=
module_data
[
'name'
]
self
.
weight
=
module_data
.
get
(
'weight'
,
0
)
self
.
path
=
module_data
.
get
(
"module_path"
)
print
(
self
.
path
)
self
.
pages
=
{
page
[
'name'
]:
page
for
page
in
module_data
.
get
(
'pages'
,
[])
}
self
.
sections
=
[]
self
.
system_lang_code
=
self
.
get_system_language
()
def
add_section
(
self
,
section
):
self
.
sections
.
append
(
section
)
def
get_sorted_sections
(
self
):
# Сортируем секции по весу
return
sorted
(
self
.
sections
,
key
=
lambda
s
:
s
.
weight
)
@staticmethod
def
get_system_language
():
lang
,
_
=
locale
.
getdefaultlocale
()
return
lang
.
split
(
'_'
)[
0
]
if
lang
else
'en'
def
get_translation
(
self
,
text
,
lang_code
=
None
):
if
text
.
startswith
(
'_'
):
text
=
text
[
1
:]
locales_path
=
os
.
path
.
join
(
self
.
path
,
"locale"
)
if
os
.
path
.
exists
(
locales_path
):
text
=
gettext
.
translation
(
domain
=
'messages'
,
localedir
=
locales_path
,
fallback
=
True
)
.
gettext
(
text
)
return
text
class
Section
:
def
__init__
(
self
,
section_data
,
strategy
,
module
):
self
.
name
=
section_data
[
'name'
]
self
.
name
=
module
.
get_translation
(
section_data
[
'name'
])
self
.
weight
=
section_data
.
get
(
'weight'
,
0
)
self
.
page
=
section_data
.
get
(
'page'
)
self
.
settings
=
[
Setting
(
s
)
for
s
in
section_data
.
get
(
'settings'
,
[])]
self
.
settings
=
[
Setting
(
s
,
module
)
for
s
in
section_data
.
get
(
'settings'
,
[])]
self
.
strategy
=
strategy
self
.
module
=
module
...
...
@@ -267,13 +305,20 @@ def init_settings_stack(stack, listbox, split_view):
modules_dict
[
module
.
name
]
=
module
for
section_data
in
module_data
.
get
(
'sections'
,
[]):
page_name
=
section_data
.
get
(
'page'
,
'Default'
)
page_name
=
module
.
get_translation
(
section_data
.
get
(
'page'
,
'Default'
))
module_page_name
=
section_data
.
get
(
'page'
,
'Default'
)
print
(
module_page_name
)
if
page_name
not
in
pages_dict
:
page_info
=
module
.
pages
.
get
(
page_name
,
{})
page_info
=
(
module
.
pages
.
get
(
f
"_{module_page_name}"
,
{})
or
module
.
pages
.
get
(
module_page_name
,
{})
)
page
=
Page
(
name
=
page_name
,
icon
=
page_info
.
get
(
'icon'
)
icon
=
page_info
.
get
(
'icon'
)
,
)
pages_dict
[
page_name
]
=
page
...
...
This diff is collapsed.
Click to expand it.
src/settings/tools/yml_tools.py
View file @
e3154b72
...
...
@@ -31,15 +31,16 @@ def load_modules():
def
load_yaml_files_from_directory
(
directory
):
yaml_data
=
[]
for
root
,
_
,
files
in
os
.
walk
(
directory
):
for
file
in
files
:
if
file
.
endswith
(
".yml"
)
or
file
.
endswith
(
".yaml"
):
file_path
=
os
.
path
.
join
(
root
,
file
)
with
open
(
file_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
try
:
data
=
yaml
.
safe_load
(
f
)
if
data
:
yaml_data
.
extend
(
data
)
except
yaml
.
YAMLError
as
e
:
print
(
f
"Ошибка при чтении файла {file_path}: {e}"
)
for
file
in
os
.
listdir
(
directory
):
if
file
.
endswith
(
".yml"
)
or
file
.
endswith
(
".yaml"
):
file_path
=
os
.
path
.
join
(
directory
,
file
)
with
open
(
file_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
try
:
data
=
yaml
.
safe_load
(
f
)
if
data
:
for
item
in
data
:
item
[
'module_path'
]
=
directory
yaml_data
.
extend
(
data
)
except
yaml
.
YAMLError
as
e
:
print
(
f
"Ошибка при чтении файла {file_path}: {e}"
)
return
yaml_data
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment