#!/usr/bin/perl use strict; use Data::Dumper; # # The translation status from .po files # # Copyright (C) 2004-2005 Bruno Coudoin. # # gcompris2spip is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2 published by the Free Software Foundation. # # Intltool 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 # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # # Authors: Bruno Coudoin # # # Prerequisite: - We need to have the translation in the xml files in order # ------------ for this script to work. # activate @INTLTOOL_XML_RULE@ in boards/Makefile.am # # - Need to switch svg icons to png, upload them and # replace the .svg by .png in all the .xml menus # (in boards/skins/gartoon/boardicons/): # for f in *.svg; do g=`basename $f .svg`; inkscape $f --export-png=tt/$g.png; done # (in boards/): # sed -i s/\.svg/\.png/g *.xml # ----------------------------------------------------------------------------------------- # USAGE: # This tool requires no parameters. It must be run withing the gcompris/docs directory # It will extract xml menus from gcompris/boards and create a spip XML version for them #------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------- # Define some constants related to spip rubrique and section organisation # We do not detect which locale sections are. They are hardcoded here. my %sections = ( "am", 0, "af", 0, "ar", 176, "ar_TN", 0, "az", 0, "bg", 0, "br", 195, "ca", 0, "cs", 0, "da", 37, "de", 54, "dz", 0, "el", 222, "en", 2, "en_CA", 0, "en_GB", 0, "es", 40, "et", 0, "eu", 0, "fa", 380, "fi", 36, "fr", 1, "ga", 0, "gl", 0, "gu", 0, "he", 383, "hi", 0, "hr", 0, "hu", 121, "id", 369, "it", 60, "ja", 0, "ka", 0, "ko", 0, "lt", 0, "mk", 0, "ml", 0, "mr", 0, "ms", 0, "nl", 92, "nb", 107, "nn", 38, "ne", 0, "oc", 0, "pa", 0, "pl", 125, "pt", 28, "pt_BR", 141, "ro", 0, "ru", 160, "rw", 0, "sk", 396, "sl", 0, "so", 172, "sq", 0, "sr", 0, 'sr@Latn', 0, "sv", 208, "ta", 154, "th", 0, "tr", 157, "uk", 161, "ur", 0, "vi", 116, "wa", 0, "zh_CN", 0, "zh_TW", 0, ); my %rubriques = ( "am", 0, "af", 0, "ar", 177, "ar_TN", 0, "az", 0, "bg", 0, "br", 199, "ca", 0, "cs", 0, "da", 61, "de", 64, "dz", 0, "el", 223, "en", 12, "en_CA", 0, "en_GB", 0, "es", 47, "et", 0, "eu", 0, "fa", 381, "fi", 73, "fr", 6, "ga", 0, "gl", 0, "gu", 0, "he", 388, "hi", 0, "hr", 0, "hu", 123, "id", 374, "it", 66, "ja", 0, "ka", 0, "ko", 0, "lt", 0, "mk", 0, "ml", 0, "mr", 0, "ms", 0, "nl", 93, "nb", 108, "nn", 69, "ne", 0, "oc", 0, "pa", 0, "pl", 134, "pt", 56, "pt_BR", 142, "ro", 0, "ru", 162, "rw", 0, "sk", 397, "sl", 0, "so", 173, "sq", 0, "sr", 0, 'sr@Latn', 0, "sv", 213, "ta", 155, "th", 0, "tr", 158, "uk", 164, "ur", 0, "vi", 117, "wa", 0, "zh_CN", 0, "zh_TW", 0, ); my %rubriques_all = ( "am", 0, "af", 0, "ar", 178, "ar_TN", 0, "az", 0, "bg", 0, "br", 200, "ca", 0, "cs", 0, "da", 62, "de", 65, "dz", 0, "el", 224, "en", 68, "en_CA", 0, "en_GB", 0, "es", 71, "et", 0, "eu", 0, "fa", 382, "fi", 74, "fr", 63, "ga", 0, "gu", 0, "gl", 0, "he", 389, "hi", 0, "hr", 0, "hu", 124, "id", 14086, "it", 67, "ja", 0, "ka", 0, "ko", 0, "lt", 0, "mk", 0, "ml", 0, "mr", 0, "ms", 0, "nl", 94, "nb", 109, "nn", 70, "ne", 0, "oc", 0, "pa", 0, "pl", 140, "pt", 72, "pt_BR", 143, "ro", 0, "ru", 163, "rw", 0, "sk", 398, "sl", 0, "so", 174, "sq", 0, "sr", 0, 'sr@Latn', 0, "sv", 220, "ta", 156, "th", 0, "tr", 159, "uk", 165, "ur", 0, "vi", 118, "wa", 0, "zh_CN", 0, "zh_TW", 0, ); #------------------------------------------------------------------------------- sub spip_cleanup { my $output = shift; # Spip doesn't like shortucted tags like . But xsltproc does this by default # and I dod not find a way to avoid that. # I put __REMOVEME__ in empty tags and I remove it there $output =~ s/__REMOVEME__//g; $output =~ s/__NBSP__/ /g; # We need to html backquote html tags for spip # I put in uppercase all html tags my @html_tag = qw/HTML IMG A BR DIV P/; foreach my $tag (@html_tag) { $output =~ s/<$tag/<$tag/g; $output =~ s/<\/$tag/<\/$tag/g; } # Fix the tag because wa cannot use it in xslt name space is not defined $output =~ s/lien_auteur/lien:auteur/g; # Remove eMail adresses $output =~ s/[a-zA-Z0-9\_\-\.\(]+@[a-zA-Z0-9\_\-\.\)]+//g; return $output; } #------------------------------------------------------------------------------- # Initialisation my ($sec, $min, $hours, $day, $month, $year) = (localtime)[0,1,2,3,4,5]; my $date = "".($year+1900)."-".($month+1)."-"."$day $hours:$min:$sec"; my $gcompris_root_dir = ".."; my $boards_dir = "$gcompris_root_dir/boards"; my $ALL_LINGUAS_STR = `grep "ALL_LINGUAS=" $gcompris_root_dir/configure.in | cut -d= -f2`; $ALL_LINGUAS_STR =~ s/\"//g; my @ALL_LINGUAS = split(' ', $ALL_LINGUAS_STR); push @ALL_LINGUAS, "en"; # Add english, it's not in the po list # Debug #@ALL_LINGUAS = qw/fr en ar/; # Check we have all we need for each defined lang my $error = 0; foreach my $lang (@ALL_LINGUAS) { if(! defined $sections{$lang} || ! defined $rubriques{$lang} || ! defined $rubriques_all{$lang} ) { print "ERROR: Edit this script and add a lang definition for lang '$lang' in \%sections \%rubriques \%rubriques_all\n"; $error = 1; } } exit 1 if $error; my $tmp_file = "temp_file.spip"; my $output_file = "all_article.spip"; # Erase previous output unlink $tmp_file; unlink $output_file; my $first_article = 999; my $article_id = $first_article; # First, Get all the boards description files opendir DIR, $boards_dir or die "cannot open dir $boards_dir: $!"; my @files = grep { $_ =~ /\.xml$/} readdir DIR; closedir DIR; #------------------------------------------------------------------------------- # Menu creation my @sections; my $all_boards_file = "all_boards.xml"; # Erase previous output unlink $all_boards_file; open(OUTPUT, ">>$all_boards_file"); print OUTPUT "\n"; foreach my $board (@files) { print "Processing $board\n"; my $file = "$boards_dir/$board"; open(BOARD, "<$file"); my $board_content; my $board_section; my $board_name; my $board_type; read(BOARD, $board_content, 165535); $board_section = ($board_content =~ /section=\"([a-zA-Z\/\._]+)\"/)[0]; $board_name = ($board_content =~ /name=\"([a-zA-Z\/\.\:_]+)\"/)[0]; $board_type = ($board_content =~ /type=\"([a-zA-Z\/\.\:_]+)\"/)[0]; if($board_type eq "menu" and $board_name ne "root") { print " This is a menu\n"; my @section; if( $board_section ne "/") { push(@section, "$board_section/$board_name"); } else { push(@section, "/$board_name"); } push(@section, $board_name); print " Section=$board_section\n"; print " Type=$board_type\n"; print " Name=$board_name\n"; if($file !~ /($board_name).xml/) { print "ERROR: The board file '$file' does not match it's internal name field ('$board_name')\n"; exit 1; } push(@sections, \@section); } # Skip experimental activities if($board_content =~ /section=\"\/experimental\"/) { goto done; } # Some filtering $board_content =~ s/<\?xml version="1.0" encoding="UTF-8"\?>//g; print OUTPUT $board_content; done: close(BOARD); } print OUTPUT "\n\n"; close (OUTPUT); # Loop over each menu entry foreach my $onesection (@sections) { my @deref = @{$onesection}; my $section = $deref[0]; my $name = $deref[1]; print "\nProcessing section=$section name=$name\nLang:"; # The first article is the reference article my $traduction_id = $article_id; # 2nd loop over each language foreach my $lang (@ALL_LINGUAS) { my $xslfile = "spip_menuboard.xsl"; $article_id++; print "$lang "; # Remove @ from some langage to avoid non URL char my $langstrip = $lang; $langstrip =~ s/\@/_/g; my $cmd = "xsltproc --stringparam language $lang --stringparam langstrip $langstrip --stringparam date \"${date}\" --stringparam article_id ${article_id} --stringparam rubrique_id $rubriques{$lang} --stringparam section $section --stringparam name $name --stringparam section_id $sections{$lang} --stringparam traduction_id ${traduction_id} $xslfile $all_boards_file"; my $output = `$cmd`; # Uncomment to debug #print "$cmd\n"; if ($?>>8) { print "#\n"; print "#\n"; print "#\n"; print "An error as been encountered in xslt processing: processing is left uncomplete\n"; print "ERROR on section $section lang $lang#\n"; print "#\n"; print "#\n"; exit 1; } else { # Make some cleanup where needed # ------------------------------ $output = spip_cleanup($output); open(OUTPUT, ">>$tmp_file") or die "Can't open: $!"; print OUTPUT $output . "\n"; close (OUTPUT); } } } #------------------------------------------------------------------------------- # Article creation # We record in a hash the article number for each lang/board name my %articles; foreach my $board (@files) { print "\nProcessing $board\nLang:"; # Skip some boards if($board eq "administration.xml" || $board eq "experimental.xml") { print " ($board is skipped)"; next; } # The first article is the reference article my $traduction_id = $article_id; # 2nd loop over each language foreach my $lang (@ALL_LINGUAS) { my $file = "$boards_dir/$board"; my $xslfile = "spip_oneboard.xsl"; $article_id++; # Manage Left to Right / Right to Left languages my $left="left"; my $right="right"; if ($lang =~ /^ar/ || $lang =~ /^he/ || $lang =~ /^fa/) { $left = "right"; $right = "left"; } print "$lang "; # Remove @ from some language to avoid non URL char my $langstrip = $lang; $langstrip =~ s/\@/_/g; # Hide the article # $rubriques{$lang} = 0; my $output = `xsltproc --stringparam language $lang --stringparam left $left --stringparam right $right --stringparam langstrip $langstrip --stringparam date "${date}" --stringparam article_id ${article_id} --stringparam rubrique_id $rubriques_all{$lang} --stringparam section_id $sections{$lang} --stringparam traduction_id ${traduction_id} $xslfile $file`; if ($?>>8) { print "#\n"; print "#\n"; print "#\n"; print "An error as been encountered in xslt processing: processing is left uncomplete\n"; print "ERROR on file $file lang $lang#\n"; print "#\n"; print "#\n"; exit 1; } else { # Make some cleanup where needed # ------------------------------ $output = spip_cleanup($output); open(OUTPUT, ">>$tmp_file") or die "Can't open: $!"; print OUTPUT $output . "\n"; close (OUTPUT); # Record the article $articles{"$lang:$board"} = $article_id; } } } #------------------------------------------------------------------------------- # Replace article link as created in the menu by the real article number # as we created it. open(FILEREAD, "< $tmp_file"); open(FILEWRITE, "> $output_file"); my $line = 0; while (){ my $line = $_; m/href=\"(\w+:[a-zA-Z0-9_-]+\.xml)/g; if(defined($articles{"$1"})) { print "Found article " . $articles{"$1"} . "\n"; my $article = "article.php3?id_article=$articles{$1}"; my $r = s/(^.*)(href=\")(\w+:[a-zA-Z0-9_-]+\.xml)(.*)/$1$2$article$4/g; } print FILEWRITE; } close FILEWRITE; close FILEREAD; #------------------------------------------------------------------------------- # Summary print "\n\nCreated " . ($article_id - $first_article) . " Articles in $output_file\n"; print "Insert the content of this file in the SPIP dump.xml file.\n"; print "If screenshots were already in, remove them first, you can use the command:\n"; print "./spip_screenshot_remove.pl dump.xml > dump2.xml\n"; # Cleanup unlink $tmp_file; exit 0;