Skip to content

Commit

Permalink
fix(lang): fix language setting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Apr 21, 2024
1 parent 4c81572 commit 7449a02
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/retk/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def startup_event():
logger.debug(f'startup_event RETHINK_LOCAL_STORAGE_PATH: {os.environ.get("RETHINK_LOCAL_STORAGE_PATH")}')
logger.debug(f'startup_event VUE_APP_MODE: {os.environ.get("VUE_APP_MODE")}')
logger.debug(f'startup_event VUE_APP_API_PORT: {os.environ.get("VUE_APP_API_PORT")}')
logger.debug(f'startup_event VUE_APP_LANGUAGE: {os.environ.get("VUE_APP_LANGUAGE")}')
logger.debug(f'startup_event RETHINK_DEFAULT_LANGUAGE: {os.environ.get("RETHINK_DEFAULT_LANGUAGE")}')
await client.init()
logger.debug("db initialized")

Expand Down
4 changes: 2 additions & 2 deletions src/retk/dist-local/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ em.match {
width: 100%;
height: 100%;
-webkit-backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
z-index: 1000;
display: flex;
justify-content: center;
Expand Down Expand Up @@ -3921,7 +3921,7 @@ img[data-v-4f42ee16] {
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
-webkit-backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
z-index: 9;
}
.popup[data-v-68a8b995] {
Expand Down
6 changes: 3 additions & 3 deletions src/retk/dist-local/js/app.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/retk/models/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ async def init(self):
if config.is_local_db():
await self.local_try_create_or_restore()

# set default language
default_language = os.getenv("RETHINK_DEFAULT_LANGUAGE", None)
if default_language is not None:
await self.coll.users.update_one(
{"account": const.DEFAULT_USER["email"], "source": const.UserSource.LOCAL.value},
{"$set": {"settings.language": default_language}},
)

else:
# self.mongo.get_io_loop = asyncio.get_running_loop
await remote_try_build_index(self.coll)
Expand Down Expand Up @@ -87,7 +95,7 @@ async def drop(self):
await self.mongo.drop_database(config.get_settings().DB_NAME)

async def local_try_add_default_user(self):
_v = version_manager.recover.dump_dot_rethink(
_v = version_manager.recover.dump_default_dot_rethink(
path=config.get_settings().RETHINK_LOCAL_STORAGE_PATH / ".data" / ".rethink.json"
)

Expand Down Expand Up @@ -204,7 +212,7 @@ async def local_try_create_or_restore(self): # noqa: C901
await self._local_restore()
return

# try fix TypeError: can't compare offset-naive and offset-aware datetimes
# try fix TypeError: can't compare offset-naive and offset-aware datetime
docs = self.coll.nodes.find()
for doc in await docs.to_list(length=None):
await self.coll.nodes.update_one(
Expand Down Expand Up @@ -254,7 +262,7 @@ async def _local_restore(self):
last_state_node_display_method=const.NodeDisplayMethod.CARD.value,
last_state_node_display_sort_key="modifiedAt",

settings_language=v_settings.get("language", os.getenv("VUE_APP_LANGUAGE", const.Language.EN.value)),
settings_language=v_settings.get("language", const.Language.EN.value),
settings_theme=v_settings.get("theme", const.AppTheme.LIGHT.value),
settings_editor_mode=v_settings.get("editorMode", const.EditorMode.WYSIWYG.value),
settings_editor_font_size=v_settings.get("editorFontSize", 15),
Expand Down
16 changes: 8 additions & 8 deletions src/retk/routes/self_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ async def shutdown_event():


@router.get("/sauth", response_class=HTMLResponse)
@router.get("/docs", response_class=HTMLResponse)
@router.get("/login", response_class=HTMLResponse)
@router.get("/about", response_class=HTMLResponse)
@router.get("/r", response_class=HTMLResponse)
@router.get("/r/{path}", response_class=HTMLResponse)
@router.get("/r/plugin/{pid}", response_class=HTMLResponse)
@router.get("/n/{nid}", response_class=HTMLResponse)
async def app_page() -> HTMLResponse:
content = (const.FRONTEND_DIR / "index.html").read_text(encoding="utf-8")
script = f"window.VUE_APP_API_PORT={os.getenv('VUE_APP_API_PORT')};"
language = os.getenv("RETHINK_DEFAULT_LANGUAGE")
if language is not None:
script += f"window.VUE_APP_LANGUAGE='{language}';"
if os.getenv("RETHINK_SERVER_PASSWORD", None) is not None:
req_password = "window.VUE_APP_ONE_USER_REQUIRE_AUTH=1;"
else:
req_password = ""
content += f"<script>window.VUE_APP_API_PORT={os.getenv('VUE_APP_API_PORT')};" \
f"{req_password}</script>"
script += "window.VUE_APP_ONE_USER_REQUIRE_AUTH=1;"
script = f"<script>{script}</script>"

return HTMLResponse(
content=content,
content=content + script,
status_code=200,
)

Expand Down
2 changes: 1 addition & 1 deletion src/retk/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def run(
raise NotADirectoryError(f"Path is not a directory: {path}")
os.environ["VUE_APP_API_PORT"] = str(port)
os.environ["VUE_APP_MODE"] = "local"
os.environ["VUE_APP_LANGUAGE"] = language
os.environ["RETHINK_DEFAULT_LANGUAGE"] = language
os.environ["RETHINK_LOCAL_STORAGE_PATH"] = str(path)
os.environ["RETHINK_SERVER_HEADLESS"] = "1" if headless else "0"
os.environ["RETHINK_SERVER_HOSTNAME"] = host
Expand Down
4 changes: 2 additions & 2 deletions src/retk/version_manager/recover.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from retk._version import __version__


def dump_dot_rethink(path: Union[os.PathLike, Path]) -> Dict:
def dump_default_dot_rethink(path: Union[os.PathLike, Path]) -> Dict:
version = {
"version": __version__,
"_id": ObjectId(),
Expand All @@ -19,7 +19,7 @@ def dump_dot_rethink(path: Union[os.PathLike, Path]) -> Dict:
"avatar": const.DEFAULT_USER["avatar"],
"account": const.DEFAULT_USER["email"],
"settings": {
"language": os.getenv("VUE_APP_LANGUAGE", const.Language.EN.value),
"language": os.getenv("RETHINK_DEFAULT_LANGUAGE", const.Language.EN.value),
"theme": const.AppTheme.LIGHT.value,
"editorMode": const.EditorMode.WYSIWYG.value,
"editorFontSize": 15,
Expand Down
1 change: 0 additions & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def test_run(self, password=None):
for url in [
"",
"/login",
"/about",
"/sauth",
"/r",
"/r/settings",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_package_version(self):
self.assertEqual(3, len(vs_int))

def test_dump_load(self):
version_manager.recover.dump_dot_rethink(self.tmp_dir / ".rethink.json")
version_manager.recover.dump_default_dot_rethink(self.tmp_dir / ".rethink.json")

v = version_manager.recover.load_dot_rethink(self.tmp_dir / ".rethink.json")
self.assertIsNotNone(v)
Expand Down

0 comments on commit 7449a02

Please sign in to comment.