Linux あれこれ

Linux 関連(一部 Windows11 )の備忘録です。

Lubuntu 20.04 LTS にて「Update Notifier」のpot ファイルを再作成して再翻訳〈H48〉

登録日: 2020-05-14 更新日: 2020-05-15

公開されたばかりの「Lubuntu 20.04 LTS」をUSB メモリにインストールしました。

新しくシステム更新を通知するアプリが登場しました。便利になりましたが、日本語化はまだのようです。「Update Notifier」アプリの翻訳ファイルが古いようなので、pot ファイルを再作成して翻訳し直してみました。その備忘録で、当然ながら自己責任です。

翻訳の国際化(i18n) で使う「gettext」と「intltool」のツールの勉強になりました。

-

「目次」

-


「Update Notifier」ダイアログの日本語化

定期的(1時間ごと?)に自動でシステム更新があるかをチェック、システム更新があると更新するかダイアログが表示されます。更新するタイミングを選べるのはありがたいです。

→ただし、日本語化はまだです。

和訳:

                「アップデートの通知」

利用可能なアップグレードがあります。 システムのアップグレードを行いますか?
パッケージをアップグレード、インストール、または削除できます。

           「アップグレード」    「閉じる」

→閉じておいて、再表示まで待ってもよいし、下記のように、メニューから手動で更新できます。

設定→「Apply Full Upgrade」→下記画面が表示。

→日本語化されていません。

-

前回の翻訳 ( lubuntu-upgrader の修正 )が完了していれば:

設定→「すべてのアップグレードの適用」→下記画面が表示。

-


システム更新を通知するアプリ「update-notifier」

翻訳ファイルはあるけど、なぜか日本語表示されません。ちなみに、システムのインストール後の設定でfcitx-mozc の右クリックのメニューが日本語化されていないので、追加で「language-pack-gnome-ja」をインストールしました。

普通は重ならないはずですが、フォルダ違いで同じ名前の翻訳ファイルが2つあります。どちらかが余分…。 langpack でない方が古いけど行数が多く、langpack の方が新しくて行数が少ないです。

確か、langpack の方が優先度は低かったと記憶してます。

2つの翻訳ファイル:

-rw-r--r-- 1 root root 11792  4月  2 20:25 /usr/share/locale/ja/LC_MESSAGES/update-notifier.mo
-rw-r--r-- 1 root root 10582  4月 17 16:11 /usr/share/locale-langpack/ja/LC_MESSAGES/update-notifier.mo

-

翻訳ファイルの中身を確認したいので:

$ whereis update-notifier
update-notifier: /usr/lib/update-notifier /etc/update-notifier /usr/share/update-notifier

→翻訳ファイルが対応しているアプリが存在していることを確認。

-


1. gettext ツールのインストール:

$ sudo apt update
$ sudo apt install gettext
:
提案パッケージ:
  gettext-doc autopoint libasprintf-dev libgettextpo-dev
以下のパッケージが新たにインストールされます:
  gettext libcroco3

-


.mo を .po に変換するには:
$ msgunfmt messages.mo -o messsages.po

-


.po を .mo に変換するには:
$ msgfmt messages.po -o messsages.mo

-


mo を po に変換して中身を見てみると翻訳日付が古いです。

翻訳ファイルはあるけど、翻訳されずに英語のメッセージが表示されるのは、そのメッセージが翻訳ファイルに登録されていないからだと思われます。最新のソースから、翻訳の元になる「pot ファイル」を再作成、再度翻訳する必要がありそう。

-


2. update-notifier のソースを入手:

» Ubuntu » パッケージ » focal (20.04LTS) » ソース » gnome » update-notifier

最新のソースパッケージ: update-notifier (3.192.30)

-


「update-notifier-3.192.30」のソースをダウンロード:

update-notifier_3.192.30.tar.xz 03-Apr-2020 13:38

-


チェックサムの確認:

$ md5sum update-notifier_3.192.30.tar.xz
4ce8daaef7358eccfdbbb54e2cf81b8e  update-notifier_3.192.30.tar.xz

-


ダウンロードした「update-notifier_3.192.30.tar.xz」を展開。

「~/ダウンロード/update/」配下にコピーして、右クリックで展開しました。

-


展開した中の、POTFILES.in の内容

  • 翻訳可能な文字列を含むソースファイルのリストになります。

ディレクトリー「po/」には、intltool で参照される「POTFILES.in」というファイルが(必要なので)存在します。 このファイルは、すべてのプログラムソースの中で、翻訳が必要だとマークされた文字列をもつファイルがどれかを指示するものです。(国際化対応しているソースの一覧になります)

$ cat ~/ダウンロード/update/update-notifier-3.192.30/po/POTFILES.in

内容:

