-
Notifications
You must be signed in to change notification settings - Fork 12
Languages
The gPhone uses a custom system similar to Trouble in Terrorist Town's to handle multiple languages, the language is stored as a table of strings and has multiple functions to deal with it. This allows for the base phone and 3rd party apps to appeal to a wider audience of Garry's Mod players.
This is about as simple as it gets and you can check the default languages to see how its done. You simply call a function with the string name and it will return the table that you add indexes to. The language name is case-insensitive
local l = gPhone.createLanguage( "spanish" )
l.hello = "Hola"
The language file cannot account for every single phrase, especially 3rd party applications, so there is a function available to add your own.
gPhone.addTranslation( id, phrase, language )
You need the first and second arguments, key and value respectively, but the language will default to english if not declared. It also returns the phrase so you can use it where you declare it. Here is an example:
title:SetText( gPhone.addTranslation( "myapp_title1", "My App", "english") )
Or
local challenge = gPhone.addTranslation( "myapp_challenge", "Challenge", "english")
button:SetText(challenge)
If you see text that looks like this '#airplane_mode' then you know your language file is incomplete and needs to be updated. The pound sign is simply there to help show that this is supposed to be a translated word and not actually what is supposed to be there.
The solution to that is simply to add 'airplane_mode' to your language file with the proper translation from the English version. You can also get all the translations that yours is missing with this helpful function:
gPhone.getMissingTranslations( lang, bFormatted )
You simply type the name of the language you are fixing and an optional boolean (true returns code, false returns the keys and phrases) and it will return a table of all values present in the English translation but not yours.