PHP code example of tomk79 / px2-i18n
1. Go to this page and download the library: Download tomk79/px2-i18n library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomk79 / px2-i18n example snippets
/** デフォルトの言語 */
$conf->default_lang = 'ja';
/** 対応する言語 */
$conf->accept_langs = array('en', 'zh-CN', 'zh-TW', 'ko');
/**
* funcs: Before sitemap
*
* サイトマップ読み込みの前に実行するプラグインを設定します。
*/
$conf->funcs->before_sitemap = array(
/* 中略 */
// カスタムサイトマップオブジェクトを生成して登録する
tomk79\pickles2\px2I18n\loader::site(),
// LangBank を `$px->lb` に登録する
tomk79\pickles2\px2I18n\loader::langbank( [
"path_csv" => "/realpath/to/language.csv",
] ),
);
/** カスタムフィールドを登録 */
$conf->plugins->px2dt->guieditor->custom_fields = array(
'text'=>array(
'backend'=>array(
'class' => 'tomk79\\pickles2\\px2I18n\\fields\\text',
'18nText'
),
),
'html_attr_text'=>array(
'backend'=>array(
'class' => 'tomk79\\pickles2\\px2I18n\\fields\\html_attr_text',
'8n\\fields\\multitext',
'th/to/vendor/tomk79/px2-i18n/fields/i18n_summernote/backend/summernote.js',
),
'frontend'=>array(
'dir' => 'path/to/vendor/tomk79/px2-i18n/fields/i18n_summernote/frontend/',
'file' => array(
'summernote.css',
'summernote.js',
"summernote/summernote.min.css",
"summernote/summernote.min.js",
),
'function' => 'window.BroccoliFieldPx2I18nSummernote'
),
),
);
/** Broccoliフィールドの初期設定 */
$mlSettings = array(
'defaultLang' => $conf->default_lang,
'subLangs' => $conf->accept_langs,
);
$conf->plugins->px2dt->guieditor->field_config = array(
// text フィールドを設定
'text' => $mlSettings,
// html_attr_text フィールドを設定
'html_attr_text' => $mlSettings,
// multitext フィールドを設定
'multitext' => $mlSettings,
// summernote フィールドを設定
'summernote' => $mlSettings,
);
// Google Cloud の認証情報のパスを、環境変数として宣言する
putenv( 'GOOGLE_APPLICATION_CREDENTIALS=/path/to/google-cloud-credentials.json' );
$devices = array();
foreach( $conf->accept_langs as $langCode ){
array_push( $devices, array(
'user_agent'=>'Mozilla/',$langCode,
'params' => array(
'LANG' => $langCode,
),
'path_publish_dir'=>'../dist/',
'path_rewrite_rule'=>'/'.$langCode.'{$dirname}/{$filename}.{$ext}',
'paths_target'=>array(
'/*',
),
'paths_ignore'=>array(
// '/common/*',
),
// リンクの書き換え方向
// `origin2origin`、`origin2rewrited`、`rewrited2origin`、`rewrited2rewrited` のいずれかで指定します。
// `origin` は変換前のパス、 `rewrited` は変換後のパスを意味します。
// 変換前のパスから変換後のパスへのリンクとして書き換える場合は `origin2rewrited` のように指定します。
'rewrite_direction'=>'rewrited2rewrited',
) );
}
/**
* funcs: Before content
*
* サイトマップ読み込みの後、コンテンツ実行の前に実行するプラグインを設定します。
*/
$conf->funcs->before_content = array(
// PX=api
'picklesFramework2\commands\api::register' ,
// PX=publish (px2-publish-ex)
'tomk79\pickles2\publishEx\publish::register('.json_encode(array(
'devices'=>$devices,
)).')' ,
// PX=px2dthelper
'tomk79\pickles2\px2dthelper\main::register' ,
);