Closed Blueberryy closed 4 years ago
Can't you just add a custom localisation file for your language?
If you can give me documentation how to do that then sure
I will need to document that stuff on the wiki I guess.
I can't find a wiki page for it (never mind it seems a wiki page is being created :P), but it's relatively simple so I'll try summarise it below.
Localisation files define translations to any language using standard English strings, they are placed in /garrysmod/resource/localization/locale/name.properties
(where locale
is a 2-4 letter locale language code, and name
is a simple name for whatever you're making the localisations for). Garry's Mod itself includes dozens of localisation files which provide translations for most, if not all vanilla aspects of the game. You can view them here (the online repository only includes English, but you can find all the other languages within your Garry's Mod installation in the same folder). I recommend looking through these default ones so you can get a grasp of how they're structured.
To create your own localisation file, create a folder (if it doesn't already exist) in /garrysmod/resource/localization/locale/
with the name of the locale you're creating it for (for example, en
for English, fr
for French, etc). Next, create a file within that newly created folder with a simple name referencing whatever it is you're making the localisation file for, this can be anything, but the file extension must be .properties
(for example, mycooladdon.properties
). Open this file up in a text editor to start creating your translations, they follow a key-value pair structure where the key is the name of the localisation string and the value is the translation in the language you're creating it for (for example mycooladdon.help=This is a help message!
. These localisation files should also be added to the resource download queue so that clients joining servers will receive the translations (I don't know if this is automatically done by the game itself).
Hopefully this quickly sums it up, if you've got any other questions then it's probably best to ask them on the official Garry's Mod Discord where you can get support.
I will try man. Thanks
Oh it works!
Рубака, thanks for creating extra documentation for that
Why not a 3rd argument for language.Add to specify language? Now the addons have to ship those files in order for their language to work.
Now the addons have to ship those files in order for their language to work.
That's the way it's supposed to be done though? As the wiki now states:
languge.Add will add a localization string for the currently selected language. This is mainly used as a developer tool or when your addon only has 1 language. This method not suitable for multiple languages and changing language will reset all strings added by this function.
Write your own language system in Lua anyway.
It could work for multiple languages though since that's essentially what the properties files are doing.
Now the addons have to ship those files in order for their language to work.
As opposed to shipping the same content, but in a Lua file while at the same time taking up more space?
It could work for multiple languages though since that's essentially what the properties files are doing.
It couldn't. There's no internal registry for each language, only the active language is loaded in memory.
It couldn't. There's no internal registry for each language, only the active language is loaded in memory.
Only language.Add with 3rd argument matching current language (default en) would run. Though I guess it would not work with switching language in-game.
Custom .properties files needs to be added in files through resource.AddWorkshop so people can acquire them?
resource.AddSingleFile()
is what you're looking for to make players download them. (However as I stated earlier, I don't know if the game automatically adds all files in resource/localization/*
to the download queue, someone else will need to confirm this.)
Example:
resource.AddSingleFile( "resource/localization/en/mycooladdon.properties" )
(If you want to use the workshop still, then of course as with every resource you can upload it to the workshop then make connecting players download that addon via resource.AddWorkshop()
.)
Is there a way to get the current language? Probably a convar I imagine.
We could just do
if currentLang=="ru" then
language.Add("whatever","'russian'")
else
language.Add("whatever","english")
end
gmod_language is that convar, but using language.Add is still flawed since you would have to update all your custom strings every time the user changes their language in-game since only one language is loaded at a time. Also, custom properties files won't really work and aren't currently on the resource or workshop whitelists. Best to make your own custom translation systems in Lua - they're pretty easy to implement as a HashTable<Language, HashTable<Key, Value>>
.
Also, custom properties files won't really work and aren't currently on the resource or workshop whitelists.
To load custom properties files from legacy addons installed manually on the client.
.properties files are most definitely allowed on workshop.
Sadly but language.Add string works only for English. Would be helpful to translate mod tools for other languages if you will improve this string with something like that.