Skip to content

Commit

Permalink
feat: 翻訳準備一次対応 (#13)
Browse files Browse the repository at this point in the history
* 下線が表示されてしまう問題の修正

* fix: コメントの体裁を調整

* feat: 英語と日本語を追加

* JavsScript側にも国際化用のパッケージをインストール

* fix: lint

* feat: i18nの設置

* chore: potファイルを更新する

* potファイルを更新

* feat: potファイルを更新

* feat: 英語に変換

* 文言を変更

* (一時コミット)翻訳情報を読み込む処理を追加

* wp-i18nは最初から依存に含まれていたので、wp-i18nを依存に追加する処理を削除

* 翻訳ファイルを追加

* テストコードの削除

* 一部ファイルコミット(必要かはわからないが)

* プレビューを修正
  • Loading branch information
taako-502 authored May 14, 2023
1 parent 57a595f commit 1fe2f1b
Show file tree
Hide file tree
Showing 34 changed files with 1,117 additions and 113 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.DS_Store
package-lock.json
.github/workflows/secrets.json
yarn-error.log

# i18n
languages/ccl-plugin-*-backup*.po~
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
公式プラグインに登録しています。<br>
[Custom Card Link](https://wordpress.org/plugins/custom-card-link/)

## リポジトリ
### GitHub
https://github.com/taako-502/custom-card-link

コミットする前に以下を実施すること

以下のコマンドを実行する
```bash
$ yarn build
```

`ccl-plugin.pot`を更新する。

## Third-party resources
### Get_OGP_InWP
Expand Down
2 changes: 1 addition & 1 deletion build/admin.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api', 'wp-components', 'wp-element'), 'version' => '7b4195b648902a0b38cf');
<?php return array('dependencies' => array('react', 'wp-api', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '252db134fc55c5d9f5ce');
4 changes: 2 additions & 2 deletions build/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-server-side-render'), 'version' => '43276567b64dad97c637');
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-server-side-render'), 'version' => '84333d84564baeac6b75');
2 changes: 1 addition & 1 deletion build/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 48 additions & 6 deletions custom-card-link.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php
Namespace Ccl_Plugin;

/*
Plugin Name: Custom Card Link
Plugin URI: https://github.com/taako-502/custom-card-link
Description: 外部リンクを表示するGutenbergブロック
Version: 1.0.1
Author: takao502
Author URI: https://github.com/taako-502
Text Domain: ccl-plugin
Domain Path: /languages
License: GPL2
*/
const OPTION_GROUP = 'custom-card-link';
const CCL_SLUG = 'custom-card-link';
const TEXT_DOMAIN = 'ccl-plugin';
const DB_NAME = 'custom_card_link_settings';
const MAX_DESCRIPTION_CHAR_OF_NUM = 200; //setting-pc.jsおよびsetting-sp.jsとあわせる

Expand All @@ -22,13 +26,31 @@

use function Ccl_Plugin\functions\data\get_setting;

/**
* 翻訳ファイルの読み込み
*/
add_action('init', function() {
load_plugin_textdomain(
TEXT_DOMAIN,
false,
basename( plugin_dir_url( __FILE__ ) ) . '/languages'
);

// FIXME: うまく読み込めない
wp_set_script_translations(
CCL_SLUG,
TEXT_DOMAIN,
basename( plugin_dir_url( __FILE__ ) ) . '/languages'
);
});

/**
* 管理画面追加
*/
add_action('admin_menu', function() {
add_menu_page(
'カスタムカードリンク',
'カスタムカードリンク - デザイン設定',
__('Custom Card Link', 'ccl-plugin'),
__('Custom Card Link - Settings', 'ccl-plugin'),
'manage_options',
OPTION_GROUP,
function() {
Expand All @@ -55,16 +77,36 @@ function() {
array('wp-components')
);

// JavaScriptファイルの読み込み
// JavaScriptファイルの読み込み
wp_enqueue_media();
$asset_file = include_once ( __DIR__ . '/build/admin.asset.php') ;
wp_enqueue_script (
wp_enqueue_script(
CCL_SLUG,
plugin_dir_url( __FILE__ ).'build/admin.js',
$asset_file['dependencies'],
$asset_file['version'],
true
);

load_script_textdomain(
CCL_SLUG,
TEXT_DOMAIN,
basename( plugin_dir_url( __FILE__ ) ) . '/languages'
);

// NOTE: https://elearn.jp/wpman/function/load_plugin_textdomain.html
load_plugin_textdomain(
TEXT_DOMAIN,
false,
basename( plugin_dir_url( __FILE__ ) ) . '/languages'
);

// FIXME: うまく読み込めない
wp_set_script_translations(
CCL_SLUG,
TEXT_DOMAIN,
basename( plugin_dir_url( __FILE__ ) ) . '/languages'
);
});

/**
Expand All @@ -79,9 +121,9 @@ function() {
$ogps = \Ccl_Plugin\library\Get_OGP_InWP::get(trim($url));
$post_id = url_to_postid($url);
if($url == '' && !is_singular()) {
return 'URLを入力してください。';
return __('Please enter the URL.', 'ccl-plugin');
} else if(($ogps == [] && $post_id == 0) && !is_singular()){
return '有効なURLを入力してください。';
return __('Please enter a valid URL.', 'ccl-plugin');
}
if($url == '' || ($ogps == [] && $post_id == 0)){
return;
Expand Down
Loading

0 comments on commit 1fe2f1b

Please sign in to comment.