From c148ad54cf99d3347076a3c3caa01cb3013f3512 Mon Sep 17 00:00:00 2001 From: OverflowCat Date: Thu, 17 Aug 2023 03:17:56 +0800 Subject: [PATCH] feat(i18n): detect system language --- README.md | 6 +++++- biliarchiver/i18n.py | 7 ++++++- biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7e143bb..1a7fb3b 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ Please use poetry to install dependencies: poetry install ``` +Build English locale if necessary. Refer to the last section for details. + ### Run ```sh @@ -59,6 +61,8 @@ poetry run ruff check . ### i18n +To generate and build locales, you need a GNU gettext compatible toolchain. You can install `mingw` and use `sh` to enter a bash shell on Windows. + Generate `biliarchiver.pot`: ```sh @@ -77,7 +81,7 @@ Update a language: pnpx gpt-po sync --po biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po --pot biliarchiver/locales/biliarchiver.pot ``` -Build a language: +**(Important)** Build a language: ```sh msgfmt biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po -o biliarchiver/locales/en/LC_MESSAGES/biliarchiver.mo diff --git a/biliarchiver/i18n.py b/biliarchiver/i18n.py index 3201b05..5cb9031 100644 --- a/biliarchiver/i18n.py +++ b/biliarchiver/i18n.py @@ -1,9 +1,14 @@ import gettext +import locale + +default_lang, default_enc = locale.getdefaultlocale() + +languages = ["en"] if default_lang.startswith("en") else ["zh_CN"] appname = "biliarchiver" i18n = gettext.translation( - appname, localedir="biliarchiver/locales", fallback=True, languages=["en"] + appname, localedir="biliarchiver/locales", fallback=True, languages=languages ) _ = i18n.gettext diff --git a/biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po b/biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po index ccde1e6..58fe4e5 100644 --- a/biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po +++ b/biliarchiver/locales/en/LC_MESSAGES/biliarchiver.po @@ -2,7 +2,7 @@ # Copyright (C) 2023 THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # Neko , 2023. -# +# msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" @@ -280,8 +280,8 @@ msgstr "Batch fetching BV numbers" #: biliarchiver/cli_tools/get_command.py:307 msgid "请通过 flag 指定至少一种批量获取 BV 号的方式。多个不同组的 flag 同时使用时,将会先后通过不同方式获取。" msgstr "" -"Please specify at least one way to batch fetch BV numbers through the flag. When multiple group flags are used " -"simultaneously, they will be fetched in sequence." +"Please specify at least one way to batch fetch BV numbers through the flag." +"When flags of multiple groups are used together, they will be fetched in sequence." #: biliarchiver/cli_tools/get_command.py:309 msgid "合集"