Translation Page With Object Snippet

As i know, nothing has been done to translate a strutured page (page containing an FAQ object for exemple). I hope this will be integrated to xwiki soon. The code following allow you to do this.
You have to add the string propertie AF_translation to the object class you want translating.

############ CSS
<style>
.imgFlag {
		padding-left:28px;
		background-repeat:no-repeat;
		line-height: 20px;
}
</style>

############ MACRO VELO
##################################################
###Allow to create a Java ArrayList java based on a word list
## listWord : list of word (tyty,toto,tutu)
## separator : separator (,) NOT |
##################################################
#macro (to_arrayList $listWord $separator)
	#set($array_listWord=$listWord.split($separator))
	#set($al=[])
	#foreach($oneWord in $array_listWord)
		#set($retAdd=$al.add($oneWord))
	#end
#end

############ PANEL CONTENT
#############################################################################################
##
## Panel content
## Warning : this code is optimize for page containing one type of object class
##
#############################################################################################
#if($xwiki.isMultiLingual()==true || $showEmptyPanels)
  #panelheader($msg.get("panels.translation.title"))
	#set($imgFlag=" class='imgFlag' style='background-image:url(${xwiki.getSkinFile('img/flags/small/small_${context.getLanguage()}.gif')});'>")
	$msg.get("panels.translation.editingTranslation", ['<span '])${imgFlag}<b>$msg.get(${context.getLanguage()})</b></span>
###### Recuperation des traductions existantes
	#set($error_translation_is_not_manage=true)
	#set($existingTranslation = "")
	##ts les types d'objets present dans le doc courant
	#foreach($class in $doc.xWikiClasses)
		##ts les objets d'un type donné
		#foreach ($obj in $doc.getObjects($class.name))
			#set($prop_AF_translation=$!obj.getProperty("AF_translation"))
			#if ($prop_AF_translation)
				##champ translation present
				#set($error_translation_is_not_manage=false)
				#if( $prop_AF_translation.getValue().length()>0 )
					#set($existingTranslation = "${prop_AF_translation.getValue()},${existingTranslation}")
				#end
			#end
		#end
	#end
	#if ($error_translation_is_not_manage)
		#warning("translation not allowed for this objet; contact your administrator.")
	#else
		#to_arrayList($existingTranslation ",")  
	###### Recuperation des traductions necessaires pour le wiki courant
		#set($allowedLanguages=$xwiki.getXWikiPreference("languages").split("[|, ]"))
	###### Affichage du bon lien en fonction de l'existance de la traduction
		#foreach ($allowedLanguage in $allowedLanguages)
	###### Si ce n'est pas la langue en cours
			#if ($allowedLanguage!=${context.getLanguage()})
				#set($imgFlag=" class='imgFlag' style='background-image:url(${xwiki.getSkinFile('img/flags/small/small_${allowedLanguage}.gif')});'>")
				#set($af_redirect=$doc.getURL("inline", "language=${allowedLanguage}"))
				#if (${al.contains("${allowedLanguage}")})
					##la traduction existe deja
					<br><a href="$af_redirect" $imgFlag>${msg.get($allowedLanguage)}</a>
				#else
					##nouvelle traduction
					<br><a $imgFlag href="$doc.getURL("objectadd","classname=XWiki.ArticleClass&XWiki.ArticleClass_AF_translation=${allowedLanguage}&xredirect=$xwiki.getURLEncoded($af_redirect)")">$msg.get($allowedLanguage)</a>
				#end
			#end
		#end
	#end
  #panelfooter()
#end

############ edittoolbar.vm (skin file - edit mode)
#if($editor == "wiki" || $editor == "wysiwyg" )
	#set($panel='xwiki:Panels.EditTranslations')
	#displaypanel($panel)
	<br>
#end
#if ( ( $context.action == "inline" ) && ( $doc.fullName!="News.CreateNews") )
	#set($panel='xwiki:Panels.EditInlineTranslations')
	#displaypanel($panel)
	<br>
#end
[...]

############ languages.vm (skin file - view mode) (You can do this in a panel content if you want)
#if ( ($xwiki.isMultiLingual()==true) && ($context.action=="view") )
	#set($translation_is_not_object=true)
	#set($existingTranslation = "")
	##ts les types d'objets present dans le doc courant
	#foreach($class in $doc.xWikiClasses)
		##ts les objets d'un type donné
		#foreach ($obj in $doc.getObjects($class.name))
			#set($prop_AF_translation=$!obj.getProperty("AF_translation"))
			#if ($prop_AF_translation)
				##champ translation present
				#set($translation_is_not_object=false)
				#if( $prop_AF_translation.getValue().length()>0 )
					#set($existingTranslation = "${prop_AF_translation.getValue()},${existingTranslation}")
				#end
			#end
		#end
	#end
	#if ($translation_is_not_object)
		############# TRADUCTION DE DOCUMENT
		#set($preflanguage = $xwiki.languagePreference)
		#set($languageactive = (($preflanguage == "")||($preflanguage == "default")||($preflanguage==$doc.defaultLanguage)))
		#set($defaultLanguage = $doc.defaultLanguage)
		#if ($doc.defaultLanguage == "")
			#set($defaultLanguage = "default")
		#end
		#set($imgFlag=" class='imgFlag' style='background-image:url(${xwiki.getSkinFile('img/flags/small/small_${defaultLanguage}.gif)});' ")
		<a href="$doc.getURL("view","language=${defaultLanguage}")" $imgFlag>$msg.get($defaultLanguage)</a><br>
		#foreach ($language in $doc.translationList)
			#set($languageactive = ($preflanguage==$language))
			#set($imgFlag=" class='imgFlag' style='background-image:url(${xwiki.getSkinFile('img/flags/small/small_${defaultlanguage}.gif)});' ")
			<a href="$doc.getURL("view","language=${language}")" $imgFlag>$msg.get($language)</a><br>
		#end
	#else
		############# TRADUCTION D'OBJECT
		#to_arrayList($existingTranslation ",")  
	###### Recuperation des traductions necessaires pour le wiki courant
		#set($allowedLanguages=$xwiki.getXWikiPreference("languages").split("[|, ]"))
	###### Affichage du lien en fonction de l'existance de la traduction
		#foreach ($allowedLanguage in $allowedLanguages)
			#set($imgFlag=" class='imgFlag' style='background-image:url(${xwiki.getSkinFile('img/flags/small/small_${allowedLanguage}.gif)});' ")
			#if (${al.contains("${allowedLanguage}")})
				##la traduction existe
				<a href="${doc.getURL("view", "language=${allowedLanguage}")}" $imgFlag>${msg.get($allowedLanguage)}</a><br>
			#end
		#end
	#end
#end
Version 4.1 last modified by jurevert on 22/04/2008 at 16:20

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: jurevert on 2008/04/22 09:30
This wiki is licensed under a Creative Commons license
1.4.1.10194