Skip to content

Commit

Permalink
Editor localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsabil83 committed Jul 30, 2023
1 parent 4d8d7bd commit f0eb6e8
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 6 deletions.
2 changes: 2 additions & 0 deletions resources/views/tiny-editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class="relative z-0"
>
<div
x-data="{ state: $wire.entangle('{{ $getStatePath() }}'), initialized: false }"
x-load-js="[@js(\Filament\Support\Facades\FilamentAsset::getScriptSrc($getLanguageId(), 'mohamedsabil83/filament-forms-tinyeditor'))]"
x-init="(() => {
window.addEventListener('DOMContentLoaded', () => initTinymce());
$nextTick(() => initTinymce());
Expand All @@ -13,6 +14,7 @@ class="relative z-0"
tinymce.init({
target: $refs.tinymce,
language: '{{ $getInterfaceLanguage() }}',
language_url: 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/{{ $getInterfaceLanguage() }}.min.js',
toolbar_sticky: {{ $getToolbarSticky() ? 'true' : 'false' }},
toolbar_sticky_offset: 64,
skin: {
Expand Down
123 changes: 120 additions & 3 deletions src/Components/TinyEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,124 @@ public function getFileAttachmentsDirectory(): ?string

public function getInterfaceLanguage(): string
{
return $this->language ?? app()->getLocale();
return match ($this->language) {
'ar' => 'ar',
'az' => 'az',
'bg' => 'bg_BG',
'bn' => 'bn_BD',
'ca' => 'ca',
'cs' => 'cs',
'cy' => 'cy',
'da' => 'da',
'de' => 'de',
'dv' => 'dv',
'el' => 'el',
'eo' => 'eo',
'es' => 'es',
'et' => 'et',
'eu' => 'eu',
'fa' => 'fa',
'fi' => 'fi',
'fr' => 'fr_FR',
'ga' => 'ga',
'gl' => 'gl',
'he' => 'he_IL',
'hr' => 'hr',
'hu' => 'hu_HU',
'hy' => 'hy',
'id' => 'id',
'is' => 'is_IS',
'it' => 'it',
'ja' => 'ja',
'kab' => 'kab',
'kk' => 'kk',
'ko' => 'ko_KR',
'ku' => 'ku',
'lt' => 'lt',
'lv' => 'lv',
'nb' => 'nb_NO',
'nl' => 'nl',
'oc' => 'oc',
'pl' => 'pl',
'pt' => 'pt_BR',
'ro' => 'ro',
'ru' => 'ru',
'sk' => 'sk',
'sl' => 'sl',
'sq' => 'sq',
'sr' => 'sr',
'sv' => 'sv_SE',
'ta' => 'ta',
'tg' => 'tg',
'th' => 'th_TH',
'tr' => 'tr',
'ug' => 'ug',
'uk' => 'uk',
'vi' => 'vi',
'zh' => 'zh_CN',
default => 'en',
};
}

public function getLanguageId(): string
{
return match ($this->getInterfaceLanguage()) {
'ar' => 'tinymce-lang-ar',
'az' => 'tinymce-lang-az',
'bg' => 'tinymce-lang-bg_BG',
'bn' => 'tinymce-lang-bn_BD',
'ca' => 'tinymce-lang-ca',
'cs' => 'tinymce-lang-cs',
'cy' => 'tinymce-lang-cy',
'da' => 'tinymce-lang-da',
'de' => 'tinymce-lang-de',
'dv' => 'tinymce-lang-dv',
'el' => 'tinymce-lang-el',
'eo' => 'tinymce-lang-eo',
'es' => 'tinymce-lang-es',
'et' => 'tinymce-lang-et',
'eu' => 'tinymce-lang-eu',
'fa' => 'tinymce-lang-fa',
'fi' => 'tinymce-lang-fi',
'fr' => 'tinymce-lang-fr_FR',
'ga' => 'tinymce-lang-ga',
'gl' => 'tinymce-lang-gl',
'he' => 'tinymce-lang-he_IL',
'hr' => 'tinymce-lang-hr',
'hu' => 'tinymce-lang-hu_HU',
'hy' => 'tinymce-lang-hy',
'id' => 'tinymce-lang-id',
'is' => 'tinymce-lang-is_IS',
'it' => 'tinymce-lang-it',
'ja' => 'tinymce-lang-ja',
'kab' => 'tinymce-lang-kab',
'kk' => 'tinymce-lang-kk',
'ko' => 'tinymce-lang-ko_KR',
'ku' => 'tinymce-lang-ku',
'lt' => 'tinymce-lang-lt',
'lv' => 'tinymce-lang-lv',
'nb' => 'tinymce-lang-nb_NO',
'nl' => 'tinymce-lang-nl',
'oc' => 'tinymce-lang-oc',
'pl' => 'tinymce-lang-pl',
'pt' => 'tinymce-lang-pt_BR',
'ro' => 'tinymce-lang-ro',
'ru' => 'tinymce-lang-ru',
'sk' => 'tinymce-lang-sk',
'sl' => 'tinymce-lang-sl',
'sq' => 'tinymce-lang-sq',
'sr' => 'tinymce-lang-sr',
'sv' => 'tinymce-lang-sv_SE',
'ta' => 'tinymce-lang-ta',
'tg' => 'tinymce-lang-tg',
'th' => 'tinymce-lang-th_TH',
'tr' => 'tinymce-lang-tr',
'ug' => 'tinymce-lang-ug',
'uk' => 'tinymce-lang-uk',
'vi' => 'tinymce-lang-vi',
'zh' => 'tinymce-lang-zh_CN',
default => 'tinymce',
};
}

public function getPlugins(): string
Expand Down Expand Up @@ -125,9 +242,9 @@ public function isSimple(): bool
return (bool) $this->evaluate($this->isSimple);
}

public function language(string $language = null): static
public function language(string $language): static
{
$this->language = $language ?? app()->getLocale();
$this->language = $language;

return $this;
}
Expand Down
69 changes: 66 additions & 3 deletions src/FilamentFormsTinyeditorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Mohamedsabil83\FilamentFormsTinyeditor;

use Filament\Support\Assets\Css;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Spatie\LaravelPackageTools\Package;
Expand All @@ -28,10 +27,74 @@ public function configurePackage(Package $package): void
public function packageBooted(): void
{
FilamentAsset::register([
Css::make('skin-light', 'https://cdn.jsdelivr.net/npm/[email protected]/skins/ui/oxide/skin.min.css'),
Css::make('skin-dark', 'https://cdn.jsdelivr.net/npm/[email protected]/skins/ui/oxide-dark/skin.min.css'),
Js::make('tinymce', 'https://cdn.jsdelivr.net/npm/[email protected]/tinymce.min.js'),
Js::make('tinymce-custom', __DIR__.'/../resources/dist/js/tinymce-custom.js'),
Js::make('tinymce-lang-ar', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ar.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-az', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/az.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-bg_BG', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/bg_BG.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-bn_BD', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/bn_BD.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ca', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ca.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-cs', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/cs.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-cy', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/cy.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-da', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/da.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-de', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/de.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-dv', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/dv.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-el', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/el.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-eo', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/eo.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-es', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/es.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-es_ES', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/es_ES.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-et', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/et.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-es_MX', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/es_MX.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-eu', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/eu.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-fa', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/fa.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-fa_IR', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/fa_IR.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-fi', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/fi.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-fr_FR', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/fr_FR.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ga', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ga.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-gl', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/gl.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-he_IL', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/he_IL.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-hr', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/hr.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-hu_HU', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/hu_HU.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-hy', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/hy.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-id', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/id.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-is_IS', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/is_IS.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-it', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/it.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-it_IT', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/it_IT.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ja', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ja.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-kab', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/kab.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-kk', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/kk.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ko_KR', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ko_KR.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ku', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ku.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-lt', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/lt.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-lv', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/lv.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-nb_NO', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/nb_NO.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-nl', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/nl.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-nl_BE', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/nl_BE.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-oc', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/oc.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-pl', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/pl.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-pt_BR', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/pt_BR.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-pt_PT', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/pt_PT.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ro', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ro.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ro_RO', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ro_RO.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ru', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ru.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ru_RU', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ru_RU.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-sk', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/sk.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-sl', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/sl.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-sl_SI', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/sl_SI.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-sq', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/sq.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-sr', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/sr.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-sv_SE', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/sv_SE.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ta', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ta.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ta_IN', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ta_IN.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-tg', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/tg.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-th_TH', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/th_TH.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-tr', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/tr.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-tr_TR', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/tr_TR.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-ug', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/ug.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-uk', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/uk.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-vi', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/vi.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-zh_CN', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/zh_CN.min.js')->loadedOnRequest(),
Js::make('tinymce-lang-zh_TW', 'https://cdn.jsdelivr.net/npm/[email protected]/langs5/zh_TW.min.js')->loadedOnRequest(),
], package: 'mohamedsabil83/filament-forms-tinyeditor');
}
}

0 comments on commit f0eb6e8

Please sign in to comment.