61 lines
1.5 KiB
Diff
61 lines
1.5 KiB
Diff
--- xdg_menu
|
|
+++ xdg_menu
|
|
@@ -10,6 +10,7 @@
|
|
use Getopt::Long;
|
|
use Encode;
|
|
use I18N::Langinfo qw(langinfo CODESET);
|
|
+use Locale::gettext;
|
|
use POSIX qw(locale_h);
|
|
|
|
my $Version = "0.2";
|
|
@@ -23,6 +24,7 @@
|
|
my $language = '';
|
|
my $charset = 'iso-8859-1';
|
|
my $root_cmd = 'xdg_menu_su';
|
|
+my $default_textdomain;
|
|
|
|
my $die_on_error = 0;
|
|
my $verbose = 0;
|
|
@@ -1228,7 +1230,23 @@
|
|
return $desktop->{$loc_entry} if defined $desktop->{$loc_entry} && $desktop->{$loc_entry} !~ /^\s*$/;
|
|
}
|
|
|
|
- return $desktop->{$entry};
|
|
+ my $textdomain = $default_textdomain;
|
|
+
|
|
+ if ($desktop->{'X-SUSE-Gettext-Domain'}) {
|
|
+ $textdomain = Locale::gettext->domain_raw($desktop->{'X-SUSE-Gettext-Domain'});
|
|
+ $textdomain->codeset('UTF-8');
|
|
+ }
|
|
+
|
|
+ my $key = $desktop->{$entry};
|
|
+ my $file = $desktop->{'id'};
|
|
+ my $key_context = "$entry($file): $key";
|
|
+
|
|
+ my $translated = $textdomain->get($key_context);
|
|
+ if ($translated eq $key_context) {
|
|
+ $translated = $textdomain->get($key);
|
|
+ }
|
|
+
|
|
+ return $translated;
|
|
}
|
|
|
|
sub preprocess_menu ($)
|
|
@@ -2094,6 +2113,16 @@
|
|
"help" => \$help
|
|
);
|
|
|
|
+if (!setlocale(LC_MESSAGES, $language))
|
|
+ {
|
|
+ print STDERR "WARNING: invalid language '$language'\n";
|
|
+ $language = setlocale(LC_MESSAGES);
|
|
+ print STDERR "Falling back to '$language'\n";
|
|
+ }
|
|
+
|
|
+$default_textdomain = Locale::gettext->domain_raw("desktop_translations");
|
|
+$default_textdomain->codeset('UTF-8');
|
|
+
|
|
@language_keys = prepare_language_keys($language);
|
|
|
|
$desktop_name = $format unless defined $desktop_name;
|