# List of source files containing translatable strings.

# *grumpf* [type=] does not work because intltool-update does not
# know about anything but the types available in intltool-extract --help
[type=gettext/Shell] data/notify-reboot-required
[type=gettext/Shell] data/notify-updates-outdated
data/apt_check.py
data/apt-cdrom-check
data/cddistupgrader
src/crash.c
src/avahi.c
src/cdroms.c
src/hooks.c
src/livepatch.c
src/livepatch-tray.c
src/update.c
src/update-notifier.c
[type: gettext/glade]ui/hooks-dialog.ui
data/com.ubuntu.update-notifier.gschema.xml.in
data/com.ubuntu.update-notifier.policy.in
data/update-notifier.desktop.in
[type: gettext/rfc822deb] data/package-data-downloads-failed.in
[type: gettext/rfc822deb] data/package-data-downloads-failed-permanently.in

ソースには、python もあれば、c もあります。

→下記のintltool ツールをインストール後に「intltool-extract --help」を参照すると、ここで使われている[type: ] はサポート対象でした。

現在サポートしている、FILENAMEのファイルタイプ:

"gettext/glade", "gettext/ini", "gettext/keys","gettext/rfc822deb", "gettext/schemas","gettext/gsettings", "gettext/xml", "gettext/quoted","gettext/quotedxml", "gettext/tlk", "gettext/qtdesigner"

ちなみに、ペアとして、下記のファイルもありますが、中身は空でした。

~/ダウンロード/update/update-notifier-3.192.30/po/POTFILES.skip

-


3. intltool のインストール:

intltool は、国際化(Internationalization) のためのコマンド(ツール)群です。ちなみに、あの「intel」とは関係ありません。

$ sudo apt update

$ sudo apt install intltool
:
提案パッケージ:
  autoconf-archive gnu-standards autoconf-doc libtool m4-doc
以下のパッケージが新たにインストールされます:
  autoconf automake autotools-dev intltool libsigsegv2 m4

確認:

$ ls /usr/bin/intltool*
/usr/bin/intltool-extract  /usr/bin/intltool-prepare  /usr/bin/intltoolize
/usr/bin/intltool-merge    /usr/bin/intltool-update

$ whereis intltool-update
intltool-update: /usr/bin/intltool-update /usr/share/man/man8/intltool-update.8.gz

-


intltool で使えるコマンド:

  • 詳細は、「man」や「--help」で確認できます。
intltoolize

→パッケージに対して intltool を利用できる環境にします。

-

intltool-extract

→gettext が読み込むことの出来るヘッダーファイルを生成します。

-

intltool-merge

→翻訳された文字列を様々な種類のファイルにマージします。

-

intltool-prepare

→pot ファイルを更新し、翻訳ファイルにマージします。

-

intltool-update

→po テンプレートファイル(.pot) を更新し、翻訳ファイルにマージします。

-


4. intltoolize の実行前に、作業ディレクトリをパッケージの最上位ディレクトリに変更:

$ cd ~/ダウンロード/update/update-notifier-3.192.30/

$ ls
AUTHORS    HOOKS        NEWS            TODO         configure.ac  pixmaps  tests
COPYING    INSTALL      README          autogen.sh   data          po       ui
ChangeLog  Makefile.am  README.testing  config.h.in  debian        src

-


5. intltoolを使えるようにパッケージを準備:

$ intltoolize -c

You should add the contents of '/usr/share/aclocal/intltool.m4' to 'aclocal.m4'.

-c (--copy) : ファイルへのシンボリックリンクを作成するのではなく、ファイルをコピーします。

和訳:「/usr/share/aclocal/intltool.m4」の内容を「aclocal.m4」に追加する必要があります。

→いつも出るメッセージみたい。無視してよさそう。

→「po/Makefile.in.in」が作成されました。

-


6. intltool-update の実行前に、作業ディレクトリを翻訳を含むディレクトリ(「po/」)に変更:

$ cd po/

-


7. ソースコードからpoテンプレート(.pot)を生成:

$ intltool-update -p --verbose

-p (--pot) : poテンプレート(.pot)のみを生成

po/POTFILES.in が参照されます。 →翻訳可能な文字列を含むソースファイルのリストが1行に1つずつ含まれています。

xgettext コマンドだと、ひとつずつのファイル指定が必要ですが、intltool だとリストとして読み込まれるので楽です。

