Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Shortcut Functions
component displayName="Shortcut Functions application" output="false" {
this.name = "ShortcutFunctions";
public void function onRequest( required template ) {
param name="url.language" default="en";
variables.__ = shortcutGetTranslation;
include template;
}
private string function shortcutGetTranslation( string input ) {
var translate = new com.awayken.translation();
return translate.getTranslation( input, url.language );
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="charset" content="utf-8">
<title>Shortcut Functions</title>
</head>
<body>
<cfoutput>
<h1>Shortcut Functions</h1>
<p>
<cfif url.language eq 'en'>
<a href="?language=es">#__('Spanish')#</a>
<cfelse>
<a href="?language=en">#__('English')#</a>
</cfif>
</p>
<ul>
<li>#__('dog')#</li>
<li>#__('cat')#</li>
<li>#__('milk')#</li>
</ul>
</cfoutput>
</body>
</html>
component {
public string function getTranslation( string input, string language ) {
switch( language ) {
case 'en':
return getEnglish( input );
break;
case 'es':
return getSpanish( input );
break;
default:
return getEnglish( input );
break;
}
}
private string function getSpanish( string input ) {
switch( input ) {
case 'english':
return 'Ingl&eacute;s';
break;
case 'spanish':
return 'Espa&ntilde;ol';
break;
case 'dog':
return 'perro';
break;
case 'cat':
return 'gato';
break;
case 'milk':
return 'leche';
break;
default:
return input;
}
}
private string function getEnglish( string input ) {
return input;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment