Skip to content

Commit

Permalink
[ADD] Multilang TV.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Sep 16, 2024
1 parent 396688d commit 6e3d409
Show file tree
Hide file tree
Showing 18 changed files with 361 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('s_lang_tmplvar_contentvalues', function (Blueprint $table) {
$table->id();
$table->string('lang', 4)->default('base')->index()->comment('Language of content data');
$table->integer('tmplvarid')->index()->comment('Template variable ID');
$table->foreign('tmplvarid')->references('id')->on('site_tmplvars')->cascadeOnDelete();
$table->unsignedInteger('contentid')->index()->comment('Site content resource ID');
$table->foreign('contentid')->references('id')->on('site_content')->cascadeOnDelete();
$table->longText('value')->fulltext('value')->nullable()->comment('Translated value of the template variable');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('s_lang_tmplvar_contentvalues');
}
};
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ repo: https://github.com/Seiger/sLang
github_user: seiger
github_repo: sCommerce
# discord: https://community.discord.com
ko_fi: seigerkornelyuk

# If you have a logo, put here to include in meta tags
logo: assets/img/logo.svg
Expand Down
10 changes: 10 additions & 0 deletions docs/_includes/social-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@
</svg>
</a>
{% endif %}
{% if site.ko_fi %}
<a href="https://ko-fi.com/{{site.ko_fi}}" class="hover:text-sky-700 transition-colors">
<span class=sr-only>By Coffee</span>
<svg role=img class=icon viewBox="0 0 24 24" style='width: 20px; height: 20px' fill=currentColor>
<g buffered-rendering=static>
<path d="M23.881 8.948c-.773-4.085-4.859-4.593-4.859-4.593H.723c-.604 0-.679.798-.679.798s-.082 7.324-.022 11.822c.164 2.424 2.586 2.672 2.586 2.672s8.267-.023 11.966-.049c2.438-.426 2.683-2.566 2.658-3.734 4.352.24 7.422-2.831 6.649-6.916zm-11.062 3.511c-1.246 1.453-4.011 3.976-4.011 3.976s-.121.119-.31.023c-.076-.057-.108-.09-.108-.09-.443-.441-3.368-3.049-4.034-3.954-.709-.965-1.041-2.7-.091-3.71.951-1.01 3.005-1.086 4.363.407 0 0 1.565-1.782 3.468-.963 1.904.82 1.832 3.011.723 4.311zm6.173.478c-.928.116-1.682.028-1.682.028V7.284h1.77s1.971.551 1.971 2.638c0 1.913-.985 2.667-2.059 3.015z"/>
</g>
</svg>
</a>
{% endif %}
</div>
</nav>
4 changes: 2 additions & 2 deletions docs/pages/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permalink: /getting-started/
Go to You /core/ folder:

```console
cd core
cd path/to/your/evolution/cms/core
```

Run php artisan command
Expand Down Expand Up @@ -48,7 +48,7 @@ The resource includes tabs for each language separately.

![Multilingual tabs](https://github.com/Seiger/slang/releases/download/v1.0.0/sLang.png)

[Management tabs]({{ site.baseurl }}/management/){: .btn .btn-sky}
[Management tabs]({{site.baseurl}}/management/){: .btn .btn-sky}

## Extra

Expand Down
14 changes: 5 additions & 9 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ industry best practices. With its focus on simplicity and integration, sLang eme
an essential companion for those aiming to enhance the linguistic versatility of their
Evolution CMS-powered websites.

[Getting Started]({{ site.baseurl }}/getting-started/){: .btn .btn-sky}
[Getting Started]({{site.baseurl}}/getting-started/){: .btn .btn-sky}

## Features

Expand All @@ -42,14 +42,10 @@ Evolution CMS-powered websites.

## Minimum requirements

- Evolution CMS 3.2.0
- PHP 8.1.0
- Composer 2.2.0
- PostgreSQL 10.23.0
- MySQL 8.0.3
- MariaDB 10.5.2
- SQLite 3.25.0
- Evolution CMS >= 3.2.0
- PHP >= 8.1.0
- Composer >= 2.2.0

## Support

If you need help, please don't hesitate to [open an issue]({{ site.support }}).
If you need help, please don't hesitate to [open an issue]({{site.support}}).
42 changes: 0 additions & 42 deletions images/seirgerit-yellow.svg

This file was deleted.

2 changes: 2 additions & 0 deletions lang/en/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@
'synchronize_help' => 'Synchronize translations of templates and site database',
'synchronize' => 'Synchronize',
'use_url' => 'Use in URL',
'multilang_tvs' => 'List of the multilanguage parametrs (TV)',
'select_multilang_tvs' => 'Select the parametr',
];
2 changes: 2 additions & 0 deletions lang/ru/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@
'synchronize_help' => 'Синхронизировать переводы шаблонов и БД сайта',
'synchronize' => 'Синхронизировать',
'use_url' => 'Использовать в URL',
'multilang_tvs' => 'Список языковых параметров (TV)',
'select_multilang_tvs' => 'Выберите параметр',
];
2 changes: 2 additions & 0 deletions lang/uk/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@
'synchronize_help' => 'Синхронізувати переклади шаблонів та БД сайту',
'synchronize' => 'Синхронізувати',
'use_url' => 'Використати в URL',
'multilang_tvs' => 'Список мультимовних параметрів (TV)',
'select_multilang_tvs' => 'Оберіть параметр',
];
13 changes: 9 additions & 4 deletions modules/sLangModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@
case "settings":
// Default language
if (request()->has('s_lang_default')) {
$sLangController->setLangDefault(request()->s_lang_default);
$sLangController->setLangDefault(request()->input('s_lang_default'));
}

