Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

2.0, SugarCube, (and possibly PHP) for changing languages

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

  • edited May 2015
    Translators are going to prefer working from a Word document in any case. So you could just write out your story first in word, send it off to a translator, then figure out what you want to do with it. That's always the best way if you are in need of any editing or localisation services. Putting text in the game environment always comes later in most productions.

    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.
  • edited May 2015
    Okay. Thank you. In PHP/ASP I just do a switch/case and then do an (include) or even define a constant. I guess that is out of reach here?
  • edited May 2015
    You know.... the more I think about this... what's to stop me from using a PHP page to call the TWINE story in the first place? Hmm... maybe that's not the issue. It's probably what happens AFTER the story is called.
    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.
  • I think I found something that works. Haven't tested it yet. Looks good, though.

    http://blog.thecodingmachine.com/content/internationalizing-javascript-script

    Thoughts?
    ―Sage.
  • Clarification: Sage is referring to Internationalization (i18n), not localization (L10n) — they are closely related yet distinct concepts. You do, obviously, need to obtain translations of the relevant text in both cases.

    As to creating globals, you could simply do something like the following (in a script tagged passage):
    window.gameText = {};
    window.gameText["EN"] = {
    	"hello" : "Hello.",
    	"start" : "…"
    };
    window.gameText["ES"] = {
    	"hello" : "Hola.",
    	"start" : "…"
    };
    window.gameText["FR"] = {
    	"hello" : "Bonjour.",
    	"start" : "…"
    };
    
    Then in-game you could access them like so:
    <<print gameText[$lang]["hello"]>>
    
    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).
  • WOW!

    A) You are awesome!
    B ) When does SugarCube 2 come out? It has the cool Click-to-Retract menu, does it not?
  • Yes, SugarCube 2's UI bar is stowable. As to when it might come out, I don't really know. I've been neglecting it to a degree lately, since better handling of story formats in Twine 2 really needs to be a thing first (and for those using Twine 1, I'd rather do a simultaneous release for both Twine 1 & 2, so…).
  • edited May 2015
    If you still need to translate the whole thing, it still seems to me it'd just be easier to create two different story versions, but maybe I'm missing something.
  • As just one example, if you have code separate from content you can make the changes without worrying about breaking game mechanics.

    It also allows for community translation efforts (if I should happen to ever get a following).
Sign In or Register to comment.