2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package pre2par
::language
;
23 ##############################################################
24 # Returning a specific language string from the block
26 ##############################################################
28 sub get_language_string_from_language_block
30 my ($language_block, $language) = @_;
34 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
37 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
40 $newstring = "\"" . $newstring . "\"";
45 # defaulting to english!
47 if ( $newstring eq "" )
49 $language = "en-US"; # defaulting to english
51 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
53 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*(\".*\")\s*$/ )
64 ############################################
65 # collecting all replace variables
67 ############################################
69 sub get_all_replace_variables
75 for ( my $i = 0; $i <= $#{$langfile}; $i++ )
77 if ( ${$langfile}[$i] =~ /^\s*\[\s*(.*?)\s*\]\s*$/ )
80 # print "lang block '$variable'\n";
84 # Store the complete block in all languages for a specified variable
85 for ( $counter = $i + 1; $counter <= $#{$langfile}; $counter++ ) {
86 my $line = ${$langfile}[$counter];
87 last if ($line =~ /^s*\[/); # next decl.
88 push @lang_block, $line;
90 # print "$variable = '@lang_block'\n";
91 $allvars{$variable} = \
@lang_block;
99 ############################################
100 # localizing the par file with the
101 # corresponding language file
102 ############################################
106 my ($parfile, $langfile) = @_;
108 my $replace_hash = get_all_replace_variables
($langfile);
110 # parse lines of the form Name (st) = STR_NAME_MODULE_HELPPACK_OC;
111 # for variable substitution
112 my $langlinere = qr/^\s*\w+\s*\(([\w-]+)\)\s*\=\s*([\w-]+)\s*;/;
113 for ( my $i = 0; $i <= $#{$parfile}; $i++ )
115 my $oneline = ${$parfile}[$i];
117 if ( $oneline =~ $langlinere) {
118 my $language = $1; # can be "01" or "en" or "en-US" or ...
121 # print "line '$oneline' split to '$language' '$variable'\n";
123 if (defined $replace_hash->{$variable}) {
124 my $newstring = get_language_string_from_language_block
($replace_hash->{$variable}, $language);
125 if ( $newstring eq "" ) { $newstring = "\"" . $variable . "\""; }
127 $oneline =~ s/$variable/$newstring/g;
129 ${$parfile}[$i] = $oneline;