// Default language display
if (request()->has('s_lang_default_show')) {
$sLangController->setLangDefaultShow(request()->s_lang_default_show);
$sLangController->setLangDefaultShow(request()->input('s_lang_default_show'));
}

// List of site languages
if (request()->has('s_lang_config')) {
$sLangController->setLangConfig(request()->s_lang_config);
$sLangController->setLangConfig(request()->input('s_lang_config'));
}

// List of languages for the frontend
if (request()->has('s_lang_front')) {
$sLangController->setLangFront(request()->s_lang_front);
$sLangController->setLangFront(request()->input('s_lang_front'));
}

// List of multilang TVs
if (request()->has('s_lang_tvs')) {
$sLangController->setLangTvs(request()->input('s_lang_tvs'));
}

if (count($_POST) > 0) {
Expand Down
37 changes: 35 additions & 2 deletions plugins/sLangPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@
*/
Event::listen('evolution.OnAfterLoadDocumentObject', function($params) {
$langContentField = sLang::getLangContent($params['documentObject']['id'], evo()->getLocale());
$langTemplateContentvalueField = sLang::getLangTemplateContentvalue($params['documentObject']['id'], evo()->getLocale());

if (count($langContentField)) {
foreach (sLang::siteContentFields() as $siteContentField) {
$params['documentObject'][$siteContentField] = $langContentField[$siteContentField];
}
}

if (count($langTemplateContentvalueField)) {
foreach ($langTemplateContentvalueField as $key => $item) {
if (isset($params['documentObject'][$key])) {
$params['documentObject'][$key][1] = $item['value'];
}
}
}

evo()->documentObject = $params['documentObject'];
});

Expand Down Expand Up @@ -203,20 +212,29 @@
}

$sLangController = new sLangController();

foreach (sLang::langConfig() as $langConfig) {
$fields = [];
//$tvs = [];
foreach (request()->all() as $key => $value) {
$matches = [];
if (str_starts_with($key, $langConfig.'_')) {
$keyName = str_replace($langConfig.'_', '', $key);
$fields[$keyName] = $value;
unset($_REQUEST[$key]);
}
} /*elseif(preg_match_all('/tv([0-9]*)_'.$langConfig.'$/', $key, $matches)) {
$keyName = $matches[1][0];
$tvs[$keyName] = $value;
unset($_REQUEST[$key]);
}*/
}

if (count($fields)) {
$sLangController->setLangContent($params['id'], $langConfig, $fields);
}
/*if (count($tvs)) {
$sLangController->setLangTmplvarContentvalue($params['id'], $langConfig, $tvs);
}*/

}
});

Expand Down Expand Up @@ -304,5 +322,20 @@
$value->value = (int)request()->menu_footer;
$value->save();
}

foreach (sLang::langConfig() as $langConfig) {
$tvs = [];
foreach (request()->all() as $key => $value) {
$matches = [];
if(preg_match_all('/tv([0-9]*)_'.$langConfig.'$/', $key, $matches)) {
$keyName = $matches[1][0];
$tvs[$keyName] = $value;
unset($_REQUEST[$key]);
}
}
if (count($tvs)) {
$sLangController->setLangTmplvarContentvalue($params['id'], $langConfig, $tvs);
}
}
}
});
Loading

0 comments on commit 6e3d409

Please sign in to comment.