Skip to content

Commit

Permalink
[Mod] update i18n document
Browse files Browse the repository at this point in the history
  • Loading branch information
vnpy committed Mar 5, 2024
1 parent 424e5fa commit 496eee0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion docs/community/app/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@
portfolio_manager.md
excel_rtd.md
web_trader.md
i18n.md
25 changes: 10 additions & 15 deletions docs/community/info/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ output(_("参数优化空间:{}").format(len(settings)))
在命令行中,调用python环境下Tools\i18n文件夹中的pygettext.py对模块所有python文件进行扫描,把所有标记过的字符都写入指定的pot模板文件,如以下代码所示:

```python
python "你的python环境路径"\Tools\i18n\pygettext.py -o vnpy/locale/vnpy.pot vnpy/trader/utilty.py
python "你的python环境路径"\Tools\i18n\pygettext.py -o vnpy\trader\locale\vnpy.pot vnpy\trader\*.py vnpy\trader\ui\*.py
```
其中“python”是python的软链接,-o后面是生成pot文件的路径,“vnpy/trader/utility.py”是扫描文件的相对路径单个示例

请注意:
- pot文件中标记的路径需要是基于locale文件夹的相对路径
- 可以通过代码```(gci vnpy -Recurse "*.py").Fullname```获取vnpy包的所有.py文件的绝对路径(再在生成的pot文件中对绝对路径统一处理)

其中-o后面是要生成的pot文件的路径,“vnpy\trader\*.py”是扫描指定文件夹下所有Python文件的示例。

## 创建po文件

Expand Down Expand Up @@ -61,9 +56,9 @@ msgstr "Range parameter added successfully, quantity {}"
在命令行中,调用python环境下Tools\i18n文件夹中的msgfmt.py将po文件转成二进制mo文件,如以下代码所示:

```python
python "你的python环境路径"\Tools\i18n\msgfmt.py -o vnpy/locale/en/LC_MESSAGES/vnpy.mo vnpy/locale/en/LC_MESSAGES/vnpy
python "你的python环境路径"\Tools\i18n\msgfmt.py -o vnpy\trader\locale\en\LC_MESSAGES\vnpy.mo vnpy\trader\locale\en\LC_MESSAGES\vnpy
```
其中“python”是python的软链接,-o后面是生成mo文件的路径,最后的是po文件的路径(无需后缀名)
其中-o后面是生成mo文件的路径,最后的是po文件的路径(无需后缀名)


## 打包
Expand Down Expand Up @@ -130,20 +125,20 @@ as unfortunately f-strings are not supported. One way to search for Chinese char
Once all the messages are marked, we run `xgettext` to extract the translatable strings into a message template file

```shell
xgettext -o vnpy/locale/base.pot `find ./vnpy -name "*.py"`
xgettext -o vnpy/trader/locale/base.pot `find ./vnpy -name "*.py"`
```

## individual language files

We then create individual language files, by copying the template. So for English and Spanish

```shell
mkdir -p vnpy/locale/{en, es}/LC_MESSAGES
cp vnpy/locale/vnpy.pot vnpy/locale/en/LC_MESSAGES/vnpy.po
cp vnpy/locale/vnpy.pot vnpy/locale/es/LC_MESSAGES/vnpy.po
mkdir -p vnpy/trader/locale/{en, es}/LC_MESSAGES
cp vnpy/trader/locale/vnpy.pot vnpy/trader/locale/en/LC_MESSAGES/vnpy.po
cp vnpy/trader/locale/vnpy.pot vnpy/trader/locale/es/LC_MESSAGES/vnpy.po
```

Then edit the .po files to add the translated text, updating the `msgstr` attributes. So for English (`vnpy/locale/en/LC_MESSAGES/vnpy.po`):
Then edit the .po files to add the translated text, updating the `msgstr` attributes. So for English (`vnpy/trader/locale/en/LC_MESSAGES/vnpy.po`):

```
#: vnpy/trader/optimize.py:45
Expand Down Expand Up @@ -179,7 +174,7 @@ Quality of the automatic translation services is variable, and not always free.
The plain text languages files (*.po) must be converted into the binary format (.mo) used at runtime. This would be normally done at the build stage. But to do it manually during development or testing:

```shell
msgfmt -o vnpy/locale/en/LC_MESSAGES/vnpy.mo vnpy/locale/en/LC_MESSAGES/vnpy
msgfmt -o vnpy/trader/locale/en/LC_MESSAGES/vnpy.mo vnpy/trader/locale/en/LC_MESSAGES/vnpy
```

## install
Expand Down
3 changes: 2 additions & 1 deletion docs/community/info/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
database.md
datafeed.md
pycharm.md
contribution.md
contribution.md
i18n.md

0 comments on commit 496eee0

Please sign in to comment.