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.