Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* メールフォーム確認ページ
*/
$this->BcBaser->css('admin/jquery-ui/jquery-ui.min', true);
$this->BcBaser->js(array('vendor/jquery-ui-1.11.4.min', 'vendor/i18n/ui.datepicker-ja'), false);
$jsFiles = ['vendor/jquery-ui-1.11.4.min'];
if ($this->BcBaser->isJapaneseLocale()) {
$jsFiles[] = 'vendor/i18n/ui.datepicker-ja';
}
$this->BcBaser->js($jsFiles, false);
if ($freezed) {
$this->Mailform->freeze();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* メールフォーム
*/
$this->BcBaser->css('admin/jquery-ui/jquery-ui.min', true);
$this->BcBaser->js(array('vendor/jquery-ui-1.11.4.min', 'vendor/i18n/ui.datepicker-ja'), false);
$jsFiles = ['vendor/jquery-ui-1.11.4.min'];
if ($this->BcBaser->isJapaneseLocale()) {
$jsFiles[] = 'vendor/i18n/ui.datepicker-ja';
}
$this->BcBaser->js($jsFiles, false);
?>


Expand Down
11 changes: 7 additions & 4 deletions plugins/BcThemeSample/templates/layout/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
$request = $this->getRequest();
$attributes = $request->getAttributes();
$base = $attributes['base'];
$jsFiles = [];
if ($this->BcBaser->isJapaneseLocale()) {
$jsFiles[] = 'vendor/i18n/ui.datepicker-ja';
}
?>
<!DOCTYPE html>
<html>
<html lang="<?= h($this->BcBaser->getHtmlLang()) ?>">
<head>
<?php $this->BcBaser->charset() ?>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
Expand All @@ -35,14 +39,13 @@
'editor'
]) ?>
<?= $this->BcBaser->declarationI18n() ?>
<?php $this->BcBaser->js([
<?php $this->BcBaser->js(array_merge([
'vendor/jquery-1.11.3.min',
'vendor/jquery-ui-1.11.4.min',
'vendor/jquery.bxslider-4.12.min',
'vendor/jquery.colorbox-1.6.1.min',
'vendor/i18n/ui.datepicker-ja',
'vendor/jquery-accessibleMegaMenu',
]); ?>
], $jsFiles)); ?>
<?php $this->BcBaser->js('common.bundle', true, [
'id' => 'AdminScript',
'data-baseUrl' => h($base),
Expand Down
Binary file modified plugins/baser-core/resources/locales/en/baser_core.mo
Binary file not shown.
11 changes: 3 additions & 8 deletions plugins/baser-core/resources/locales/en/baser_core.po
Original file line number Diff line number Diff line change
Expand Up @@ -8577,7 +8577,7 @@ msgstr "Table"

#: plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomContents/form.php:54
msgid "テーブルを選択してください"
msgstr "SPlease select Table"
msgstr "Please select Table"

#: plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomContents/form.php:58
msgid "コンテンツに紐付けるテーブルを選択します。"
Expand Down Expand Up @@ -9882,7 +9882,7 @@ msgstr "Received Emails"

#: plugins/bc-admin-third/templates/plugin/BcMail/Admin/element/Dashboard/mail_messages.php:34
msgid "{0} 件"
msgstr "%s Items"
msgstr "{0} Items"

#: plugins/bc-admin-third/templates/plugin/BcMail/Admin/element/MailContents/form.php:27
msgid "メールフォーム説明文"
Expand Down Expand Up @@ -15099,15 +15099,10 @@ msgstr "Widgets"
#~ msgid "更新日に不正な文字列が入っています。"
#~ msgstr "There are invalid strings in Update Date."

#, fuzzy
#~| msgid "PHPの構文エラーが発生しました。"
#~ msgid "草稿欄でPHPの構文エラーが発生しました。"
#~ msgstr "PHP syntax error occured."

#~ msgid "PHPの構文エラーが発生しました。"
#~ msgstr "PHP syntax error occured."

#, fuzzy
#~#, fuzzy
#~| msgid "このURLの登録は許可されていません。"
#~ msgid "スクリプトの入力は許可されていません。"
#~ msgstr "This URL's registration is not allowed."
Expand Down
30 changes: 30 additions & 0 deletions plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -2317,4 +2317,34 @@ public static function isDevelopmentVersion(): bool
return is_dir(ROOT . DS . 'plugins' . DS . 'baser-core');
}

/**
* locale から言語コードを取得する
*
* @param string|null $locale
* @param string $default
* @return string
* @checked
* @noTodo
* @unitTest
*/
public static function getLocaleLanguageCode(?string $locale = null, string $default = 'ja'): string
{
$locale = strtolower((string) ($locale ?? \Cake\I18n\I18n::getLocale()));
return preg_replace('/[_-].*$/', '', $locale) ?: $default;
}

/**
* 現在の locale が日本語かどうか判定する
*
* @param string|null $locale
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public static function isJapaneseLocale(?string $locale = null): bool
{
return self::getLocaleLanguageCode($locale) === 'ja';
}

}
26 changes: 26 additions & 0 deletions plugins/baser-core/src/View/Helper/BcBaserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2885,4 +2885,30 @@ public function getFullUrl(string $url): string
return BcUtil::fullUrl($url);
}

/**
* html の lang 属性に使う言語コードを取得する
*
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getHtmlLang(): string
{
return BcUtil::getLocaleLanguageCode();
}

/**
* 現在の locale が日本語かどうか判定する
*
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isJapaneseLocale(): bool
{
return BcUtil::isJapaneseLocale();
}

}
16 changes: 15 additions & 1 deletion plugins/baser-core/src/View/Helper/BcCkeditorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BaserCore\View\Helper;

use BaserCore\Utility\BcUtil;
use Cake\Core\Plugin;
use Cake\View\Helper;
use Cake\Utility\Inflector;
Expand Down Expand Up @@ -207,8 +208,21 @@ public function initialize($config): void
*/
protected function build($fieldName, $options = [])
{
static $langExistsCache = [];

$editorLanguage = BcUtil::getLocaleLanguageCode();

if (!isset($langExistsCache[$editorLanguage])) {
// CKEditor の言語JSがない場合、要求すると 404 で初期化が失敗するため ja にフォールバック
$editorLanguagePath = Plugin::path('BcAdminThird') . 'webroot' . DS . 'js' . DS . 'vendor' . DS . 'ckeditor' . DS . 'lang' . DS . $editorLanguage . '.js';
$langExistsCache[$editorLanguage] = file_exists($editorLanguagePath);
}
if (!$langExistsCache[$editorLanguage]) {
$editorLanguage = 'ja';
}

$options = array_merge([
'editorLanguage' => 'ja', // 言語
'editorLanguage' => $editorLanguage, // 言語
'editorSkin' => 'moono', // スキン
'editorToolType' => 'normal', // ツールバータイプ
'editorToolbar' => [], // ツールバータイプ
Expand Down
23 changes: 22 additions & 1 deletion plugins/baser-core/tests/TestCase/Utility/BcUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@ public static function isInstallModeDataProvider()
];
}

/**
* locale から言語コードを取得する
*/
public function testGetLocaleLanguageCode(): void
{
$this->assertSame('ja', BcUtil::getLocaleLanguageCode('ja_JP'));
$this->assertSame('en', BcUtil::getLocaleLanguageCode('en_US'));
$this->assertSame('fr', BcUtil::getLocaleLanguageCode('fr-FR'));
$this->assertSame('ja', BcUtil::getLocaleLanguageCode('', 'ja'));
}

/**
* 日本語 locale かどうか判定する
*/
public function testIsJapaneseLocale(): void
{
$this->assertTrue(BcUtil::isJapaneseLocale('ja_JP'));
$this->assertTrue(BcUtil::isJapaneseLocale('ja'));
$this->assertFalse(BcUtil::isJapaneseLocale('en_US'));
}

/**
* Test getVersion
* @return void
Expand Down Expand Up @@ -1545,7 +1566,7 @@ public function testIsSameReferrerAsCurrent($referer, $expected)
public static function isSameReferrerAsCurrentDataProvider()
{
return [
// refererがnullの場合 
// refererがnullの場合
[null, false],
// referer!=$siteDomainの場合
["/baser/admin", false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,34 @@ public function testI18nScript()
$this->assertStringContainsString($encoded2, $result);
}

/**
* html lang 用の言語コードを取得する
*/
public function testGetHtmlLang(): void
{
$originalLocale = \Cake\I18n\I18n::getLocale();
try {
\Cake\I18n\I18n::setLocale('ja_JP');
$this->assertSame('ja', $this->BcBaser->getHtmlLang());
} finally {
\Cake\I18n\I18n::setLocale($originalLocale);
}
}

/**
* 現在の locale が日本語かどうか判定する
*/
public function testIsJapaneseLocale(): void
{
$originalLocale = \Cake\I18n\I18n::getLocale();
try {
\Cake\I18n\I18n::setLocale('ja_JP');
$this->assertTrue($this->BcBaser->isJapaneseLocale());
} finally {
\Cake\I18n\I18n::setLocale($originalLocale);
}
}

/**
* Test BcBaser->flashが適切なflashメッセージを出力してるかテスト
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use BaserCore\View\BcAdminAppView;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\Helper\BcCkeditorHelper;
use Cake\Core\Plugin;
use Cake\I18n\I18n;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
Expand Down Expand Up @@ -111,6 +113,50 @@ public function testBuild()
$this->assertMatchesRegularExpression('/let config = JSON\.parse\(\'\{"ckeditorField/', $jsResult);
}

/**
* Test build locale-aware editor language
*/
public function testBuildEditorLanguageByLocale()
{
$this->BcCkeditor->getView()->setTheme('BcAdminThird');
$request = $this->BcCkeditor->getView()->getRequest()->withAttribute('formTokenData', ['dummy']);
$this->BcCkeditor->getView()->setRequest($request);
$this->BcCkeditor->BcAdminForm->create();

$originalLocale = I18n::getLocale();
try {
I18n::setLocale('en_US');
$this->execPrivateMethod($this->BcCkeditor, 'build', ['Page.contents', []]);
$jsResult = $this->BcCkeditor->getView()->fetch('script');
$editorLanguagePath = Plugin::path('BcAdminThird') . 'webroot' . DS . 'js' . DS . 'vendor' . DS . 'ckeditor' . DS . 'lang' . DS . 'en.js';
$this->assertFileExists($editorLanguagePath);
$this->assertStringContainsString('"language":"en"', $jsResult);
} finally {
I18n::setLocale($originalLocale);
}
}

/**
* Test build falls back to ja for unsupported locale
*/
public function testBuildEditorLanguageFallbackToJa()
{
$this->BcCkeditor->getView()->setTheme('BcAdminThird');
$request = $this->BcCkeditor->getView()->getRequest()->withAttribute('formTokenData', ['dummy']);
$this->BcCkeditor->getView()->setRequest($request);
$this->BcCkeditor->BcAdminForm->create();

$originalLocale = I18n::getLocale();
try {
I18n::setLocale('fr_FR');
$this->execPrivateMethod($this->BcCkeditor, 'build', ['Page.contents', []]);
$jsResult = $this->BcCkeditor->getView()->fetch('script');
$this->assertStringContainsString('"language":"ja"', $jsResult);
} finally {
I18n::setLocale($originalLocale);
}
}

/**
* Test setEditorToolbar
*/
Expand Down
13 changes: 8 additions & 5 deletions plugins/bc-admin-third/templates/Admin/layout/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
$request = $this->getRequest();
$attributes = $request->getAttributes();
$base = $attributes['base'];
$jsFiles = [];
if ($this->BcBaser->isJapaneseLocale()) {
$jsFiles[] = 'vendor/i18n/ui.datepicker-ja';
$jsFiles[] = 'vendor/jquery.validate_ja';
}
?>
<!DOCTYPE html>
<html lang="ja">
<html lang="<?= h($this->BcBaser->getHtmlLang()) ?>">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow"/>
Expand Down Expand Up @@ -68,18 +73,16 @@
'bcConfirmAlertMessage1' => __d('baser_core', 'メッセージを指定してください。'),
'bcConfirmAlertMessage2' => __d('baser_core', 'コールバック処理が登録されていません。')
], ['block' => false]) ?>
<?php $this->BcBaser->js([
<?php $this->BcBaser->js(array_merge([
'admin/vendor.bundle',
'vendor/jquery-3.5.1.min',
'vendor/jquery.bt.min',
'vendor/jquery-contextMenu-2.2.0/jquery.contextMenu.min',
'vendor/jquery-ui-1.13.0.min',
'vendor/i18n/ui.datepicker-ja',
'vendor/jquery.validate.1.19.3.min',
'vendor/jquery.validate_ja',
'vendor/jquery.form-2.94',
'vendor/jquery.timepicker'
]) ?>
], $jsFiles)) ?>
<?php $this->BcBaser->js('admin/common.bundle', true, [
'id' => 'AdminScript',
'data-baseUrl' => h($base),
Expand Down
15 changes: 10 additions & 5 deletions plugins/bc-admin-third/templates/Admin/layout/error.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php
$jsFiles = [];
if ($this->BcBaser->isJapaneseLocale()) {
$jsFiles[] = 'vendor/i18n/ui.datepicker-ja';
}
?>
<!DOCTYPE html>
<html lang="ja">
<html lang="<?= h($this->BcBaser->getHtmlLang()) ?>">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow"/>
Expand All @@ -12,15 +18,14 @@
'admin/style',
]) ?>
<?php echo $this->fetch('css') ?>
<?php $this->BcBaser->js([
<?php $this->BcBaser->js(array_merge([
'admin/vendor.bundle',
'vendor/vue.min',
'vendor/jquery-3.5.1.min',
'vendor/jquery.bt.min',
'vendor/jquery-ui-1.11.4.min.js',
'vendor/i18n/ui.datepicker-ja',
'vendor/jquery-ui-1.13.0.min',
'vendor/jquery.timepicker',
]) ?>
], $jsFiles)) ?>
<?php echo $this->fetch('script') ?>
</head>

Expand Down
5 changes: 5 additions & 0 deletions plugins/bc-admin-third/webroot/js/vendor/ckeditor/lang/en.js

Large diffs are not rendered by default.

Loading
Loading