Description:
A small library to query for localized strings in a database by string token (such as the keys from
/tf/resource/tf_english.txt).
Localizations are read from the game's
/resource directory through a Python script and stored in an SQLite database. Kind of similar to TF2 Item DB. You'll want to run the script every now and then to keep the translations fresh.
Originally, I wasn't going to finish working on this (I've had the Python script for what feels like
forever), but I've been working on a plugin that reads certain usermessages that would need colorization as of late.
And someone mentioned Sourcemod being unable to access these translations.
If you're only interested in sending localized messages (i.e., not interested in getting the localized string to manipulate it), you're probably better off with
Powerlord's PrintValveTranslation stocks, which also supports formatting and doesn't need to keep an SQLite database up to date.
Installation:
- Install localization_server.smx as you would any other plugin.
- Add localization strings.
- If using TF2 (and if you only care about very outdated TF2 localizations):
- Download and unpack the language-db.7z file available here to addons/sourcemod/data/sqlite
(Note: That database does not get updates.)
- If trying to use strings other than those under /tf/resources (manual generation):
- Install the vdf library.
- Modify the Python script (utilities/localization_db.py) as needed to point to your game directory, language files, and Sourcemod installation, then run. Requires Python 3. I assume the language files are structured in the same way as TF2's; I can't test them myself.
Things this plugin might clobber:
I've only ever tested English strings so far, if that tells you anything.
Usage:
The plugin currently provides two non-threaded "resolve" natives and one threaded "get" native (and associated callback).
Documentation is provided in the include.
(Note: do not include the "#" symbol in the token.)
Sample usage is available as the
localization_test plugin.
Version History:
- 0.6.0 Added ResolveAllLocalizedStrings, which returns a StringMap containing all localized versions of the specified token. Non-threaded. Should make it easier for those that want to print multiple messages in one go.
- Also updated the script to support Russian, Thai, and Bulgarian. Wonder if there's a good way to get a list of supported languages so I don't have to update it by hand.
- Also, the script uses Python 3 syntax.
- 0.5.1 Made the native callback fail more gracefully (a failed threaded query now passes an empty string to the callback instead of just throwing a native error), so any data handles can be closed. Forgot to commit this; it's been a while. (How did this get 22 downloads? Nobody's commented or anything.)
- 0.4.0 The GetLocalizedString function actually uses threaded queries now!
- 0.3.0 Initial plugin release.
Source code and include files on Github.