UnitTest( translator.asp )

Output

Non existing string
-------------------
Hello World!

Existing string test
--------------------
Welcome!
Bem vindo!
Bienvenido!
いらしゃいます!
환영합니다!
欢迎!

Sources

/axe-ut/translator.unit.test.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!--#include virtual="/lib/axe/classes/interface.asp"-->
<!--#include virtual="/lib/axe/classes/Parsers/json2.asp"-->
<!--#include virtual="/lib/axe/classes/Utilities/translator.asp"-->
<!--#include virtual="/lib/axe/classes/Utilities/Translator/interface.asp"-->
<!--#include virtual="/lib/axe/classes/Utilities/Translator/Medias/json.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>AXE - Unit Test - Translator</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>UnitTest( translator.asp )</h1>
            </div>
            <div id="container-bd">
 
<h2>Output</h2>
<div class="code"><pre><%
 
dim T : set T = new Translator
set T.Media = new Translator_Media_Json
T.Media.path = Server.mapPath("/cache/axe-translator.json")
call T.load()
 
Response.write( "Non existing string" & vbNewline )
Response.write( "-------------------" & vbNewline )
Response.write( strsubstitute( "{0}!{1}", array( T("Hello World"), vbNewline ) ) )
Response.write( vbNewline )
 
Response.write( "Existing string test" & vbNewline )
Response.write( "--------------------" & vbNewline )
 
Response.write( strsubstitute( "{0}!{1}", array( T("welcome"), vbNewline ) ) )
 
T.language = "pt-br"
Response.write( strsubstitute( "{0}!{1}", array( T("welcome"), vbNewline ) ) )
 
T.language = "es-es"
Response.write( strsubstitute( "{0}!{1}", array( T("welcome"), vbNewline ) ) )
 
T.language = "ja-jp"
Response.write( strsubstitute( "{0}!{1}", array( T("welcome"), vbNewline ) ) )
 
T.language = "kr-ko"
Response.write( strsubstitute( "{0}!{1}", array( T("welcome"), vbNewline ) ) )
 
T.language = "zn-cn"
Response.write( strsubstitute( "{0}!{1}", array( T("welcome"), vbNewline ) ) )
 
set T.Media = nothing
set T = nothing
 
%></pre></div>
 
            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
                <h3>/lib/axe/classes/Utilities/Translator/interface.asp</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "/lib/axe/classes/Utilities/Translator/interface.asp" ) ), "asp" ) %></div>
                <h3>/lib/axe/classes/Utilities/Translator/Medias/json.asp</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "/lib/axe/classes/Utilities/Translator/Medias/json.asp" ) ), "asp" ) %></div>
                <h3>/cache/axe-translator.json</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "/cache/axe-translator.json" ) ), "asp" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>
 

/lib/axe/classes/Utilities/Translator/interface.asp

<%
 
' File: interface.asp
'
' AXE(ASP Xtreme Evolution) translator object interface specification.
'
' License:
'
' This file is part of ASP Xtreme Evolution.
' Copyright (C) 2010 Fabio Zendhi Nagao
'
' ASP Xtreme Evolution is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' ASP Xtreme Evolution is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License for more details.
'
' You should have received a copy of the GNU Lesser General Public License
' along with ASP Xtreme Evolution. If not, see <http://www.gnu.org/licenses/>.
 
 
 
' Class: Translator_Interface
'
' Defines the common specifications required to implement a working media of
' Translator class.
'
' About:
'
'	- Written by Fabio Zendhi Nagao <http://zend.lojcomm.com.br> @ Jun 2010
'
class Translator_Interface' extends Interface
 
' --[ Interface definition ]----------------------------------------------------
 
	' Function: load
	'
	' Returns the serialized Translator from the persistence layer.
	'
	' Returns:
	'
	'	(string) - Translator serialized content
	'
	public function load()
		load = "(string)"
	end function
 
	' Property: classType
	'
	' Class type.
	'
	' Contains:
	'
	'	(string) - type
	'
	public property get classType
		classType = typename(Me)
	end property
 
	' Property: classVersion
	'
	' Class version.
	'
	' Contains:
	'
	'	(string) - version in terms of http://semver.org/#semantic-versioning-200
	'
	public property get classVersion
		classVersion = "2.0.0"
	end property
 
