状況に応じて、カスタム翻訳ファイルを自分で維持管理して使用することができます。これを行うメリットは、全てのユーザー向け文字列 (カスタムフィールドを含む) が適切に翻訳されることです。デメリットは、プラグインに変更が加えられた場合はカスタム翻訳ファイルをあなたが最新の状態に保たなければならないことです。私も翻訳に影響を与える変更は行わないように努めていますが、やむを得ない場合もあります。
カスタム翻訳ファイルを維持管理するには、まずはpolyglotsプロジェクトで使用可能なあなたの言語を見に行きましょう。サイトから.poファイルをダウンロード (エクスポート) します。次に Poeditなどのツールを使用して必要な文字列を追加して翻訳できます。Poedit は保存時にこれを.moファイルとしてコンパイルします。.po はテンプレートファイルで、.moは翻訳を表示するために必要な機械読み取り可能なコンパイル済みファイルです。
Poedit は無料ですが、プレミアム版もあります。上記作業を行うには無料版のみで十分ですが有料版をお勧めします。まず、追加機能があります。 そして第二に、それがプロジェクトを支援することになるからです。(個人的な価値基準に従い、私はプログラムの有料版を持っています。自分で所有して使用していない製品はお勧めしません。)
カスタム翻訳ファイル一式を作成したら、次の2つのことを行う必要があります。:
- ファイルを Web サーバー上に読み込みます。
- フィルターを設定して、デフォルトファイルの代わりにカスタムファイルを読み込むようにプラグインに指示します。
カスタム翻訳ファイルはサーバー上のどこにでも置くことができますが、wp-content ディレクトリ内のどこかに置くことをお勧めします。子テーマを使用する場合は通常は触れられない場所が適しています。WP Media Manager経由でアップロードし、その場所をメモすることもできます。基本的に、上書きされる可能性のある場所 (つまりwp-membersフォルダーの外) にない限り特定の WP インストールに基づいて正しいことを行ってください。
カスタムファイルが「wp-members-{locale}.mo」であることを確認してください。たとえば、標準ドイツ語は「de_DE」なので、ファイルは wp-members-de_DE.mo になります (ハイフンとアンダースコアの違いに注意してください。これらは重要です)。
次にwpmem_localization_fileフィルターを使用して、カスタム翻訳ファイルを読み込むフィルターを設定します。これにより読み込まれる.moファイルの場所がフィルタリングされます。このフィルターには現在の $locale 値 のパラメーターが追加されているため、多言語サイトに役立ちます(プラグインのロケール情報が正しい限り) 。ドキュメント内のフィルターは「そのまま」使用できます。 カスタムファイルを保存した場所に基づいてパスを必ず調整してください。
原文を見る
ou can maintain a custom translation file for your situation. The upside to doing this is that you have a proper translation of all user facing strings (including custom fields). The downside is that you need to make sure you keep it up to date if any changes are made in the plugin. I try not to make changes affecting translation, but sometimes it is unavoidable.
To maintain a custom translation file, you can start from what is available in your language at the polyglots project. Download (export) the .po file from the site. Then, using a tool like Poedit, you can add your necessary strings and translate them. Poedit will compile this as an .mo file when you save it. The .po is your template file, the .mo is the machine readable compiled file necessary to display translations.
Poedit is free, and there is a premium version as well. You only need the free version to do this, but I recommend the paid version. First, there are additional features; and second, it supports the project. (In keeping with my personal standards, I have a paid version of the program. I don’t recommend products that I don’t own and use myself.)
Once you create a set of custom translation files, you’ll need to do two things:
- Load the files to a location on your web server,
- Set up a filter to tell the plugin to load your custom file instead of the default file.
Custom translation files can live anywhere on your server, but I recommend that you put them somewhere in the wp-content directory. If you use a child theme, that’s a good location that isn’t generally touched. You can also upload via the WP Media Manager and make note of that location. Essentially, do what is right based on your specific WP install as long as they are not in a location that would be overwritten (i.e. not the wp-members folder).
Make sure that your custom file is “wp-members-{locale}.mo”. For example, a standard German is “de_DE” so your file would be wp-members-de_DE.mo (make careful note of the difference between hyphens and underscores – these are critical).
Then set up a filter to load your custom translation file using the wpmem_localization_file filter. This filters the location of the .mo file being loaded. The filter has an added parameter of the current $locale, making it useful for multi-language sites (as long as the plugin locale is correct). You can use the filter in the documentation “as is.” Just make sure to adjust the path based on where you have saved your custom file.
https://rocketgeek.com/plugins/wp-members/docs/maintain-a-custom-translation-file/