[Klone-users] Shared variables - Include KL1 page
Stefano Barbato
barbato at koanlogic.com
Wed Apr 30 07:34:05 EDT 2008
> 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.
A simple implementation...
Add translated strings in kloned.conf:
---[ kloned.conf ]---
# choose the language here
lang it
fr
{
mettre_a_jour in french...
}
it
{
mettre_a_jour in italian...
}
en
{
mettre_a_jour in english...
}
---------------------
Add a lang.h file with all strings defines like #define
METTRE_A_JOUR "mettre_a_jour".
Then edit the lang_text() function that return the translated text
based on the chosen "lang" setting:
---[ lang.c ]---
#include <klone/klone.h>
#include <klone/context.h>
const char *lang_text(const char *id)
{
u_config_t *sk, *cfg = ctx->config; /* klone config file */
const char *text, *lang;
dbg_err_if((lang = u_config_get_subkey_value(cfg, "lang")) ==
NULL);
dbg_err_if(u_config_get_subkey(cfg, lang, &sk));
dbg_err_if((text = u_config_get_subkey_value(sk, id)) == NULL);
return text;
err:
return "NOT FOUND";
}
----------------
Your index.kl1 will then look like this:
---[ index.kl1 ]---
<%!
#include <liblang/lang.h>
%>
<html>
<body>
<%= lang_text(METTRE_A_JOUR) %>
</body>
</html>
-------------------
Using this method you can switch the language without recompiling
klone using an external configuration file (-f FILE switch) or you can
embed all translation into the kloned executable. You could also have
different config file with just one language defined if you want to
save storage:
kloned -f kloned-it.conf
kloned -f kloned-en.conf
kloned -f kloned-fr.conf
You'll find the proof of concept klone-app attached.
bye,
stefano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: klone-lang-1.0.0.tar.gz
Type: application/x-gzip
Size: 1382 bytes
Desc: not available
Url : http://koanlogic.com/pipermail/klone-users/attachments/20080430/8ab88a4c/klone-lang-1.0.0.tar.bin
-------------- next part --------------
More information about the klone-users
mailing list