2017-09-06 10 views
1

xgettextツールを使用すると、適切な名前に関する翻訳者を支援するコメントを自動的に追加することができます()。proper_nameの--keywordに特定のコンテキストを割り当てる方法は?

ドキュメントは、コマンドラインに以下を追加することを提案:

このような .potファイルに抽出された適切な名前になり
--keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' 

#. This is a proper name. See the gettext manual, section Names. 
#: ../Foo.cpp:18 
msgid "Bob" 
msgstr "" 

これに伴う問題。その文字列に対して特定のコンテキストが定義されていないことです。ここでは、適切な名前が抽出される方法に理想的です:

#. This is a proper name. See the gettext manual, section Names. 
#: ../Foo.cpp:18 
msgctxt "Proper Name" 
msgid "Bob" 
msgstr "" 

私は次のことを試みたが、成功しませんしました:

# Hoping that 0 would be the function name 'proper_name'. 
--keyword='proper_name:0c,1,"This is a proper name. See the gettext manual, section Names."' 

# Hoping that -1 would be the function name 'proper_name'. 
--keyword='proper_name:-1c,1,"This is a proper name. See the gettext manual, section Names."' 

# Hoping that the string would be used as the context. 
--keyword='proper_name:"Proper Name"c,1,"This is a proper name. See the gettext manual, section Names."' 

# Hoping that the string would be used as the context. 
--keyword='proper_name:c"Proper Name",1,"This is a proper name. See the gettext manual, section Names."' 

は、すべてのために使用される特定のmsgctxtを強制する方法はありますキーワードで抽出された文字列(上記の例のproper_nameなど)?その後、私はおそらく使用して考えられているとして、

xgettextでこれを達成するためのオプションはありません場合は、以下:

--keyword='proper_name:1,"<PROPERNAME>"' 

を有する得られた:

#. <PROPERNAME> 
#: ../Foo.cpp:18 
msgid "Bob" 
msgstr "" 

問題はその後になり、自動的に次のように結果の.potファイルにこれのすべての出現を変換する方法:

#. This is a proper name. See the gettext manual, section Names. 
#: ../Foo.cpp:18 
msgctxt "Proper Name" 
msgid "Bob" 
msgstr "" 

答えて

1

を使用すると、メッセージのコンテキストを抽出したい場合は、引数リストの一部である必要があります。また、 "Nc"の数値部分は正の整数でなければなりません。 0、-1でのあなたの試行はすべて無駄です、申し訳ありません。

あなたの関数のシグネチャは次のようになります。

#define PROPER_NAME "Proper Name" 
const char *proper_name(const char *ctx, const char *name); 

をし、このようにそれを呼び出す:

すべてのコードの上にPROPER_NAMEを繰り返し、それが取得する唯一の方法だ
proper_name(PROPER_NAME, "Bob"); 

それをメッセージコンテキストに追加します。

多分、機能リクエストを提出しますか?

ソースコードを変更せずに同じことを実現するハックもあります。 POTFILES-proper-names

コピーしたファイルPOTFILESPOTFILES.inに行./proper_names.potを追加:私はあなたがCおよび標準のMakefileを使用している(ただし、他の言語で同じことを行うことができます)ことを前提としています。

xgettext --files-from=POTFILES-proper-names \ 
     --keyword='' \ 
     --keyword='proper_names:1:"Your comment ..."' \ 
     --output=proper_names.pox 

これは今だけ「proper_names()」を集約したエントリが含まれます。

その後、あなたはproper_names.potを作成する必要があります。今すぐコンテキストを追加します。

msg-add-content proper_names.pox "Proper Name" >proper_names.pot 
rm proper_names.pot 

残念ながら、「MSG-アドオンコンテンツ」と呼ばれるプログラムはありません。膨大な数のポーパーサーのうちの1人をそこにつかんで、あなた自身で書く(またはこの記事の最後に私のものを取る)。

いつものようにPACKAGE.potを更新してください。 "proper_names.pox"はメインxgettextの実行のための入力ファイルなので、コンテキストが追加された適切な名前がすべてあなたのポットファイルに追加されます(コンテキストも使用されます)。 .POTファイル内のすべてのエントリへのメッセージコンテキストを追加するための別のスクリプトのショート

、このいずれかを使用します。

あなたはそれのためのPerlライブラリ「ロケール:: PO」をインストールする必要が
#! /usr/bin/env perl 

use strict; 

use Locale::PO; 

die "usage: $0 POFILE CONTEXT" unless @ARGV == 2; 

my ($input, $context) = @ARGV; 

my $entries = Locale::PO->load_file_asarray($input) or die "$input: failure"; 
foreach my $entry (@$entries) { 
    $entry->msgctxt($context) unless '""' eq $entry->msgid; 
    print $entry->dump; 
} 

、 「sudo cpan install Locale :: PO」を使用するか、ベンダーが持つ可能性があるビルド済みバージョンを使用してください。

関連する問題