' --[ Delegation ]--------------------------------------------------------------
 
	public property get requireds
		requireds = Parent.requireds
	end property
 
	public function check(byRef Implementation)
		check = Parent.check(Implementation)
	end function
 
' --[ Private section ]---------------------------------------------------------
 
	private Parent
 
	private sub Class_initialize()
		set Parent = new Interface
		Parent.requireds = array("load")
	end sub
 
	private sub Class_terminate()
		set Parent = nothing
	end sub
 
end class
 
%>
 

/lib/axe/classes/Utilities/Translator/Medias/json.asp

<%
 
' File: json.asp
'
' AXE(ASP Xtreme Evolution) json file media.
'
' License:
'
' This file is part of ASP Xtreme Evolution.
' Copyright (C) 2007-2012 Fabio Zendhi Nagao
'
' ASP Xtreme Evolution is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' ASP Xtreme Evolution is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License for more details.
'
' You should have received a copy of the GNU Lesser General Public License
' along with ASP Xtreme Evolution. If not, see <http://www.gnu.org/licenses/>.
 
 
 
' Class: Translator_Media_Json
'
' This class enables Translator to use data stored in json files.
'
' About:
'
'	- Written by Fabio Zendhi Nagao <http://zend.lojcomm.com.br> @ Dec 2010
'
class Translator_Media_Json' implements Translator_Interface
 
' --[ Implementation ]----------------------------------------------------------
 
	' Function: load
	'
	' Returns the serialized Translator from the json file.
	'
	' Returns:
	'
	'	(string) - Translator serialized content
	'
	public function load()
		if(varType(path) = vbEmpty) then _
			Err.raise 5, "Evolved AXE runtime error", strsubstitute( _
				"Invalid procedure call or argument. '{0}' property 'path' isn't defined", _
				array(classType) _
			)
		with Server.createObject("Scripting.FileSystemObject")
			if( .fileExists(path) ) then
				with Server.createObject("ADODB.Stream")
					.type = adTypeText
					.mode = adModeReadWrite
					.charset = "UTF-8"
					.open()
 
					.loadFromFile(path)
					.position = 0
					load = JSON.minify( .readText() )
 
					.close()
				end with
			else
				load = "{}"
			end if
		end with
	end function
 
	' Property: encoding
	'
	' Text encoding
	'
	' Contains:
	'
	'	(Stream.charset) - text encoding. Defaults to UTF-8
	'
	public encoding
 
	' Property: path
	'
	' File System physical path
	'
	' Contains:
	'
	'	(string) - file system physical path
	'
	public path
 
	' Property: classType
	'
	' Class type.
	'
	' Contains:
	'
	'	(string) - type
	'
	public property get classType
		classType = typename(Me)
	end property
 
	' Property: classVersion
	'
	' Class version.
	'
	' Contains:
	'
	'	(string) - version in terms of http://semver.org/#semantic-versioning-200
	'
	public property get classVersion
		classVersion = "2.0.0"
	end property
 
' --[ Private Section ]---------------------------------------------------------
 
	private Interface
 
	private sub Class_initialize()
		set Interface = new Translator_Interface
		if( not Interface.check(Me) ) then _
			Err.raise 17, "Evolved AXE runtime error", strsubstitute( _
				"Can't perform requested operation. '{0}' is a bad interface implementation of '{1}'", _
				array(classType, typename(Interface)) _
			)
		encoding = "UTF-8"
	end sub
 
	private sub Class_terminate()
		set Interface = nothing
	end sub
 
end class
 
%>
 

/cache/axe-translator.json

{
    "en-us": { "welcome": "Welcome" },
    "pt-br": { "welcome": "Bem vindo" },
    "es-es": { "welcome": "Bienvenido" },
    "ja-jp": { "welcome": "いらしゃいます" },
    "kr-ko": { "welcome": "환영합니다" },
    "zn-cn": { "welcome": "欢迎" }
}