Facepunch / garrysmod-issues

Garry's Mod issue tracker
145 stars 56 forks source link

Make language.Add for specific language #4656

Closed Blueberryy closed 4 years ago

Blueberryy commented 4 years ago

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.

viral32111 commented 4 years ago

Can't you just add a custom localisation file for your language?

Blueberryy commented 4 years ago

If you can give me documentation how to do that then sure

robotboy655 commented 4 years ago

I will need to document that stuff on the wiki I guess.

viral32111 commented 4 years ago

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.

Blueberryy commented 4 years ago

I will try man. Thanks

Blueberryy commented 4 years ago

Oh it works!

robotboy655 commented 4 years ago

https://wiki.facepunch.com/gmod/Addon_Localization

Blueberryy commented 4 years ago

Рубака, thanks for creating extra documentation for that

thegrb93 commented 4 years ago

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.

viral32111 commented 4 years ago

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.

Kefta commented 4 years ago

Write your own language system in Lua anyway.

thegrb93 commented 4 years ago

It could work for multiple languages though since that's essentially what the properties files are doing.

robotboy655 commented 4 years ago

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.

thegrb93 commented 4 years ago

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.

Blueberryy commented 4 years ago

Custom .properties files needs to be added in files through resource.AddWorkshop so people can acquire them?

viral32111 commented 4 years ago

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().)

thegrb93 commented 4 years ago

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
Kefta commented 4 years ago

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

viral32111 commented 4 years ago

Also, custom properties files won't really work and aren't currently on the resource or workshop whitelists.

What's this for then?

Kefta commented 4 years ago

To load custom properties files from legacy addons installed manually on the client.

robotboy655 commented 4 years ago

.properties files are most definitely allowed on workshop.