Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Unreleased

- Added `craft\ckeditor\web\assets\BaseCkeditorPackageAsset::getImportCompliantLanguage()`.
- Fixed a bug where custom `toolbar` config settings were getting ignored. ([#522](https://github.com/craftcms/ckeditor/issues/522))
- Fixed a bug where files uploaded to Assets fields could also be added to nearby CKEditor fields. ([#523](https://github.com/craftcms/ckeditor/issues/523))
- Fixed an error that could occur when registering a custom CKEditor plugin. ([#525](https://github.com/craftcms/ckeditor/issues/525))
- Fixed a JavaScript error that occurred if the control panel was being translated into a language that CKEditor doesn’t support. ([#526](https://github.com/craftcms/ckeditor/issues/526))

## 5.1.0 - 2026-03-05

Expand Down
3 changes: 2 additions & 1 deletion src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,8 @@ private function _inputHtml(mixed $value, ?ElementInterface $element, bool $stat

// Add the translation import
$uiLanguage = BaseCkeditorPackageAsset::uiLanguage();
$uiTranslationImport = "import coreTranslations from 'ckeditor5/translations/$uiLanguage.js';";
$importCompliantUiLanguage = BaseCkeditorPackageAsset::getImportCompliantLanguage(BaseCkeditorPackageAsset::uiLanguage());
$uiTranslationImport = "import coreTranslations from 'ckeditor5/translations/$importCompliantUiLanguage.js';";

$view->registerScriptWithVars(fn($baseConfigJs, $toolbarJs, $languageJs, $showWordCountJs, $wordLimitJs, $characterLimitJs, $imageMode) => <<<JS
$imports
Expand Down
108 changes: 108 additions & 0 deletions src/web/assets/BaseCkeditorPackageAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,114 @@
*/
abstract class BaseCkeditorPackageAsset extends AssetBundle
{
// a list of languages supported by CKEditor
private static array $ckeSupportedLanguages = [
'af',
'ar',
'ast',
'az',
'be',
'bg',
'bn',
'bs',
'ca',
'cs',
'da',
'de',
'de-ch',
'el',
'en',
'en-au',
'en-gb',
'eo',
'es',
'es-co',
'et',
'eu',
'fa',
'fi',
'fr',
'gl',
'gu',
'he',
'hi',
'hr',
'hu',
'hy',
'id',
'it',
'ja',
'jv',
'kk',
'km',
'kn',
'ko',
'ku',
'lt',
'lv',
'ms',
'nb',
'ne',
'nl',
'no',
'oc',
'pl',
'pt',
'pt-br',
'ro',
'ru',
'si',
'sk',
'sl',
'sq',
'sr',
'sr-latn',
'sv',
'th',
'ti',
'tk',
'tr',
'tt',
'ug',
'uk',
'ur',
'uz',
'vi',
'zh',
'zh-cn',
];

/**
* Returns import compliant language code.
*
* CKEditor doesn't support all the languages that Craft does.
* It also often only support the major version, not localized ones (e.g. they support fr but not fr-FR, fr-CA, fr-BE etc).
* Since we're now using imports to get the correct translation files, we need to know if the file exists before we import it,
* or the field won't render.
*
* @param string $language
* @return string
* @since 5.2.0
*/
public static function getImportCompliantLanguage(string $language): string
{
// first check if we have an exact match
if (in_array($language, self::$ckeSupportedLanguages, true)) {
return $language;
}

// if not - check if there's a major version that we can use
if (str_contains($language, '-')) {
$language = substr($language, 0, strpos($language, '-'));
if (in_array($language, self::$ckeSupportedLanguages, true)) {
return $language;
}
}

// if not, default to plain English
return 'en';
}

/**
* Returns the CKEditor UI language that should be used based on the app language.
*
Expand Down
Loading