简体   繁体   中英

Translating strings that are outside of the range of gettext

I'm implementing get text on my Discord bot and I have a few strings that come from configuration files for example: Regions where the game is from (Global server, Korean server, Japanese server, Asia server, etc.) that I want to also be translated into. Since these files are stored as JSON, I can't really use get text on them.

So I was wondering what can I do to get these strings translated? I came up with a few approaches that would solve my problem but they don't look that nice to me.

Method 1 - Use .py files for these settings

This one is self explanatory. I can use python modules to store the configuration for that, which would allow me to use the _(...) get text function which would allow xgettext to pick up the strings to be translated.

Method 2 - Hard code the strings

This would come in two ways, hardcoding them inside the module they're going to be used on or in a module where I would hard code all the strings that come from external data sources.

Is there any better approach to tackle this?

Extract the strings from the configuration files into an additional .pot file like config.pot . You can then pass this file as an additional input file to xgettext because xgettext will always recognize .po or .pot files as input regardless of the programming language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM