diff --git a/composer.json b/composer.json index 1b0fa52..5f15aed 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "statikbe/craft-translate", "description": "Translate static string from the Craft control panel", "type": "craft-plugin", - "version": "2.1.3", + "version": "5.0.0.beta-01", "keywords": [ "craft", "cms", @@ -22,7 +22,7 @@ } ], "require": { - "craftcms/cms": "^4.0.0-beta.1" + "craftcms/cms": "^5.0.0-alpha.1" }, "autoload": { "psr-4": { diff --git a/src/controllers/TranslateController.php b/src/controllers/TranslateController.php index ac7214b..bf6df07 100644 --- a/src/controllers/TranslateController.php +++ b/src/controllers/TranslateController.php @@ -146,7 +146,6 @@ public function actionDownloadCsvFile(): Response public function actionSave(): \yii\web\Response { $this->requireAcceptsJson(); - $response = [ 'success' => true, 'errors' => [] @@ -177,9 +176,10 @@ public function actionSave(): \yii\web\Response } } $translations = Craft::$app->request->getRequiredBodyParam('translation'); + $translations = reset($translations); // Save to translation file - Translate::getInstance()->translate->set($site->language, $translations, $translatePath); + Translate::getInstance()->translate->set($site->language, $translations['translation'], $translatePath); // Redirect back to page return $this->asJson($response); diff --git a/src/elements/Translate.php b/src/elements/Translate.php index f9fc2a3..88ee804 100644 --- a/src/elements/Translate.php +++ b/src/elements/Translate.php @@ -13,6 +13,7 @@ use Craft; use craft\base\Element; use craft\elements\db\ElementQueryInterface; +use craft\elements\User; use craft\helpers\FileHelper; use craft\web\ErrorHandler; use statikbe\translate\elements\db\TranslateQuery; @@ -116,13 +117,6 @@ public static function find(): ElementQueryInterface */ protected static function defineTableAttributes(): array { -// $primary = Craft::$app->getSites()->getPrimarySite(); -// $locale = Craft::$app->getI18n()->getLocaleById($primary->language); -// $attributes['original'] = ['label' => Craft::t('translate', 'Source: {region} ({language})', [ -// 'language' => $primary->language, -// 'region' => $locale->displayName -// ])]; -// $currentSite = Craft::$app->getRequest()->getQueryParam('site'); $attributes['field'] = ['label' => Craft::t('app', 'Translation')]; return $attributes; } @@ -161,7 +155,6 @@ protected static function defineSearchableAttributes(): array 'translation', 'source', 'file', - //'status', 'locale' ]; } @@ -173,99 +166,6 @@ protected static function defineSources(string $context = null): array { $sources = []; - //toonde extra kolom met template status (bolletjes groen/oranje) -// $sources[] = ['heading' => Craft::t('translate', 'Template Status')]; -// -// $key = 'status:' . self::ALL; -// $sources[] = [ -// 'status' => null, -// 'key' => $key, -// 'label' => Craft::t('translate', 'All'), -// 'criteria' => [ -// 'source' => [ -// Craft::$app->path->getSiteTemplatesPath() -// ], -// ], -// ]; -// -// $key = 'status:' . self::PENDING; -// $sources[] = [ -// 'status' => self::PENDING, -// 'key' => $key, -// 'label' => Craft::t('translate', 'Pending'), -// 'criteria' => [ -// 'source' => [ -// Craft::$app->path->getSiteTemplatesPath() -// ], -// 'translateStatus' => self::PENDING -// ], -// ]; -// -// $key = 'status:' . self::TRANSLATED; -// $sources[] = [ -// 'status' => self::TRANSLATED, -// 'key' => $key, -// 'label' => Craft::t('translate', 'Translated'), -// 'criteria' => [ -// 'source' => [ -// Craft::$app->path->getSiteTemplatesPath() -// ], -// 'translateStatus' => self::TRANSLATED -// ], -// ]; - - // Get template sources (toont files in sidebar) -// $templateSources = array(); -// $options = [ -// 'recursive' => false, -// 'only' => ['*.html', '*.twig', '*.js', '*.json', '*.atom', '*.rss'], -// 'except' => ['vendor/', 'node_modules/', 'jsPlugins/'] -// ]; -// -// $templates = FileHelper::findFiles(Craft::$app->path->getSiteTemplatesPath(), $options); -//// $templates = FileHelper::findFiles(Craft::$app->path->getSiteTemplatesPath(), $allTemplates); -// -// foreach ($templates as $template) { -// // If matches, get template name -// $fileName = basename($template); -// // Fixes bug in ElementHelper::findSource in Linux OS -// $cleanTemplateKey = str_replace('/', '*', $template); -// // Add template source -// $templateSources['templatessources:' . $fileName] = [ -// 'label' => $fileName, -// 'key' => 'templates:' . $cleanTemplateKey, -// 'criteria' => [ -// 'source' => [ -// $template -// ], -// ], -// ]; -// } - - // Maps (toont folders in sidebar) -// $options = [ -// 'recursive' => false, -// 'except' => ['vendor/', 'node_modules/', 'jsPlugins/'] -// ]; -// $folders = FileHelper::findDirectories(Craft::$app->path->getSiteTemplatesPath(), $options); -// -// foreach ($folders as $template) { -// // If matches, get template name -// $fileName = basename($template); -// // Fixes bug in ElementHelper::findSource in Linux OS -// $cleanTemplateKey = str_replace('/', '*', $template); -// // Add template source -// $templateSources['templatessources:' . $fileName] = [ -// 'label' => $fileName . '/', -// 'key' => 'templates:' . $cleanTemplateKey, -// 'criteria' => [ -// 'source' => [ -// $template -// ], -// ], -// ]; -// } - $sources[] = ['heading' => Craft::t('translate', 'Default')]; $sources[] = [ @@ -290,7 +190,7 @@ protected static function defineSources(string $context = null): array //was vroeger $modulesources (om plugin mapje te maken met eronder de plugins, nu enkel balkje per plugin) // $sources['plugins:' . $path] = [ - $modulesSources['plugins:' . $path] = [ + $modulesSources['plugins:' . $path] = [ 'label' => $module->id, 'key' => 'plugins:' . $module->id, 'criteria' => [ @@ -318,10 +218,30 @@ protected static function defineSources(string $context = null): array return $sources; } + public function canSave(User $user): bool + { + return true; + } + + public function getInlineAttributeInputHtml(string $attribute): string + { + return $this->field; + } + + /** * @inheritdoc */ - public static function indexHtml(ElementQueryInterface $elementQuery, array $disabledElementIds = null, array $viewState, string $sourceKey = null, string $context = null, bool $includeContainer, bool $showCheckboxes): string + public static function indexHtml( + ElementQueryInterface $elementQuery, + array $disabledElementIds = null, + array $viewState, + string $sourceKey = null, + string $context = null, + bool $includeContainer, + bool $showCheckboxes, + bool $sortable + ): string { // just 1 locale enabled if (empty($elementQuery->siteId)) { @@ -329,20 +249,25 @@ public static function indexHtml(ElementQueryInterface $elementQuery, array $dis $elementQuery->siteId = $primarySite->id; } - if ($elementQuery->translateStatus) { - $elementQuery->status = $elementQuery->translateStatus; - } + + $elementQuery->status = null; $elements = TranslatePlugin::getInstance()->translate->get($elementQuery); $variables = [ 'viewMode' => $viewState['mode'], 'context' => $context, - 'disabledElementIds' => $disabledElementIds, + 'inputNameSpace' => 'translation', + 'nestedInputNamespace' => 'translation', + 'disabledElementIds' => [], 'attributes' => Craft::$app->getElementSources()->getTableAttributes(static::class, $sourceKey), 'elements' => $elements, 'sourceKey' => $sourceKey, - 'includeContainer' => $includeContainer, + 'includeContainer' => false, 'showCheckboxes' => false, + 'selectable' => false, + 'sortable' => false, + 'showHeaderColumn' => true, + 'inlineEditing' => true, ]; // Better UI @@ -351,9 +276,7 @@ public static function indexHtml(ElementQueryInterface $elementQuery, array $dis Craft::$app->view->registerJs("$('.filter-btn').addClass('hidden');"); Craft::$app->view->registerJs("$('.btn.statusmenubtn').addClass('hidden');"); - $template = '_elements/' . $viewState['mode'] . 'view/' . ($includeContainer ? 'container' : 'elements'); - - return Craft::$app->view->renderTemplate($template, $variables); + return Craft::$app->view->renderTemplate("_elements/tableview/container", $variables); } /** diff --git a/src/services/Translate.php b/src/services/Translate.php index 26be351..88c4dd4 100644 --- a/src/services/Translate.php +++ b/src/services/Translate.php @@ -207,10 +207,10 @@ private function _processFile(string $path, string $file, ElementQueryInterface $translation = Craft::t($category, $original, [], $site->language); $view = Craft::$app->getView(); - $elementId = ElementHelper::generateSlug($original); + $slug = ElementHelper::generateSlug($original); $field = $view->renderTemplate('_includes/forms/text', [ - 'id' => $elementId, + 'id' => $slug, 'name' => 'translation[' . $original . ']', 'value' => $translation, 'placeholder' => $translation, @@ -218,7 +218,7 @@ private function _processFile(string $path, string $file, ElementQueryInterface // Let's create our translate element with all the info $element = new TranslateElement([ - 'id' => ElementHelper::generateSlug($original), + 'id' => $slug, 'original' => $original, 'translation' => $translation, 'source' => $path, diff --git a/src/templates/index.twig b/src/templates/index.twig index 3230f94..80ea70f 100644 --- a/src/templates/index.twig +++ b/src/templates/index.twig @@ -43,6 +43,7 @@ {% set selectedSite = craft.app.request.getQueryParam('site', null) ? craft.app.sites.getSiteByHandle(craft.app.request.getQueryParam('site')) : craft.app.sites.primarySite %} + {# banner block #}