forrest-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Telford <>
Subject Re: please help me with Chinese content problem
Date Wed, 16 Jul 2008 16:17:53 GMT
fanieste wrote:
> hi guys,
> I'm using forrest to generate a site where most content is in Chinese.
> I started at invoking "forrest seed-sample" to generate a template
> project, then I edited index.xml in the xdocs directory to made some
> Chinese content added, and ran "forrest site".
> when I browsed the index.html within my browser, it showed me "????"
> instead of the Chinese characters. I checked the index.html generated,
> the Chinese Content was turned to "????", I mean It's not because of a
> wrong http metadata setting. I also checked the index.pdf, there are
> "#####"   at the corresponding positions.
I had problems with encoding for a static site. In my case I  had 
english, french and chinese translations.  I finally worked out that I 
need correct environment settings before running forrest. I am using 
Below is the shell script that I run from the folder that has the src 
and build folders in it.  (If you are  just building in one language, 
then just type 'export LANG=zh_CN.UTF-8' or whatever is appropriate 
before running forrest.) Hope this helps someone, my full 'build' bash 
script, htaccess, and javascript snippets are below, and is suitable for 
assembling a set of files suitable for use with apache.

# start of build script
# remove old forrest generated site
rm -rf build
# rebuild all 3 languages
LANG=en_US.UTF-8 forrest
LANG=fr_CA.UTF-8 forrest
LANG=zh_CN.UTF-8 forrest
# combine sites in the directory combined/ suitable for apache
# clean out combined/
rm -rf combined
mkdir combined
# copy all files from the forrest build directory renaming appropriately
filelist=`find build/site -type f -printf '%p '`
for i in $filelist
ii=`echo $i | sed 's|build/site/||'`
la=`echo $ii | sed 's|\(..\).*|\1|'`
dest=`echo $ii | sed 's|../\(.*\)|\1|'`
 install -D $i combined/$dest.$la

# copy htaccess file
cp htaccess combined/.htaccess

# finally if all language versions exist and are the same merge to a 
single non-language version
filelist=`find combined -type f -name \*.en -printf '%p '`
for i in $filelist
 root=`echo $i | sed 's|\(.*\).en|\1|'`
  if [ -f $i -a -f $ -a -f $root.zh ]
    cmp -s $i $
    cmp -s $i $root.zh
    if [  "$cmpfr" -eq 0  ]
     if [ "$cmpzh" -eq 0 ]
       # all three versions are the same rename
       rm -f $ $root.zh
       mv $i $root
# then run sitecopy or whatever to upload "combined" folder to
#end if bash script

Here is the file which is copied to combined/.htaccess in the shell script

AddCharset UTF-8 .html .html.zh .html.en
SetEnvIf Cookie "StellaeLang=(..)" prefer-language=$1
SetEnvIf Cookie "StellaeLang=def" !prefer-language
Header set ENV_PREFER_LANG %{prefer-language}e env=prefer-language
Header append Vary cookie
AddLanguage zh .zh
LanguagePriority en fr zh

Following are the modifications to the forrest distribution.
I have modified main/webapp/skins/common/scripts/fontsize.js :

function init()
{ //embedded in the doc

function setStellaeLang(language)
    return false;

function StellaeInit()
    var l=ndeReadCookie('StellaeLang');
    switch (l)
        case 'en'  :   document.getElementById('lngsel').selectedIndex = 
1; break;
        case 'fr'  :   document.getElementById('lngsel').selectedIndex = 
2; break;
        case 'zh'  :   document.getElementById('lngsel').selectedIndex = 
3; break;
        default :   document.getElementById('lngsel').selectedIndex = 0;
    return false;

In main/webapp/skins/pelt/xslt/html/site-to-xhtml.xsl I insert the code 
which will add the language selector (under the skinconf-podlink section)

 <xsl:template match="div[@id='skinconf-langsel']">
    <div class="langsel trail"  title="Set browser cookie for 
      <select  onchange="setStellaeLang(this.value);" size="1" 
id="lngsel" class="dida">
        <option value="def" selected="selected">Default</option>
        <option value="en">English</option>
        <option value="fr">Fran&#231;ais</option>
        <option value="zh">&#x4e2d;&#x6587;</option>

In main/webapp/skins/pelt/xslt/html/document-to-html.xsl I add the 
following under the pdflink line, so that the xsl above will insert the 
selector at the correct place

 <div id="skinconf-langsel"/>

(Check for the actual site. )

View raw message