In PHP if I wanted to set a global variable or define something, I can do that fairly easily, but with JavaScript, I don't think I can (although for my purposes I might not need to).
What I am trying to do is to have a separate language file that I can call once a user sets their choice for preferred reading/game-playing language (for example, English, Spanish).
This way I can separate out the text and have JUST THAT PART translated into other languages, without needing someone to go through the code. It's cleaner.
When I search the forums the only thing that comes back are conversations about programming languages and not the language for the text itself.
Thanks in advance for any help.
―Sage.
Comments
The absolutely simplest way to achieve two languages in a Twine game is to create duplicates of each passage in different languages and have the user diverge from the start screen.
Or you can create two entirely separate stories and link to each one from a basic setup screen, which is perhaps in itself a small Twine story with external hyperlinks leading to other Twine stories.
Whichever way you go, localisation is a fair bit of work and there's no simple switch.
Just thinking out loud.
If I come up with a workable solution, i will let everyone know.
I've always been a fan of separating code from content.
―Sage.
http://blog.thecodingmachine.com/content/internationalizing-javascript-script
Thoughts?
―Sage.
As to creating globals, you could simply do something like the following (in a script tagged passage): Then in-game you could access them like so: Obviously, I've kept the example very simple, but you should get the idea.
Warning: You most definitely do not want to do this in a TwineScript $variable, since those are part of the story history.
SugarCube 2 does something similar with its strings variable, so virtually all of its user-facing text may be translated (it actually exists in SugarCube 1, but isn't used much).
A) You are awesome!
B ) When does SugarCube 2 come out? It has the cool Click-to-Retract menu, does it not?
It also allows for community translation efforts (if I should happen to ever get a following).