feat(i18n): detect system language

This commit is contained in:
OverflowCat 2023-08-17 03:17:56 +08:00
parent 49901b15e6
commit c148ad54cf
3 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <overflowcat@gmail.com>, 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 "合集"