[Klone-users] Shared variables - Include KL1 page

thomas fossati tho at koanlogic.com
Wed Apr 30 02:27:40 EDT 2008


Ciao Mickael,

On Apr 29, 2008, at 3:56 PM, Mickael Auger wrote:
> To explain this with a real example, my variables contain a lot of  
> word in english (or in other language) that I want separate to C/ 
> HTML code to make a web-site in different languages.
>
> My 'language.kl1' file is
> =====================
> <%!
> #ifdef ENGLISH
> #define WORD "Hello"
> #endif
>
> #ifdef ITALIANO
> #define WORD "Ciao"
> #endif
> %>
> =====================
>
> And my 'index.kl1' page is
> =====================
> <html>
> <body>
>    <p><%= WORD %></p>
> </body>
> </html>
> =====================
> However, with this example, my variables are not declared to the  
> compilation of 'index.kl1'.

<super digression>

An hash map with custom "translation" records would perfectly fit your  
"multilingual" example.  I'd use u_hmap to hold the global translation  
table and possibly u_list's for each statement translation.  Something  
like:

u_hmap
======
key("sentence0")
	`-----> u_list
		======
		"en"		"it"		"fr"
		"the black cat"	"il gatto nero"	"le chat noir"
key("sentence1")
	`-----> u_list
		======
		"en"		"it"		"fr"
		"music"		"musica"	"musique"

Translation would be read from a custom dictionary file and loaded  
into memory at kloned initialization via hook_server_init().

To load from a file the u_config module could be used with a syntax  
similar to:

sentence0
{
	en	the black cat
	it	il gatto nero
	fr 	le chat noir
	# perhaps a fallback/default language should be also specified
}

sentence1
{
	en	music
	it	musica
	fr 	musique
}

As you can see everything could be obtained using only readily  
available klone components:

u_hmap -> http://www.koanlogic.com/libu/api/html/group__hmap.html
u_list -> http://www.koanlogic.com/libu/api/html/group__list.html
u_config -> http://www.koanlogic.com/libu/api/html/group__config.html

</super digression>

> If not, can I include a KL1 page (with only a unique <%! ...%> tag)  
> to share the variables
>
> Example :
> My 'index.kl1' page (2nd version) is
> ====================
> <%!
>     include("language.kl1");
> %>
> <html>
> <body>
>    <p><%= WORD %></p>
> </body>
> </html>
> ====================

The syntax for inclusion is:

<%@ include "language.kl1" %>

ciao, t.




More information about the klone-users mailing list