0 votes
by (120 points)
Hello dear twiners,

If I want to write a story in french and english, how could I do that ?

3 Answers

+1 vote
by (63.1k points)

An example by @TheMadExile: 

https://gist.github.com/tmedwards/33f3b4b7ada317fc9cc70aa8580c03f0

This assumes SugarCube. For Harlowe, you have your work cut out for you. 

by (120 points)
Thanks a lot, that's very interesting !

If I understand correctly, we put this code and then we have to precede the passages with the appropriate suffix if it's not in english ?
by (63.1k points)
I believe all passages get suffixes, regardless of which is the "default" language, and the unsuffixed passages should be blank (though theoretically, and potentially at the risk of confusing things, you could put code common to all languages in the non-suffixed passages, but I don't think I'd recommend that as it'd probably mess up the history system).
0 votes
by (6.2k points)
Please use the tags to show which format you are using.
0 votes
by (710 points)

I had asked the same question some time ago with SugarCube 2.

https://twinery.org/questions/9/possible-to-language-switch-option-with-twine-and-sugarcube

Here’s a code you can use.

setup.i18n = {
	langs : {
		'English'  : 'en',
		'Français' : 'fr',

	},

	codes : function () {
		return Object.keys(this.langs).map(function (label) {
			return this.langs[label];
		}, this);
	},

	labels : function () {
		return Object.keys(this.langs);
	},

	labelFromCode : function (code) {
		var label = Object.keys(this.langs).find(function (label) {
			return this.langs[label] === code;
		}, this);

		if (!label) {
			throw new Error('unknown language code "' + code + '"');
		}

		return label;
	}
};

function initLanguage() {
	switch (setup.i18n.langs[settings.lang]) {

	case 'fr':
		l10nStrings.ok = 'OK',
		l10nStrings.savesLabelSlot = 'Emplacement',
		l10nStrings.savesSavedOn = 'Sauvegarder sur',
		l10nStrings.uiBarToggle = 'Cache / Montre l’IU';
		l10nStrings.settingsTitle = 'Paramètres';
		l10nStrings.settingsOff   = 'Off';
		l10nStrings.settingsOn    = 'On';
		l10nStrings.settingsReset = 'Réinitialiser';
		l10nStrings.cancel =  "Annuler";
		l10nStrings.restartTitle = "Recommencer";
		l10nStrings.restartPrompt = "Êtes-vous sûr de vouloir recommencer? Tout progrès non sauvegardé sera perdu.";
		l10nStrings.savesTitle = "Sauvegardes";
		l10nStrings.savesEmptySlot = "emplacement vide";
		l10nStrings.savesLabelDelete = "Effacer";
		l10nStrings.savesLabelExport = "Sauvegarder au Disque";
		l10nStrings.savesLabelImport = "Charger du Disque";
		l10nStrings.savesLabelLoad = "Charger";
		l10nStrings.savesLabelClear = "Tout Effacer";
		l10nStrings.savesLabelSave = "Sauvegarder";
		break;

	case 'en':
		l10nStrings.ok = 'OK',
		l10nStrings.savesLabelSlot = 'Slot',
		l10nStrings.savesSavedOn = 'Saved on',
		l10nStrings.uiBarToggle = 'Toggle the UI bar';
		l10nStrings.settingsTitle = 'Settings';
		l10nStrings.settingsOff   = 'Off';
		l10nStrings.settingsOn    = 'On';
		l10nStrings.settingsReset = 'Reset to Defaults';
		l10nStrings.cancel =  "Cancel";
		l10nStrings.restartTitle = "Restart";
		l10nStrings.restartPrompt = "Are you sure that you want to restart? Unsaved progress will be lost.";
		l10nStrings.savesTitle = "Saves";
		l10nStrings.savesEmptySlot = "slot empty";
		l10nStrings.savesLabelDelete = "Delete";
		l10nStrings.savesLabelExport = "Save to Disk\u2026";
		l10nStrings.savesLabelImport = "Load from Disk\u2026";
		l10nStrings.savesLabelLoad = "Load";
		l10nStrings.savesLabelClear = "Delete All";
		l10nStrings.savesLabelSave = "Save";
		break;
}

	$('html').attr('lang', setup.i18n.langs[settings.lang]);
}

function changeLanguage() {
	window.location.reload();
}

Setting.addList('lang', {
	label    : 'Language - Langue',
	list     : setup.i18n.labels(),
	default  : setup.i18n.labelFromCode('fr'),
	onInit   : initLanguage,
	onChange : changeLanguage
});

postrender['i18n-passage-include'] = function (content) {
	var passage = State.passage + '_' + setup.i18n.langs[settings.lang];

	$(content).empty().wiki(Story.get(passage).processText());
};

The way it works afterward is with one empty passage (the “container”), then two passages for the languages used. Like: Start, Start_fr, Start_en.

by (280 points)
edited by

Hello,

I am using Sugarcube 2 with Twine 2, aiming at creating a sort of dropdown menu with language picker (switcher) for a user to give ability to change language whenever needed. I've used the above script, which is working but I have no clue on how let the user have the ability to pick a language.

for instance, imagine to have the following two anchor links - always present in the user ui, then what would be the script to change language accordingly?

/* Lang switch to EN/FR */
<a id="buttonLangIT" href="" class="button">EN</a>
<a id="buttonLangFR" href="" class="button">FR</a>

Can someone please help me?

Sorry, I did not activated the settings ui API in my custom user interface. Now I see the select menu with all languages available. Just a clarification, for multilanguages i18n shall we duplicate all passages according to the number of languages OR all languages should be placed into single passages?

Thank you!! 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...