diff --git a/languages/ga-communicator-ja.mo b/languages/ga-communicator-ja.mo index 9cdd3b5..3b187b9 100644 Binary files a/languages/ga-communicator-ja.mo and b/languages/ga-communicator-ja.mo differ diff --git a/languages/ga-communicator-ja.po b/languages/ga-communicator-ja.po index dc2c67e..fa4d54f 100644 --- a/languages/ga-communicator-ja.po +++ b/languages/ga-communicator-ja.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2024-01-11 16:35+0900\n" -"PO-Revision-Date: 2024-01-11 16:38+0900\n" +"POT-Creation-Date: 2024-01-30 14:00+0900\n" +"PO-Revision-Date: 2024-01-30 14:02+0900\n" "Last-Translator: Takahashi Fumiki \n" "Language-Team: \n" "Language: ja\n" @@ -10,9 +10,13 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Poedit 3.3.2\n" +"X-Generator: Poedit 2.4.3\n" "X-Poedit-Basepath: .\n" +#: assets/js/ga-custom-dimensions.js:52 +msgid "Registered Dimension" +msgstr "登録済みディメンション" + #: ga-communicator.php:50 msgid "Composer file is missing. Please run composer install." msgstr "Composerファイルが見つかりません。composer installを実行してください。" @@ -37,6 +41,7 @@ msgstr "" msgid "data attributes must be valid JSON format." msgstr "data属性は有効なJSON形式である必要があります。" +#. translators: %1$s is account, %2$s property. #: src/Kunoichi/GaCommunicator/Api/Dimensions.php:49 #, php-format msgid "Account and Property is required. (%1$s/%2$s)" @@ -63,6 +68,7 @@ msgstr "" msgid "No results found." msgstr "結果が見つかりませんでした。" +#. translators: %s is property id. #: src/Kunoichi/GaCommunicator/Command.php:62 #, php-format msgid "Getting web properties of %s..." @@ -92,16 +98,17 @@ msgstr "設定" msgid "Sandbox" msgstr "サンドボックス" +#. translators: %s is document url. #: src/Kunoichi/GaCommunicator/Screen/Settings.php:124 #, php-format msgid "" -"Try to interact GA data. Check the documentation and confirm what you get " -"with your JSON. WP-CLI is also helpful." +"Try to interact GA data. Check the documentation and confirm what you get with " +"your JSON. WP-CLI is also helpful." msgstr "" -"GAとデータをやり取りしてみてください。ドキュメントを参照し、JSONで取得できるデータ" -"を確認しましょう。WP-CLIも利用できます。" +"GAとデータをやり取りしてみてください。ドキュメントを参照し、JSONで取得できるデータを確" +"認しましょう。WP-CLIも利用できます。" #: src/Kunoichi/GaCommunicator/Screen/Settings.php:127 msgid "JSON to API" @@ -135,12 +142,13 @@ msgstr "サービスアカウントキー" msgid "Service account is defined programmatically." msgstr "サービスアカウントはプログラムで定義済みです。" +#. translators: %s is URL. #: src/Kunoichi/GaCommunicator/Screen/Settings.php:199 #, php-format msgid "" "You can get a service account key in JSON format from Google API Library. " -"For more detail, please check the document." +"For more detail, please check the document." msgstr "" "Google APIライブラリのJSON形式サービスアカウントキー。詳細はドキュメントをチェックして" @@ -270,12 +278,13 @@ msgstr "置換結果" msgid "Meta tags" msgstr "metaタグ" +#. translators: %s is link URL. #: src/Kunoichi/GaCommunicator/Screen/Settings.php:374 #, php-format msgid "" -"These tags are rendered as meta tags for Google Tag Manager. See our wiki for " -"more details." +"These tags are rendered as meta tags for Google Tag Manager. See our wiki for more " +"details." msgstr "" "これらのタグはmetaタグとしてGoogle タグマネージャー用に出力されます。詳細は " "Wiki をご覧" @@ -356,15 +365,34 @@ msgid "Post type in singular page." msgstr "シングルページの投稿タイプ。" #: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:42 +msgid "" +"Single post date. If page is not singular, always empty string. You can also " +"specify the format like %post_date:Y-m-d%." +msgstr "" +"投稿の投稿日時。もしページがシングルページでなければ、空文字になります。" +"%post_date:Y-m-d% のように形式を指定することもできます。" + +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:50 +msgid "" +"Character count of single post title. If page is not singular, always 0." +msgstr "" +"投稿のタイトル文字数。もしページがシングルページでなければ、0になります。" + +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:58 +msgid "" +"Character count of single post content. If page is not singular, always 0." +msgstr "投稿の本文文字数。もしページがシングルページでなければ、0になります。" + +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:66 msgid "Blog ID." msgstr "ブログID。" -#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:50 +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:74 msgid "If current page is a singular post, return author ID. Else, always 0." msgstr "" "現在のページが記事ページなら投稿者IDを返します。それ以外は0になります。" -#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:58 +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:82 msgid "" "On single page, returns CSV value for all assigned terms in any taxonomy " "like _11_,20_,_30_. Else, always empty string." @@ -373,12 +401,12 @@ msgstr "" "をCSV形式 _11_,20_,_30_で表示します。その他の場合は空文字になり" "ます。" -#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:80 +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:104 msgid "On taxonomy archive page, returns term ID. Else, always 0" msgstr "" "タクソノミーアーカイブの場合はタームIDを返します。それ以外では0になります。" -#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:92 +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:116 msgid "On taxonomy archive page, returns taxonomy name. Else, always empty." msgstr "" "タクソノミーアーカイブの場合はタクソノミー名を返します。それ以外では空文字に" @@ -458,14 +486,6 @@ msgstr "これは上記の相対的な日時設定を上書きします。" msgid "Default" msgstr "デフォルト" -#: assets/js/ga-custom-dimensions.js:52 -msgid "Registered Dimension" -msgstr "登録済みディメンション" - -#: assets/js/ga-custom-dimensions.js:62 -msgid "Scope" -msgstr "スコープ" - #. Plugin Name of the plugin/theme msgid "Google Analytics Communicator" msgstr "Google アナリティクス コミュニケーター" @@ -486,6 +506,9 @@ msgstr "株式会社 KUNOICHI" msgid "https://kunoichiwp.com" msgstr "https://kunoichiwp.com" +#~ msgid "Scope" +#~ msgstr "スコープ" + #~ msgid "Universal Analytics Account Setting" #~ msgstr "ユニバーサル・アナリティクス・アカウント設定" @@ -1475,8 +1498,8 @@ msgstr "https://kunoichiwp.com" #, fuzzy #~ msgid "rel:" #~ msgstr "" -#~ "スレッドを開始するには、 ログインしてください。" +#~ "スレッドを開始するには、 ログインしてください。" #, fuzzy #~ msgid "identity" @@ -1858,8 +1881,8 @@ msgstr "https://kunoichiwp.com" #, fuzzy #~ msgid "Blank" #~ msgstr "" -#~ "お探しの条件に合うものはありませんでした。
条件を変更するか、新規作成してください。" +#~ "お探しの条件に合うものはありませんでした。
条件を変更するか、新規作成してください。" #, fuzzy #~ msgid "Membership" diff --git a/languages/ga-communicator.pot b/languages/ga-communicator.pot index 719b73a..0a6842b 100644 --- a/languages/ga-communicator.pot +++ b/languages/ga-communicator.pot @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Google Analytics Communicator\n" -"POT-Creation-Date: 2024-01-11 16:35+0900\n" +"POT-Creation-Date: 2024-01-30 14:00+0900\n" "PO-Revision-Date: 2020-06-12 13:57+0900\n" "Last-Translator: Takahashi Fumiki \n" "Language-Team: Takahashi Fumiki \n" @@ -10,7 +10,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" -"X-Generator: Poedit 3.3.2\n" +"X-Generator: Poedit 2.4.3\n" "X-Poedit-Basepath: ..\n" "X-Poedit-Flags-xgettext: --add-comments=translators:\n" "X-Poedit-WPHeader: ga-communicator.php\n" @@ -25,6 +25,10 @@ msgstr "" "X-Poedit-SearchPathExcluded-3: wp\n" "X-Poedit-SearchPathExcluded-4: tests\n" +#: assets/js/ga-custom-dimensions.js:52 +msgid "Registered Dimension" +msgstr "" + #: ga-communicator.php:50 msgid "Composer file is missing. Please run composer install." msgstr "" @@ -45,6 +49,7 @@ msgstr "" msgid "data attributes must be valid JSON format." msgstr "" +#. translators: %1$s is account, %2$s property. #: src/Kunoichi/GaCommunicator/Api/Dimensions.php:49 #, php-format msgid "Account and Property is required. (%1$s/%2$s)" @@ -69,6 +74,7 @@ msgstr "" msgid "No results found." msgstr "" +#. translators: %s is property id. #: src/Kunoichi/GaCommunicator/Command.php:62 #, php-format msgid "Getting web properties of %s..." @@ -98,12 +104,13 @@ msgstr "" msgid "Sandbox" msgstr "" +#. translators: %s is document url. #: src/Kunoichi/GaCommunicator/Screen/Settings.php:124 #, php-format msgid "" -"Try to interact GA data. Check the documentation and confirm what you get " -"with your JSON. WP-CLI is also helpful." +"Try to interact GA data. Check the documentation and confirm what you get with " +"your JSON. WP-CLI is also helpful." msgstr "" #: src/Kunoichi/GaCommunicator/Screen/Settings.php:127 @@ -138,12 +145,13 @@ msgstr "" msgid "Service account is defined programmatically." msgstr "" +#. translators: %s is URL. #: src/Kunoichi/GaCommunicator/Screen/Settings.php:199 #, php-format msgid "" "You can get a service account key in JSON format from Google API Library. " -"For more detail, please check the document." +"For more detail, please check the document." msgstr "" #: src/Kunoichi/GaCommunicator/Screen/Settings.php:208 @@ -266,12 +274,13 @@ msgstr "" msgid "Meta tags" msgstr "" +#. translators: %s is link URL. #: src/Kunoichi/GaCommunicator/Screen/Settings.php:374 #, php-format msgid "" -"These tags are rendered as meta tags for Google Tag Manager. See our wiki for " -"more details." +"These tags are rendered as meta tags for Google Tag Manager. See our wiki for more " +"details." msgstr "" #: src/Kunoichi/GaCommunicator/Screen/Settings.php:381 @@ -349,24 +358,40 @@ msgid "Post type in singular page." msgstr "" #: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:42 -msgid "Blog ID." +msgid "" +"Single post date. If page is not singular, always empty string. You can " +"also specify the format like %post_date:Y-m-d%." msgstr "" #: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:50 -msgid "If current page is a singular post, return author ID. Else, always 0." +msgid "" +"Character count of single post title. If page is not singular, always 0." msgstr "" #: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:58 msgid "" +"Character count of single post content. If page is not singular, always 0." +msgstr "" + +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:66 +msgid "Blog ID." +msgstr "" + +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:74 +msgid "If current page is a singular post, return author ID. Else, always 0." +msgstr "" + +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:82 +msgid "" "On single page, returns CSV value for all assigned terms in any taxonomy " "like _11_,20_,_30_. Else, always empty string." msgstr "" -#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:80 +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:104 msgid "On taxonomy archive page, returns term ID. Else, always 0" msgstr "" -#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:92 +#: src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php:116 msgid "On taxonomy archive page, returns taxonomy name. Else, always empty." msgstr "" @@ -440,14 +465,6 @@ msgstr "" msgid "Default" msgstr "" -#: assets/js/ga-custom-dimensions.js:52 -msgid "Registered Dimension" -msgstr "" - -#: assets/js/ga-custom-dimensions.js:62 -msgid "Scope" -msgstr "" - #. Plugin Name of the plugin/theme msgid "Google Analytics Communicator" msgstr "" diff --git a/src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php b/src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php index 8ba4930..75d7454 100644 --- a/src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php +++ b/src/Kunoichi/GaCommunicator/Utility/PlaceHolders.php @@ -36,6 +36,30 @@ protected function init() { return is_singular() ? get_queried_object()->post_type : 0; }, ], + [ + 'name' => 'post_date', + 'type' => 'string', + 'description' => __( 'Single post date. If page is not singular, always empty string. You can also specify the format like %post_date:Y-m-d%.', 'ga-communicator' ), + 'callback' => function ( $format = 'Y-m-d H:i:s' ) { + return is_singular() ? mysql2date( $format, get_queried_object()->post_date ) : ''; + }, + ], + [ + 'name' => 'post_title_count', + 'type' => 'int', + 'description' => __( 'Character count of single post title. If page is not singular, always 0.', 'ga-communicator' ), + 'callback' => function () { + return is_singular() ? mb_strlen( get_queried_object()->post_title ) : 0; + }, + ], + [ + 'name' => 'post_content_count', + 'type' => 'int', + 'description' => __( 'Character count of single post content. If page is not singular, always 0.', 'ga-communicator' ), + 'callback' => function () { + return is_singular() ? mb_strlen( str_replace( [ "\n", "\r" ], '', get_the_content() ) ) : 0; + }, + ], [ 'name' => 'blog_id', 'type' => 'int', @@ -129,6 +153,13 @@ public function get() { public function replace( $tag ) { foreach ( $this->place_holders as $place_holder ) { $tag = str_replace( "%{$place_holder['name']}%", $place_holder['callback'](), $tag ); + // Detect placeholder with parameter. + if ( preg_match_all( "/%{$place_holder['name']}:(.*)%/", $tag, $matches ) ) { + foreach ( $matches[0] as $matched_key ) { + list( $placeholder_key, $parameter ) = explode( ':', str_replace( '%', '', $matched_key ), 2 ); + $tag = str_replace( $matched_key, $place_holder['callback']( $parameter ), $tag ); + } + } } return $tag; } diff --git a/src/Kunoichi/GaCommunicator/Utility/ScriptRenderer.php b/src/Kunoichi/GaCommunicator/Utility/ScriptRenderer.php index 38632b1..ef3f7c3 100644 --- a/src/Kunoichi/GaCommunicator/Utility/ScriptRenderer.php +++ b/src/Kunoichi/GaCommunicator/Utility/ScriptRenderer.php @@ -148,6 +148,20 @@ public function render_meta() { } } } + // Detect placeholder with parameter. + $matched_keys = preg_grep( '/' . preg_quote( $placeholder['name'] ) . ':/', $meta_keys ); + if ( ! empty( $matched_keys ) ) { + foreach ( $matched_keys as $matched_key ) { + list( $placeholder_key, $parameter ) = explode( ':', $matched_key, 2 ); + if ( isset( $placeholder['callback'] ) && is_callable( $placeholder['callback'] ) ) { + try { + $meta_tags[ 'gacommunicator:' . $placeholder['name'] . ':' . $parameter ] = $placeholder['callback']( $parameter ); + } catch ( \Exception $e ) { + error_log( 'Error while executing: ' . $e->getMessage() ); + } + } + } + } } $meta_tags = apply_filters( 'ga_communicator_meta_tags', $meta_tags ); if ( ! empty( $meta_tags ) ) {