Yesterday I played around a bit with the engine and decided to start the Italian translation.
But since I’m a programmer, I didn’t want to just translate the .tsv file and plug it in, so I also tried to make the language selection extensible.
As shown in Just released adventure games I could add a new “slider” to the options screen that changes the language value.
First thing I did was creating a setting object in Settings.dinky under player options, which defaults to “en” if not present
SETTING(language) <- getSetting(“language”,“en”)
And enabling save in onRefreshPrefs() so you don’t have to change it every time you start the game
setUserPrefs(“language”,SETTING(language))
And in Boot.dinky, instead of just uncommenting useTranslation(“en”)
, I rewrote it as useTranslation(SETTING(language))
.
The selection was a bit trickier. I used the same sliders Options.dinky has for volume and text speed, hard-binding integers to the languages I had available. I’d like to make it dynamic for more languages, but for now it’s fine. The slider has an integer value where 0 is assigned to a string “en” and 1 to “it”, and circular value reset (if v < 0 goes back to 1).
line += 1
makeSlider(point(0, linePos(line)), "", 185, 1.0, 0.0, @(inc_dec){
local s = SETTING(language)
local v = 0
if (s == "en" ) v = 0 else
if (s == "it" ) v = 1
if (inc_dec < 0) v -= 1
if (inc_dec > 0) v += 1
if (v < 0) v = 1
if (v > 1) v = 0
local p = "en"
if (v == 0) { p = "en" }
if (v == 1) { p = "it" }
SETTING(language) <- p
useTranslation(p);
onRefreshPrefs()
local langname = TR(TEXT(10000,"English"))
return format(TR(TEXT(12355,"Language: %s")),langname)
})
Then language turned out to be Engish (sic), because there’s a typo in the translation file.
While doing so I also noticed that the text speeds are hardcoded (i.e., untranslatable).
So I added new text entries to the .tsv values and encapsulated them with TR() calls.
if (v == 7) { t = TR(TEXT(12356,“slowest”)); p = 2.0 }
if (v == 6) { t = TR(TEXT(12357,“slower”)); p = 1.5 }
if (v == 5) { t = TR(TEXT(12358,“slow”)); p = 1.25 }
if (v == 4) { t = TR(TEXT(12359,“normal”)); p = 1.0 }
if (v == 3) { t = TR(TEXT(12360,“fast”)); p = 0.75 }
if (v == 2) { t = TR(TEXT(12361,“faster”)); p = 0.5 }
if (v == 1) { t = TR(TEXT(12362,“fastest”)); p = 0.25 }
The only thing I didn’t manage was changing the whole UI on the fly when changing language. But if you close the options and turn them on again, or change the text speed, you’ll get that sweet sweet Italian text you’re craving for.
I could also change the spritesheet for the title cards room, creating a new texture for the Italian title text and show it dynamically if the current language is “it”.
I created a new room object, but now that I think of it, I could have extended the pre-existing object adding a new state. I’ll probably change that later. I want to do the same work for all image texts.