Repository navigation
Lua Script API: Language Translation
Languages are a system of communication that consists of speech, manual (signed), or written symbols. In version 1.0 pre-release of Psych Engine, it added support for languages to make more accessible to people who don't speak English. It uses a lang file or a language localization file to translate words and phrases to different languages without doing it hard-coded.
Firstly make a lang file that is relative to: assets/shared/data or mods/data. You can name this file anything you want but I'd recommend using the language code format for organization. For instance: en-US for english in USA; en-CA for english in Cananda; and es for spanish. Again it's your choice if you want to use this format or not.
Note
If both or more language localization file has the same file name, for instance: pt_BR. The others will override the main language localization file, it doesn't require the entire list of key elements and title.
Now that you're done setting up the language localization file. It's time for the next part which is translating every word and phrases. The first line of the file should include the title for the given language, let's say as an example the language is LOLCAT. So basically the title will be: LOLCAT (US), bear in mind that the parenthesis is the country name shorten.
Example:
LOLCAT (US)
Lastly the content below the title should contain every key elements to translate. Basically they are elements on which text to translate, for instance: Pause Menus, Ratings, Achievements, and etc. There is already pre-existing list containing every key elements it can translate already at the pt-BR.lang file.
So simply copy and paste it, remove the key elements' text content, and replace it with the language you'll translate in. If you'd notice a number index surrounded by curly-braces {}. This where the missing value that will be inserted from the values argument derived at the getPhrase() in source-code or the getTranslationPhrase() function. You can also add custom key elements, if you want.
Example:
LOLCAT (US)
// Gameplay
score_text: "SKOR: {1} | MISEZ: {2} | RATEEZ: {3}"
score_text_instakill: "SKOR: {1} | RATEEZ: {2}"
botplay: "CHEATIN MODE"
Gets the key element from a language localization file or a lang file. If the key element isn't present inside the language localization file. It will return the receive key argument it recieves.
-
key- The key element from the language localization file.
Example:
LOLCAT (US)
// Gameplay
score_text: "SKOR: {1} | MISEZ: {2} | ACCURACY: {3}"
score_text_instakill: "SKOR: {1} | ACCURACY: {2}"
botplay: "CHEATIN MODE"
function onCreate()
debugPrint(getFileTranslation('botplay')) --> "CHEATIN MODE"
endGets the key element from a language localization file or a lang file. If the key element isn't present inside the language localization file. It will return from the defaultPhrase argument, if the argument is present.
-
key- The key element from the language localization file. -
defaultPhrase- An optional parameter, The default word or phrase if thekeyargument value isn't present. -
values- An optional parameter, The amount of values to each insert from a index. This depends if key element's content has an index present or not.
Example:
LOLCAT (US)
// Gameplay
score_text: "SKOR: {1} | MISEZ: {2} | RATEEZ: {3}"
score_text_instakill: "SKOR: {1} | RATEEZ: {2}"
botplay: "CHEATIN MODE"
function onUpdateScore()
local score_textPhrase = 'Score: {1} | Misses: {2} | Rating: {3}'
local score_textValues = {score, misses, string.format('%.2f', math.floor(rating * 100))}
local score_text = getTranslationPhrase('score_text', score_textPhrase, score_textValues)
debugPrint(score_text) --> "SKOR: 0 | MISEZ: 0 | Rating: ?"
endIs the page in some way inaccurate? an error, a typo, or outdated data? To report it, use the "Issue Tab". Or do you wish to include a new function or add new information? use the "Pull Request Tab". Help is always appreciated!
- Event Callbacks
- Custom Sprite
- Custom Text
- Object Functions
- General Functions
- Scripting & File Functions
- Game Input Control Functions
- Language Translation
- HScript Functions
- Custom Substates
- Custom Shaders
- Deprecated & Removed Functions
- Sound & Music Functions
- Tweens & Timers Functions
- Reflection Functions
- Variables