- 1. 概要
- 2. 項目名日本語化・・・できない
- 3. 苦し紛れ
1. 概要
前の方のページで、メニューのカテゴリ名を編集しましたが・・・。

やはり、カテゴリ名だけでは、つらい。
項目名も、日本語化したいな・・・と。
2. 項目名日本語化・・・できない
「Application menu for Openbox - Void Linux Wiki」やら「obmenu-generator」あたりを読むと。
~/.config/obmenu-generator/config.pl
をいじればいいように書いています。
デフォルトの状態がこれで
#!/usr/bin/perl
# obmenu-generator - configuration file
# This file will be updated automatically.
# Any additional comment and/or indentation will be lost.
=for comment
|| FILTERING
| skip_filename_re : Skip a .desktop file if its name matches the regex.
Name is from the last slash to the end. (e.g.: name.desktop)
Example: qr/^(?:gimp|xterm)\b/, # skips 'gimp' and 'xterm'
| skip_entry : Skip a desktop file if the value from a given key matches the regex.
Example: [
{key => 'Name', re => qr/(?:about|terminal)/i},
{key => 'Exec', re => qr/^xterm/},
{key => 'OnlyShowIn', re => qr/XFCE/},
],
| substitutions : Substitute, by using a regex, in the values from the desktop files.
Example: [
{key => 'Exec', re => qr/xterm/, value => 'tilix', global => 1},
],
|| ICON SETTINGS
| gtk_rc_filename : Absolute path to the GTK configuration file.
| missing_icon : Use this icon for missing icons (default: gtk-missing-image)
| icon_size : Preferred size for icons. (default: 48)
| generic_fallback : Try to shorten icon name at '-' characters before looking at inherited themes. (default: 0)
| force_icon_size : Always get the icon scaled to the requested size. (default: 0)
|| PATHS
| desktop_files_paths : Absolute paths which contain .desktop files.
Example: [
'/usr/share/applications',
"$ENV{HOME}/.local/share/applications",
glob("$ENV{HOME}/.local/share/applications/wine/Programs/*"),
],
|| NOTES
| Regular expressions:
* use qr/.../ instead of '...'
* use qr/.../i for case insensitive mode
=cut
our $CONFIG = {
"editor" => "geany",
"force_icon_size" => 0,
"generic_fallback" => 0,
"gtk_rc_filename" => "$ENV{HOME}/.gtkrc-2.0",
"icon_size" => 32,
"Linux::DesktopFiles" => {
desktop_files_paths => [
"/usr/share/applications",
"/usr/local/share/applications",
"/usr/share/applications/kde4",
"$ENV{HOME}/.local/share/applications",
],
gtk_rc_filename => "$ENV{HOME}/.gtkrc-2.0",
icon_dirs_first => undef,
icon_dirs_last => undef,
icon_dirs_second => undef,
keep_unknown_categories => 1,
skip_entry => [{ key => "Name", re => qr/^(Qt4?\b)/ }],
skip_filename_re => qr/^(mugshot|menulibre|xfce-keyboard-settings|xfce-backdrop-settings|xfce4-accessibility-settings|xfce-settings-editor|xfce-wmtweaks-settings|xfce-wm-settings|xfce-workspaces-settings|xfce4-about|xfce4-session-logout|bssh|bvnc|avahi-discover|logdconf|ffadomixer|gconf|urxvt|xterm|uxterm|compton)/,
skip_svg_icons => 0,
strict_icon_dirs => undef,
substitutions => undef,
terminalization_format => "%s -e '%s'",
terminalize => 1,
unknown_category_key => "other",
},
"locale_support" => 1,
"missing_icon" => "gtk-missing-image",
"terminal" => "termite",
"VERSION" => 0.85,
}
77行目と78行目との間に
"name_keys" => ['Name[it]', 'GenericName[it]', 'Name'],
てな、行をいれればいいと書いてあります。
当然、[it] の箇所は [ja] にするわけですが・・・。
編集後
obmenu-generator -i -s -c
を流しなさい・・・と(これ、GUI ログインして端末を開いてやらないとエラーになります)。
やってみると・・・。

カテゴリにアイコンがついたのは、うれしくないわけでもないが・・・、目的とは違うのだ。
3. 苦し紛れ
思った通りにならないので・・・苦し紛れ・・・。
どうやら、メニューの項目名は、大多数は
/usr/share/applications/
内の、.desktop (Unix・Linux では一般的です)の項目名定義ファイルの
Name=
の値を表示していることが分かりました(書き換えて確認・・・)。
いささか強引ではありますが、.desktop ファイルを書き換えちゃえばいいわけで。
かと言って、ひとつひとつ手書きで書くのは骨が折れますので・・・。
スクリプトを書くことにしました。
perl のスクリプトを書くのは久しぶりです。
まず、書き換えように「/usr/share/applications/」のファイルを「~/.local/share/applications/」にコピーしてやります。
cp /usr/share/applications/* ~/.local/share/applications/.
前項の「~/.config/obmenu-generator/config.pl」の 55~60行目で、もともと「~/.local/share/applications/」にあるファイルは読みこんで処理することになっています。
スクリプトファイルの内容は
#!/usr/bin/perl
BEGIN
{
use lib './';
};
use strict;
use FileList;
my $ext = 'desktop';
sub main
{
my @argv = @_;
my $root = $argv[0];
my $list = FileList->new();
my $filelist = $list->get($root, $ext); # .desktop をリストする
foreach my $name (sort(@$filelist)) # 全 .desktop ファイルを処理
{
my $fh = IO::File->new();
my @read = undef;
if ($fh->open("< $name")) # 全行読込
{
@read = <$fh>;
$fh->close;
}
else
{
next;
}
my $item = undef;
my $janame = undef;
for my $line (@read) # Name= 取り出し
{
my ($title, $itemname) = split(/=/, $line);
if ($title eq 'Name') # Name=
{
if ($item == undef)
{
$janame = $itemname;
}
}
if ($title eq 'Name[ja]') # Name[ja]=
{
$janame = $itemname;
last;
}
}
my @write = undef; # 書込み内容
for my $line (@read) # Name= 取り出し
{
my ($title, $itemname) = split(/=/, $line);
if ($title eq 'Name') # Name=
{
if (defined($janame))
{
push(@write, "Name=$janame");
}
else
{
push(@write, $line);
}
}
else # Name= 以外はそのまま出力
{
push(@write, $line);
}
}
if ($fh->open("> $name")) # 書き込みオープン
{
print $fh @write; # 書き込み
$fh->close;
}
else
{
next;
}
# print "[$name][$item]\n";
}
}
main(@ARGV);
てな感じ。
使用している「FileList.pm」に関しては「perl - クラスライブラリ」の「ファイルをリスト」の項をご参照ください。
「FileList.pm」は、このスクリプトファイルと同じディレクトリにおいてください。
簡単に言うと、「*.desktop」のファイルを開いて「Name=項目名」の箇所の「項目名」を「Name[ja]=項目名」の名称に置き換えてやっているわけです。
こいつを実行して、obmenu-generator を流します。
perl スクリプトファイル名 ~/.local/share/applications/
obmenu-generator -i -s -c
その結果

日本語名のある、プログラムは、日本語名になりました。
|