Created
November 4, 2012 04:44
-
-
Save awayken/4010323 to your computer and use it in GitHub Desktop.
Shortcut Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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és'; | |
break; | |
case 'spanish': | |
return 'Españ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