Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:11.4
libreoffice-l10n
lo-l10n-gen-spec
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File lo-l10n-gen-spec of Package libreoffice-l10n
#!/usr/bin/perl -w # This script changes the definite article of ProductName use strict; sub init_lang_data($$$$) { my ($datap, $lang_code, $long_name, $level) = @_; my $curLang; my $locale; # we support the syntax: package_lang_code[/ooo_source_lang_code] if ($lang_code =~ m/([\w\-]+)\/?([\w\-]+)?/) { $curLang = "$1"; if (defined $2) { $locale = "$2"; } else { $locale = $curLang; $locale =~ s/-/_/g; } } else { die "Syntax error: unknown format of the language code: $lang_code, line $."; } $datap->{$curLang}{'long_name'} = $long_name; $datap->{$curLang}{'level'} = $level; $datap->{$curLang}{'locale'} = $locale; $datap->{$curLang}{'package-l10n'} = (); $datap->{$curLang}{'package-help'} = (); return $curLang; } sub read_data($$) { my ($data_file, $datap) = @_; my $curLang; open DATA , "< $data_file" or die "Can't open '$data_file'\n"; while( my $line = <DATA>){ chomp $line; $line =~ s/#.*//; # remove comments if ($line =~ m/^\s*\%lang\s+([\w\-\/]+)\s+(\w+)\s+(\d+)\s*$/ ) { # long name without without quotation marks, e.g. %lang de German 1 $curLang = init_lang_data($datap, "$1", "$2", "$3"); } elsif ( $line =~ m/^\s*\%lang\s+([\w\-\/]+)\s+\"([\w\s]+)\"\s+(\d+)\s*$/ ) { # long name with with quotation marks, e.g. %lang br "Breton French" 2 $curLang = init_lang_data($datap, "$1", "$2", "$3"); } elsif ( $line =~ /^\s*\%poor-help\s*$/ ) { $datap->{$curLang}{'poor-help'} = 1; } elsif ( $line =~ /^\s*\%package-l10n\s+(.*)$/ ) { push @ {$datap->{$curLang}{'package-l10n'}}, "$1"; } elsif ( $line =~ /^\s*\%package-help\s+(.*)$/ ) { push @ {$datap->{$curLang}{'package-help'}}, "$1"; } elsif ( $line =~ /^\s*\%files-l10n\s+(.*)$/ ) { push @ {$datap->{$curLang}{'files-l10n'}}, "$1"; } elsif ( $line =~ /^\s*\%files-help\s+(.*)$/ ) { push @ {$datap->{$curLang}{'files-help'}}, "$1"; } elsif ( $line =~ /^\s*$/ ) { # ignore empty line } else { die "Synrax error in $data_file, line $.\n"; } } close(DATA); } sub write_generated_section_start($) { my ($pARGV) = @_; print "####################################################\n"; print "# DO NOT EDIT THIS SECTION!\n"; print "# Start of a section generated by\n"; print "# lo-l10n-gen-spec " . join(' ', @{$pARGV}) . "\n"; print "####################################################\n"; } sub write_generated_section_end() { print "####################################################\n"; print "# End of a section generated by lo-l10n-gen-spec\n"; print "####################################################\n"; print "\n"; } sub write_section_comment($) { my ($section_name) = @_; print "#\n"; print "# $section_name\n"; print "#\n"; print "\n"; } sub write_level_begin($$) { my ($curLevel, $newLevel) = @_; if ($curLevel != $newLevel) { print "\n"; print "%endif\n" if ($curLevel > 0); print "%if %test_build_langs >= $newLevel\n" if ($newLevel > 0); } return $newLevel; } sub write_level_end($) { my ($curLevel) = @_; if ($curLevel > 0) { print "%endif\n"; } return 0; } sub write_l10n_package_section($$) { my ($datap, $curLang) = @_; return if ("$curLang" eq "en-US"); # we do not have the l10n-en-US package print "\n"; print "%package -n libreoffice-l10n-$curLang\n"; print "License: LGPLv3\n"; print "Summary: $datap->{$curLang}{'long_name'} Localization Files for LibreOffice\n"; print "Group: Productivity/Office/Suite\n"; print "Provides: locale(libreoffice:$datap->{$curLang}{'locale'})\n"; print "PreReq: libreoffice-ure = %version\n"; print "# compat stuff\n"; print "Provides: OpenOffice_org-l10n-$curLang = %version\n"; print "Obsoletes: OpenOffice_org-l10n-$curLang <= %version\n"; print "Provides: OpenOffice_org-$curLang:%_prefix/ooo-2.0/program/resource/sw680$curLang.res\n"; print "Provides: OpenOffice_org-$curLang = %version\n"; print "Obsoletes: OpenOffice_org-$curLang <= %version\n"; foreach my $line (@{$datap->{$curLang}{'package-l10n'}}) { print "$line\n"; } print "\n"; print "%description -n libreoffice-l10n-$curLang\n"; print "$datap->{$curLang}{'long_name'} localization files for LibreOffice.\n"; print "The localized help content is in libreoffice-help-$curLang.\n" unless (defined $datap->{$curLang}{'poor-help'}); print "\n"; print "\n"; } sub write_help_package_section($$) { my ($datap, $curLang) = @_; my $oldPackage; return if (defined $datap->{$curLang}{'poor-help'}); if ("$curLang" eq "en-US") { $oldPackage = "OpenOffice_org"; } else { $oldPackage = "OpenOffice_org-$curLang"; } print "\n"; print "%package -n OpenOffice_org-help-$curLang\n"; print "License: LGPLv3\n"; print "Summary: $datap->{$curLang}{'long_name'} Help Localization for LibreOffice\n"; print "Group: Productivity/Office/Suite\n"; print "Provides: locale(OpenOffice_org:$datap->{$curLang}{'locale'})\n"; print "Provides: $oldPackage:%_prefix/ooo-2.0/help/cs/default.css\n"; print "PreReq: OpenOffice_org-ure = %version\n"; print "Supplements: OpenOffice_org-l10n-$curLang\n"; foreach my $line (@{$datap->{$curLang}{'package-help'}}) { print "$line\n"; } print "\n"; print "%description -n OpenOffice_org-help-$curLang\n"; print "$datap->{$curLang}{'long_name'} help localization for LibreOffice. The other localized stuff\n"; print "is in libreoffice-l10n-$curLang.\n"; print "\n"; print "\n"; } sub write_l10n_scripts_section($$) { my ($datap, $curLang) = @_; return if ("$curLang" eq "en-US"); # we do not have the l10n-en-US package print "# $curLang\n"; print "%posttrans -n libreoffice-l10n-$curLang\n"; print "%_datadir/%ooo_home/link-to-ooo-home %_datadir/%ooo_home/files-l10n-$datap->{$curLang}{'locale'}.txt || true\n"; print "\n"; print "%preun -n libreoffice-l10n-$curLang\n"; print "test \"\$1\" = \"0\" && cp %_datadir/%ooo_home/files-l10n-$datap->{$curLang}{'locale'}.txt %_datadir/%ooo_home/files-l10n-$datap->{$curLang}{'locale'}.txt.postun || true\n"; print "\n"; print "%postun -n libreoffice-l10n-$curLang\n"; print "test \"\$1\" = \"0\" && %_datadir/%ooo_home/link-to-ooo-home --unlink %_datadir/%ooo_home/files-l10n-$datap->{$curLang}{'locale'}.txt.postun || true\n"; print "rm -f %_datadir/%ooo_home/files-l10n-$datap->{$curLang}{'locale'}.txt.postun 2>/dev/null\n"; } sub write_help_scripts_section($$) { my ($datap, $curLang) = @_; return if (defined $datap->{$curLang}{'poor-help'}); print "# $curLang\n"; print "%posttrans -n libreoffice-help-$curLang\n"; print "%_datadir/%ooo_home/link-to-ooo-home %_datadir/%ooo_home/files-help-$datap->{$curLang}{'locale'}.txt || true\n"; print "\n"; print "%preun -n libreoffice-help-$curLang\n"; print "test \"\$1\" = \"0\" && cp %_datadir/%ooo_home/files-help-$datap->{$curLang}{'locale'}.txt %_datadir/%ooo_home/files-help-$datap->{$curLang}{'locale'}.txt.postun || true\n"; print "\n"; print "%postun -n libreoffice-help-$curLang\n"; print "test \"\$1\" = \"0\" && %_datadir/%ooo_home/link-to-ooo-home --unlink %_datadir/%ooo_home/files-help-$datap->{$curLang}{'locale'}.txt.postun || true\n"; print "rm -f %_datadir/%ooo_home/files-help-$datap->{$curLang}{'locale'}.txt.postun 2>/dev/null\n"; } sub write_l10n_files_section($$) { my ($datap, $curLang) = @_; return if ("$curLang" eq "en-US"); # we do not have the l10n-en-US package print "\n"; print "%files -f files-l10n-$datap->{$curLang}{'locale'}.txt -n libreoffice-l10n-$curLang\n"; print "%defattr(-,root,root)\n"; foreach my $line (@{$datap->{$curLang}{'files-l10n'}}) { print "$line\n"; } } sub write_help_files_section($$$) { my ($datap, $curLang) = @_; return if (defined $datap->{$curLang}{'poor-help'}); print "\n"; print "%files -f files-help-$datap->{$curLang}{'locale'}.txt -n libreoffice-help-$curLang\n"; print "%defattr(-,root,root)\n"; foreach my $line (@{$datap->{$curLang}{'files-help'}}) { print "$line\n"; } } sub write_lang_section($$$) { my ($datap, $write_single_lang_section, $section_name) = @_; my $curLevel = 0; write_section_comment($section_name); foreach my $curLang (sort keys %{$datap}) { $curLevel = write_level_begin($curLevel, $datap->{$curLang}{'level'}); & {$write_single_lang_section} ($datap, $curLang); } $curLevel = write_level_end($curLevel); } sub usage() { print "This tool generates pieces of the l10n and help spec files\n\n" . "Usage:\n". "\tooo-l10n-gen-spec [--help] [--gen-l10n|--gen-help] data_file...\n\n" . "Options:\n" . "\t--help: prints this help\n" . "\t--gen-l10n: print onyl the l10n pieces\n" . "\t--gen-help: print only the help pieces\n" . "\tdata_file: input file\n"; } # info about localizations # it is a hash, the key is the lang id, e.g. "en-US", the value is: # a hash, keys introduce perl-like structure items: # 'long_name' ... string, long name of the language, e.g. "American" # 'level' ... integer, level in whih it should get build, e.g. '1' # it is the level in the rpm spec to do a reduced build # 'locale' ... string, it is the code used by the upstream sources; # it is usually the lang id with undersore instead of dash, # e.g. "en_US"; ot it might differ from the package lang code if # upstream renamed it later, for example, "gu-IN" was renamed to # "gu" in ooo320-m5 # 'poor-help' ... integer, is defined when the help is poor and the help package # is not created # 'package-l10n' ... array of strings that should be added to the %package section for # the given language # 'package-help' ... array of strings that should be added to the %package section for # the given help package # 'files-l10n' ... array of strings that should be added to the %files section for # the given language # 'package-help' ... array of strings that should be added to the %files section for # the given help package my %data; my $l10n = 1; my $help = 1; for my $arg (@ARGV) { if ($arg eq '--help' || $arg eq '-h') { usage; exit 0; } elsif ($arg =~ m/--gen-l10n/) { $l10n = 1; $help = 0; } elsif ($arg =~ m/--gen-help/) { $l10n = 0; $help = 1; } else { if (-f $arg) { read_data($arg, \%data); } else { die "File does not exist: $arg\n"; } } } write_generated_section_start(\@ARGV); write_lang_section(\%data, \&write_l10n_package_section, "l10n packages") if ($l10n); write_lang_section(\%data, \&write_help_package_section, "help packages") if ($help); write_generated_section_end(); write_generated_section_start(\@ARGV); print "# FIXME: call script that links noarch stuff to the ooo-home\n"; print "# it will be better to fix OOo to find the noarch stuff\n"; print "# on the right place\n"; print "\n"; write_lang_section(\%data, \&write_l10n_scripts_section, "l10n scripts") if ($l10n); write_lang_section(\%data, \&write_help_scripts_section, "help scripts") if ($help); write_lang_section(\%data, \&write_l10n_files_section, "l10n files") if ($l10n); write_lang_section(\%data, \&write_help_files_section, "help files") if ($help); write_generated_section_end();
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor