Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: Add support for elastic tabstops #1404

Open
ExE-Boss opened this issue Oct 4, 2017 · 0 comments
Open

REPL: Add support for elastic tabstops #1404

ExE-Boss opened this issue Oct 4, 2017 · 0 comments
Labels

Comments

@ExE-Boss
Copy link

ExE-Boss commented Oct 4, 2017

Elastic tabstops allow for better code alignment using tabs.

There is already a JavaScript library for this, but I would recommend using my fork, because it has support for JSDoc and fixes some issues with the original implementation.

Example:

A code written like so:

const languageData = {
	en: {
		appTitle:	{ "message":	"Some app"	},
		description:	{ "message":	"This application does things"	},

		options:	{ "message":	"Options"	},
		options_theme:	{ "message":	"Theme:"	},
		options_theme_default:	{ "message":	"Default Theme"	},
		options_theme_colorful:	{ "message":	"Colorful Theme"	}
	},

	en_GB: {
		options_theme_colorful:	{ "message":	"Colourful Theme"	}
	}
}

export const translateMessage = (message) => {
	const navLang	= navigator.language.split("-");
	let translated	= undefined;
	let prevLang	= undefined;

	for (let i = 0; i < navLang.length; i++) {
		let stuff	= navLang[i];
		if (prevLang) {
			stuff	= `${prevLang}_${stuff}`;
		}
		translated = languageData[stuff][message] || translated;
	}
	
	return translated;
}

Would render like so:

const languageData = {
	en: {
		appTitle:    { "message": "Some app"                     },
		description: { "message": "This application does things" },

		options:                { "message": "Options"        },
		options_theme:          { "message": "Theme:"         },
		options_theme_default:  { "message": "Default Theme"  },
		options_theme_colorful: { "message": "Colorful Theme" }
	},

	en_GB: {
		options_theme_colorful: { "message": "Colourful Theme" }
	}
}

export const translateMessage = (message) => {
	const navLang  = navigator.language.split("-");
	let translated = undefined;
	let prevLang   = undefined;

	for (let i = 0; i < navLang.length; i++) {
		let stuff = navLang[i];
		if (prevLang) {
			stuff = `${prevLang}_${stuff}`;
		}
		translated = languageData[stuff][message] || translated;
	}
	
	return translated;
}

(If this gets implemented then space indented code might finally die once and for all, because space indented code is much bigger than tab indented code (4 bytes (4 spaces) vs 1 byte (1 tab)).)

@hzoo hzoo added the repl label Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants