add shared configs system, use it for banner section
This commit is contained in:
3
configs/banner.ini
Normal file
3
configs/banner.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
[banner]
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS wurde zu GSoC 2026 angenommen!
|
||||
text = Informieren Sie sich über Programmdetails und unsere Projektideen
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS accepted to GSoC 2026!
|
||||
text = Check program details and our project ideas
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = ¡KolibriOS fue aceptado en GSoC 2026!
|
||||
text = Consulta los detalles del programa y nuestras ideas de proyecto
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS a été accepté au GSoC 2026 !
|
||||
text = Consultez les détails du programme et nos idées de projets
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS è stato accettato al GSoC 2026!
|
||||
text = Consulta i dettagli del programma e le nostre idee di progetto
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS is geaccepteerd voor GSoC 2026!
|
||||
text = Bekijk de programmadetails en onze projectideeën
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS принята в GSoC 2026!
|
||||
text = Ознакомьтесь с деталями программы и нашими идеями проектов
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS 已被 GSoC 2026 录取!
|
||||
text = 查看项目详情和我们的项目创意
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
@@ -17,8 +17,6 @@ git = Git
|
||||
[banner]
|
||||
header = KolibriOS 已入選 GSoC 2026!
|
||||
text = 查看計畫詳情和我們的專案構想
|
||||
url = https://summerofcode.withgoogle.com/programs/2026/organizations/kolibrios-project-team
|
||||
img = gsoc.png
|
||||
alt = GSoC
|
||||
|
||||
[article]
|
||||
|
||||
50
modules/configs.py
Normal file
50
modules/configs.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from os import path, listdir
|
||||
from configparser import ConfigParser
|
||||
import threading
|
||||
|
||||
|
||||
_configs = {}
|
||||
_loaded = False
|
||||
_load_lock = threading.Lock()
|
||||
|
||||
|
||||
def load_all_configs():
|
||||
new_configs = {}
|
||||
|
||||
configs_dir = "configs"
|
||||
if not path.isdir(configs_dir):
|
||||
return new_configs
|
||||
|
||||
for filename in sorted(listdir(configs_dir)):
|
||||
if not filename.endswith(".ini"):
|
||||
continue
|
||||
|
||||
file_path = path.join(configs_dir, filename)
|
||||
cp = ConfigParser()
|
||||
with open(file_path, encoding="utf-8") as f:
|
||||
cp.read_file(f)
|
||||
|
||||
for section in cp.sections():
|
||||
section_data = new_configs.setdefault(section, {})
|
||||
section_data.update(dict(cp[section]))
|
||||
|
||||
return new_configs
|
||||
|
||||
|
||||
def ensure_loaded():
|
||||
global _configs, _loaded
|
||||
with _load_lock:
|
||||
if _loaded:
|
||||
return
|
||||
_configs = load_all_configs()
|
||||
_loaded = True
|
||||
|
||||
|
||||
def get_section(name):
|
||||
ensure_loaded()
|
||||
return dict(_configs.get(name, {}))
|
||||
|
||||
|
||||
def get_all_sections():
|
||||
ensure_loaded()
|
||||
return {section: dict(values) for section, values in _configs.items()}
|
||||
@@ -2,6 +2,8 @@ from os import path, listdir
|
||||
from configparser import ConfigParser
|
||||
import threading
|
||||
|
||||
from modules import configs
|
||||
|
||||
|
||||
translations = {}
|
||||
locales_name = {}
|
||||
@@ -33,6 +35,13 @@ def load_all_locales():
|
||||
section: dict(cp[section]) for section in cp.sections()
|
||||
}
|
||||
|
||||
shared_sections = configs.get_all_sections()
|
||||
if shared_sections:
|
||||
for locale_translation in new_translations.values():
|
||||
for section_name, section_values in shared_sections.items():
|
||||
locale_section = locale_translation.setdefault(section_name, {})
|
||||
locale_section.update(section_values)
|
||||
|
||||
new_locales_code = locales_code_default + tuple(sorted(locales_code_extra))
|
||||
new_locales_name = {
|
||||
locale_code: new_translations[locale_code]["title"]["language"]
|
||||
|
||||
Reference in New Issue
Block a user