Raised This Month: $27 Target: $400
 6% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 09-29-2022 , 04: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
Spoiler

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

Quick Start

How to add in your plugin?
-------------------------

Minimal sample:
PHP Code:
#include <localizer>

Localizer loc;

public 
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!

Examples:

Spoiler



Note: first installation can take up 30 sec. to 5 minutes (refer to "Cautions" section for details). That's happened only once.
To check is Localizer ready, you can use Localizer.IsReady() or via notifier forward (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)


Cautions:
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.

Example:
Spoiler


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):

Spoiler



Details on internal implementation (for experts only):
Spoiler


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

Requirements:
- 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)

How to uninstall
- to uninstall completely, please, call loc.Uninstall() method
PHP Code:
#include <localizer>

public void OnPluginStart()
{
    
Localizer loc = new Localizer(LC_INSTALL_MODE_CUSTOM);
    
loc.Uninstall();

Or use can just delete folder {game}/resource/utf8, however this one will not erase database records.



Source Code:

Available at GitHub.


Credits:
- 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.

FAQ:
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; 03-27-2025 at 18:37.
Dragokas is offline
morzlee
Junior Member
Join Date: Jan 2022
Old 10-01-2022 , 11:07   Re: [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #2

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

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

nice.

https://forums.alliedmods.net/showpo...33&postcount=6
Bacardi is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 01-09-2025 , 19:39   Re: [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #5

Fix sm v1.12 compile warnings

PHP Code:
localizer.inc(498) : warning 203symbol is never used"file"
//    498 |         public bool PrecacheTranslationFile(char[] file, LC_CACHE cache = LC_CACHE_RAM)

localizer.inc(498) : warning 203symbol is never used"cache"
//    498 |         public bool PrecacheTranslationFile(char[] file, LC_CACHE cache = LC_CACHE_RAM)

localizer.inc(1075) : warning 204symbol is assigned a value that is never used"total_time"

localizer.inc(1136) : warning 204symbol is assigned a value that is never used"total_time" 
Attached Files
File Type: inc localizer.inc (60.5 KB, 60 views)
__________________
HarryPotter is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-27-2025 , 18:47   Re: [ANY] Localizer.inc | API | Using intrinsic Valve in-game translation #phrases
Reply With Quote #6

Updated.

Quote:
0.94
- Profiler is auto-enabled when the first installation occurs
- Display on server and chat the progress of installation per each file being parsed
- Fixed warnings in sm 1.12
e.g.
Code:
		PrintToServer(">>> [Localizer] Beginning transformation of language files...");
		PrintToServer(">>> [Localizer] It may freeze the server. Don't panic!");
		PrintToServer(">>> [Localizer] This is one-time procedure.");
and messages per each file while parsing > on server and chat, incl. when new addon map is installed.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply


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 22:17.


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