Raised This Month: $81 Target: $400

[ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases

Post New Thread Reply   
Thread Tools Display Modes
Author Message
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 09-29-2022 , 05:01   [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #1

What is it?
Most source games use own internal set of translation phrases for ~ 30 languages, located in "resource" folder as plain .txt files (as unpacked / in VPK / or both).

However, you cannot use them directly via SM.

Now, you can!

I'm presenting "Localizer" methodmap designed in a single .inc with well-familiar functions, which you are already know ("overridden" in a way allowing to accept #phrase in arbitrary text position).

Why may I need it?

Just a little real case:
Let's imagine you have L4D plugin with phrase "Easy" (difficulty) and you want to have multiple translations for that phrase.
Instead of asking people to translate it into as many languages as possible, you can find out that a game already has all translations for it in form of "#L4D_DifficultyEasy" phrase, so, you can just use it directly, like this: loc.PrintToChat(client, "#L4D_DifficultyEasy");

This is also especially useful for map names and weapons.

What's inside?

List of methods

PHP Code:
// Lists plugin names that using Localizer API, show API version and installation mode

Quick Start

How to add in your plugin?

Minimal sample:
PHP Code:
#include <localizer>

Localizer loc;

void OnPluginStart()
loc = new Localizer(); // this is always required!

Download localizer.inc here.

How to use?

Localizer methodmap "redefines" well-familiar functions, like PrintToChat(), Format() e.t.c., allowing you to specify #phrase in format buffer argument in an arbitrary place!



Note: first installation can take up 10-30 sec. (refer to "Cautions" section for details)
To check is Localizer ready, you can use Localizer.IsReady() or notifier (see later).

How to see/find ALL phrases?
- such way, to know, what is available for using...

There are 2 ways:

1) You can dump them with loc.DumpAll() method.
Resulting files are located in "addons/sourcemod/translations/localizer.phrases.txt" (+ each language subfolder),
and they are also compatible with SM's LoadTranslations(), so you have many ways to use it.

2) You can manually see phrases, searching .txt files in "resource" folders. However, it's not a preferred way, because game has multiple "resource" folders, including those bundled in VPK archives.

Naming convention:
- Phrase should always be started from # character.
- It is case sensitive.
- Any character can be prepended to the left side of #phrase (e.g. c#phrase)
- Any* special character can be appended to the end of #phrase (e.g.: #phrase^ #phrase, #phrase$)
- *with one exception: if the special character is one of ".-", the next character should NOT be an alpha-numeric (e.g.: #phrase-a is not correct)

Note 1: don't try to get translation in OnPluginStart(), since it require some time to initialize (10 - 30 sec. at first database re-build, and < 2 sec. next times).

Instead, if you need to access translation as fast as possible, you can register a notification callback function, which is called when localizer is ready to serve you.


Note 2: Localizer is not yet well tested.

Also, it is not fully finished (since the war in Ukraine, perhaps, will never be finished).
TF2 is likely not supported due to performance issues in Valve FS. Required integration of VPK_API (raw reader) written by Silvers.
I would be glad to have performance reports from CSGO / TF2 games on slow (non-SSD) servers.
To make such log, run the plugin: performance-test.sp
Then, retrieve a report from from the server console.

Installation methods (for advanced):


Details on internal implementation (for experts only):

  • L4D1
  • L4D2
  • CS:GO
  • TF2 (not supported due to performance issues, however, you may try)

- SM 1.10+
- SQLite Extension (included in SourceMod)
- Make sure, you have a correct file: addons/sourcemod/cfg/languages.cfg (from one of SM 1.10+ packages)
- Make sure, you have correct default database settings in: addons/sourcemod/cfg/databases.cfg (which is coming with SourceMod)

Source Code:

Available at GitHub.

- Externet - for the most amazing IDE BasicPawn and its excellent support, which has greatly simplified the development of this include.
- Wend4r and KyleSanderson - for suggesting walkaround against IDatabase leak while too many single threaded queries are queued - #1505.
- asherkin - for explaining multiple DB result sets (no, they aren't used here), influencing on correct Lock/Unlock usage.
- R1KO & CrazyHackGUT - for the manual and comments on various database stuff.
- SourceMod dev. team - for nice documentation, partially used here.

Q: Why the first run takes a much time?
A: At the first run, the installation process is performed. Next run will take < 1 sec.

Q: Ok, but why so long on HDD Drive?
A: 95% of the time had waste solely on resources disk read operation and database disk write operation. I can't do anything to improve it.

Good luck and have an easy usage!
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-02-2022 at 10:39.
Dragokas is offline
Junior Member
Join Date: Jan 2022
Old 10-01-2022 , 12:07   Re: [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #2

Good stuff.
morzlee is offline
Join Date: Jul 2020
Old 10-02-2022 , 01:26   Re: [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #3

Nice job!
yuzumi is offline
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-20-2022 , 21:36   Re: [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #4


Bacardi is offline

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 14:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode