load_plugin_textdomain

Sponsored Link

プラグインの翻訳された文字列を読み込みます。

Sponsored Link

Loads the plugin’s translated strings.

パスが指定されていない場合、プラグインディレクトリーのルートになります。
.moファイルはダッシュによって続いたドメインに基づいて名前を付ける必要があり、その上正確なロケールです。ロケールは言語コード或いは、wp-config.phpファイル内のWPLANG定数に定義されている国のコードです。例えば、ドイツ語のロケールならば’de_DE’であり、デンマーク語は’da_DK’です。プラグインのテキストドメインがデンマーク語の.mo と.poファイルの”my-plugin”であった場合、”my-plugin-da_DK.mo”と”my-plugin-da_DK.po”と指定すべきであり、プラグイン内にこの関数をより早期にplugins_loadedアクションを呼び出します。

If the path is not given then it will be the root of the plugin directory. The .mo file should be named based on the domain followed by a dash, and then the locale exactly. The locale is the language code and/or country code you defined in the constant WPLANG in the file wp-config.php. For example, the locale for German is ‘de_DE’, and the locale for Danish is ‘da_DK’. If your plugin’s text domain is “my-plugin” the Danish .mo and.po files should be named “my-plugin-da_DK.mo” and “my-plugin-da_DK.po” Call this function in your plugin as early as the plugins_loaded action.

同じドメインに複数回load_plugin_textdomainが呼び出された場合、翻訳はマージされます。両方のセットが同じ文字列を使用している場合、元の値から翻訳が取得されます。

If you call load_plugin_textdomain multiple times for the same domain, the translations will be merged. If both sets have the same string, the translation from the original value will be taken.

load_plugin_textdomainのファンクションタグ使用方法

<?php load_plugin_textdomain( $domain, $abs_rel_path, $plugin_rel_path ) ?>

load_plugin_textdomainのパラメーター

$domain

(string) (required)翻訳された文字列を取得するための一意の識別子。
デフォルト:なし

(string) (required) Unique identifier for retrieving translated strings.
Default: None

$abs_rel_path

(string) (optional)存在する.moファイルへのフォルダーのABSPATHへの相対パスです。廃止されましたが、2.7まで機能がありました。
デフォルト:false

(string) (optional) Relative path to ABSPATH of a folder, where the .mo file resides. Deprecated, but still functional until 2.7
Default: false

$plugin_rel_path

(string) (optional)末尾にスラッシュがついてる、WP_PLUGIN_DIRへの相対パス。これは使用するための優先引数です。それが優先度を取得します。

(string) (optional) Relative path to WP_PLUGIN_DIR, with a trailing slash. This is the preferred argument to use. It takes precendence over

$abs_rel_path

デフォルト:false

Default: false

戻り値

(void)
この関数は値を返しません。

(void)
This function does not reurn a value.

function myplugin_init() {
  load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) ); 
}
add_action('plugins_loaded', 'myplugin_init');

あるいは、サブフォルダ内に言語ファイルを置きたい場合。

Or if you’d like to put language files in a sub folder.

load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

注意

l10nは、ローカリゼーションの省略形です。

l10n is an abbreviation for localization.

変更ログ

Since: 1.5.0
2.7.0: ‘$abs_rel_path’はパラメータは廃止されました。

Since: 1.5.0
2.7.0: ‘$abs_rel_path’ parameter was deprecated.

ソースファイル

load_plugin_textdomain()は、wp-includes/l10n.php内に位置しています。

load_plugin_textdomain() is located in wp-includes/l10n.php.

関連ファンクションタグ

Localization: get_locale(), load_default_textdomain(), load_plugin_textdomain(), load_textdomain(), load_theme_textdomain()

Sponsored Link