Wrote ../data/notify-reboot-required.h
Wrote ../data/notify-updates-outdated.h
Wrote ../ui/hooks-dialog.ui.h
Wrote ../data/com.ubuntu.update-notifier.gschema.xml.in.h
Wrote ../data/com.ubuntu.update-notifier.policy.in.h
Wrote ../data/update-notifier.desktop.in.h
Wrote ../data/package-data-downloads-failed.in.h
Wrote ../data/package-data-downloads-failed-permanently.in.h
Building update-notifier.pot...
Running xgettext --add-comments --directory=. --directory=. --default-domain=update-notifier --flag=g_strdup_printf:1:c-format --flag=g_string_printf:2:c-format --flag=g_string_append_printf:2:c-format --flag=g_error_new:3:c-format --flag=g_set_error:4:c-format --flag=g_markup_printf_escaped:1:c-format --flag=g_log:3:c-format --flag=g_print:1:c-format --flag=g_printerr:1:c-format --flag=g_printf:1:c-format --flag=g_fprintf:2:c-format --flag=g_sprintf:2:c-format --flag=g_snprintf:3:c-format --flag=g_scanner_error:2:c-format --flag=g_scanner_warn:2:c-format --output=update-notifier.pot --files-from=./POTFILES.in.temp --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 --keyword=Q_ --keyword=g_dgettext:2 --keyword=g_dngettext:2,3 --keyword=g_dpgettext:2 --keyword=g_dpgettext2=2c,3 --from-code=UTF-8
Removing generated header (.h) files...done.
Wrote update-notifier.pot

→「po/update-notifier.pot」が作成されました。

-


8. マージをするので、ファイルをコピーしてから作業

$ cd ~/ダウンロード/update/update-notifier-3.192.30/po/
$ cp ja.po ~/ダウンロード/update/
$ cp update-notifier.pot ~/ダウンロード/update/

-

$ cd ~/ダウンロード/update/
$ ls -l
:
-rw-rw-r-- 1 ubn ubn  14533  2月  4 11:27 ja.po  ←展開で入っていたpoファイル(日本語の翻訳)
-rw-rw-r-- 1 ubn ubn   9233  5月 13 06:37 update-notifier.pot  ←新しく作成したpot(英語の原本)
drwxrwxr-x 9 ubn ubn   4096  5月 11 16:17 update-notifier-3.192.30  ←展開されたフォルダ
-rw-rw-r-- 1 ubn ubn 254860  5月 11 16:13 update-notifier_3.192.30.tar.xz  ←ダウンロード

-


9. マージして ja.po を更新

$ cd ~/ダウンロード/update/

$ msgmerge ja.po update-notifier.pot -o ja-new.po
................ 完了.

→翻訳されているメッセージは使われますが、翻訳が怪しいものには fuzzy フラグが付きます。

自動的に1行のメッセージの長さが均等になるように行を切り直してくれます。 日本語の場合、行を整えるのは面倒です。行の分割を意識せず長いままにしておけるので工数削減になります。このためだけに翻訳ファイルを通すのもアリかも。

-


10. ja-new.po の編集

$ cd ~/ダウンロード/update/
$ featherpad ja-new.po

→fuzzy や翻訳されていないメッセージを翻訳しました。

ESM (Ubuntu Advantage のセキュリティ延長サポートサービス)関連のメッセージが増えていました。一部翻訳がズレている箇所もあり修正しました。マージで行がズレたのか、もともと翻訳を間違えていたのか、どちらにしても、全体的に目を通すのがいいみたい。

-


編集後の確認:

$ diff ja.po ja-new.po

→行番号はだいぶ変わっています。ソースが変わったということ。

-


新しく翻訳した部分の抜粋:

$ cd ~/ダウンロード/update/
$ cat ja-new.po

"POT-Creation-Date: 2020-05-14 05:52+0900\n"
:
:(コピーライトの行があるので省略)
:

Ubuntu (launchpad)で翻訳されたpo ファイルにはなぜかコピーライトの行がほとんど。気にせずにテンプレートを使っているのかもしれないけど、追加の翻訳であっても、公開できる場所が制限されていると貢献したいと思っていても手続きが面倒なので保留。結局は日本語化が遅れる…だろうな。個人的な感想。

-


11. 「.mo」に変換

$ cd ~/ダウンロード/update/
$ msgfmt ja-new.po -o update-notifier.mo

-


12. 念の為、原本を退避:

$ cd /usr/share/locale/ja/LC_MESSAGES/
$ sudo cp update-notifier.mo update-notifier.mo-ORG

-


13: 配置:

$ cd ~/ダウンロード/update/ $ sudo cp update-notifier.mo /usr/share/locale/ja/LC_MESSAGES/

-


14: 確認:

再起動して確認。

-


まとめ

翻訳ファイルのメッセージは増えましたが、肝心のインストールした直後の再起動で表示された「アップデートの通知」ダイアログの、長めの英語のメッセージとか、ボタンの文字列とかは、含まれていませんでした。

翻訳対象とは違うモジュールからのメッセージが他にあるみたい。そのあたりは次回…。

-

-


目次

先頭

-


-